Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Can't get graphic import parameters to work

Mentor ,
Jul 31, 2012 Jul 31, 2012

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

1.2K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Jul 31, 2012 Jul 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 

...

Votes

Translate
Engaged ,
Jul 31, 2012 Jul 31, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 31, 2012 Jul 31, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 01, 2012 Aug 01, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Aug 01, 2012 Aug 01, 2012

Copy link to clipboard

Copied

Hi Markus,

Thanks for the info. Apparently, I suffer from a considerable lack of javascript expertise. Hopefully, ES will begin to rectify this.

I have to ask one followup question, because this is an important point. Would you rather use:

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

...instead of:

if (!myvariable.ObjectValid)

I'm not clear on the difference.

Russ

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 01, 2012 Aug 01, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Aug 01, 2012 Aug 01, 2012

Copy link to clipboard

Copied

LATEST

Hi Markus,

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.

Russ

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines