Skip navigation
Currently Being Moderated

Can't get graphic import parameters to work

Jul 31, 2012 12:31 PM

Hi,

 

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.

 

Thanks.

 

 

 

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);

 
Replies
  • Currently Being Moderated
    Jul 31, 2012 1:14 PM   in reply to Russ Ward

    Hi Russ,

    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;

              return true;

        }

     

    First parameter is the constant value, second the value to set and third the ***DefaultParams.

     

    Hope this helps

    Markus

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 1:50 AM   in reply to Russ Ward

    Hi Russ,

     

    I use typeof most to check if an variable is initialized or not.It's part of the javascript syntax http://de.selfhtml.org/javascript/sprache/operatoren.htm#typeof.

     

    i.e.

    var myvariable;

    //.... do more code

    if (typeof(myvariable)=='undefined')

         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.

     

    Bye

    Markus

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 5:50 AM   in reply to Russ Ward

    Hi Russ,

    there's a big difference between these two lines of codes...

     

    if (typeof(myvariable)=='undefined')

     

    typeof only checks if a variable is initialized and it's part of the javascript syntax.

     

    If you declare

    var myvariable;

    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.

     

     

     

    if (!myvariable.ObjectValid)

     

    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.

     

    var doc;

     

    //some code, where doc should be initialized (external function)

     

    if (typeof(doc)=='undefined')

    {

         //do some errorhandlings, perhaps there is a problem in your code somewhere else

    }

     

    if (doc.ObjectValid()==false)

    {

         //your code what should be done, if there is no valid doc at this point

    }

     

     

    Hope I could make it clear

    Markus

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points