I'm trying to import a graphic by reference at a set DPI (222). The following code sample imports the graphic, but ignores the DPI setting. Can anyone see what is wrong? A few notes:
- I wrote an FDK equivalent and it worked fine, following the exact same methodology.
- The GetImportDefaultParams() populates an array of about 45 members and GetPropIndex() retrieves unique indexes, suggesting that those parts are working
- Upon experimentation, I find that parms[index].PropIdent is always undefined, which seems weird.
var doc = app.ActiveDoc;
var tl = new TextLoc();
tl.obj = doc.FirstSelectedGraphicInDoc;
if(!tl.obj.ObjectValid) tl.obj = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
tl.offset = 0;
var parms = GetImportDefaultParams();
index = GetPropIndex (parms, Constants.FS_GraphicDpi);
parms[index].TypedVal = 222;
index = GetPropIndex (parms, Constants.FS_FitGraphicInSelectedRect);
parms[index].TypedVal = false;
var returnParms = new PropVals();
doc.Import(tl, "C:\\temp\\delete\\222_dpi.jpg", parms, returnParms);
what's your problem exactly, I don't think its really the NULL value of PropIdent?
So I guess, your problem is, dpi is not set.
If I change one of these ***DefaultParams(), I use this function:
function SetPropVal (prop, propval, params)
var i = GetPropIndex(params, prop);
if (i < 0)
return false ;
if (typeof(propval) == 'number')
params[i].propVal.ival = propval;
if (typeof(propval) == 'string')
params[i].propVal.sval = propval;
First parameter is the constant value, second the value to set and third the ***DefaultParams.
Hope this helps
Thanks once again for your expert advice. I was able to get it working.
I was originally trying to use this:
params[i].propVal = 222;
...but the script threw errors. I looked in the scripting guide and somehow decided to use:
params[i].TypedVal = 222;
...which did not cause any runtime errors, but also did not work. So, with your example, I see that I did not go far enough into the array, as in:
params[i].propVal.ival = 222;
...which does work and of course resembles the FDK PropValT data type.
One more question, if you don't mind. How did you know how to use that typeof() function, as in:
if (typeof(propval) == 'number')
//.... do more code
myvariable = "Hello world";
but you can also use it to check the basic type of this variable. Basic types are boolean, string, number, function, object and undefined.
I like the documentation and community of http://www.selfhtml.org. Where othere languages like html, perl, php etc, are documented as well.
Unfortunately this website isn't available in Englisch. But perhaps Google translate can help.
I have to ask one followup question, because this is an important point. Would you rather use:
I'm not clear on the difference.
there's a big difference between these two lines of codes...
If you declare
it's not initialized; it's undefined
if you don't check this and use it like myvariable.dosomething(), you'll get a runtime error.
ObjectValid() is an ES-function, which could be called to all FM-Objects (FO_* in FDK). It returns false if the id of this object is 0 or true if it's not 0. Or it returns false if this object doesn't exist anymore. It's the same als you call F_ApiGetObjectValid() in your FDK clients.
So your variable is initialized with an FM object but it is not valid.
BTW:don't miss the parenthesis when calling ObjectValid
myvariable.ObjectValid() it's a function not a property
Perhaps it's getting clear with a sample:
var doc ;
alert(typeof(doc)) ; //Message: undefined
doc = app.ActiveDoc;
alert(typeof(doc)); //Message: object
//It's allways initialized, because ES delivers always an instanziated Doc object, even if there's no document opened.
alert(doc.ObjectValid()) ; //returns false if there's no active doc and true if there's an valid active doc.
So if you are not sure at the point you use variable "doc", check this with typeof to avoid runtime errors. And then check if your doc object is valid.
//some code, where doc should be initialized (external function)
//do some errorhandlings, perhaps there is a problem in your code somewhere else
//your code what should be done, if there is no valid doc at this point
Hope I could make it clear
Thanks for the detailed information. Very helpful. You know, I've never used F_ApiGetObjectValid() before in my FDK code... if I had, I might have recognized the correlation. Maybe this is a function I should have been aware of before now.
Europe, Middle East and Africa