Skip to main content
Legend
July 31, 2012
Answered

Can't get graphic import parameters to work

  • July 31, 2012
  • 1 reply
  • 1318 views

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

This topic has been closed for replies.
Correct answer Wiedenmaier

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.propVal.ival  = propval;

          if (typeof(propval) == 'string')

            params.propVal.sval  = propval;

          return true;

    }

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

Hope this helps

Markus

1 reply

WiedenmaierCorrect answer
Inspiring
July 31, 2012

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.propVal.ival  = propval;

          if (typeof(propval) == 'string')

            params.propVal.sval  = propval;

          return true;

    }

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

Hope this helps

Markus

Russ WardAuthor
Legend
August 1, 2012

Hi Markus,

Thanks once again for your expert advice. I was able to get it working.

I was originally trying to use this:

params.propVal = 222;

...but the script threw errors. I looked in the scripting guide and somehow decided to use:

params.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.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')

This syntax is completely new to me. Is this some kind of JavaScript or ES standard? I understand that it follows the valType member methodology of the PropValT structure union, but how did you know that syntax? Is it in the documentation somewhere?

Russ

Inspiring
August 1, 2012

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