Skip to main content
Known Participant
August 19, 2009
Answered

[JS] CS4 How to position a graphic within a Frame

  • August 19, 2009
  • 3 replies
  • 2410 views

I have a JS script that I am converting from CS3 to CS4 and I am finding that the behaviour for positioning a graphic within a frame has changed.  I have code that sets the geometric bounds of a graphic to a negitave value within the frame, within CS3 this works great.  However using the same code on CS4 to set the geometric bounds does not produce the same result.  The graphic is always placed at 0,0 and it ignores the negitive top and left values supplied.

Does anyone know what has changed with the geometric bounds of a graphic within a recrangle frame?  How would I set the position of the graphic within the frame since setting the geometric bounds does not seem to work any longer.

Thanks,

Sheldon

This topic has been closed for replies.
Correct answer Harbs.

Your problem is because of the object style you are applying. The

fitting settings in the object style are resizing the graphic when you

apply the style. Move the setting of the geometric bound to after the

application of the style, and it will work as expected.

Harbs

http://www.in-tools.com

Innovations in Automation

3 replies

Known Participant
August 27, 2009

I am still looking for a solution to this problem can anyone provide any insight into this problem?

Harbs.
Harbs.Correct answer
Legend
August 27, 2009

Your problem is because of the object style you are applying. The

fitting settings in the object style are resizing the graphic when you

apply the style. Move the setting of the geometric bound to after the

application of the style, and it will work as expected.

Harbs

http://www.in-tools.com

Innovations in Automation

Known Participant
August 27, 2009

Harbs, Thanks for the advice, you are absolutly correct. I tested it and it is now working correctly.  I would have never thought that the Style object would have affected the position of the graphic.  Thanks for the advice it is greatly appreciated.

Sheldon

Known Participant
August 25, 2009

Thanks for the advice, I appreciate the help.

I tried using using the visibleBounds and it had no visible effect, it had the same result as the geometricBounds, on CS3 it worked correctly and on CS4 it still did not adjust the graphic within the parent rectangle correctly.

I also tested the move function, using the following code within my sample script:

frm.graphics.firstItem.move(['2pt','2pt'],undefined,true);

On CS3 the object moved as directed, but on CS4 it did not move at all.  It is almost like the graphic is anchored to the top left of its parent and can not be moved from that position via script.

I also tried using the item property rather than the firstItem property but it still fails with the same result on CS4.

frm.graphics.item(0).move(['2pt','2pt'],undefined,true);

Would it be possible for you to try running the script code I posted and see if you get the same results?

I am at a loss on how to make this work, I'm willing to try any other suggestions you might have.

Thanks,

Sheldon

Known Participant
August 20, 2009

Can anyone shed some light on this problem, it appears like the behavior for setting the geometric bounds of a graphic within a frame has changed with CS4.  Can anyone confirm this and do you know how I would set the position of the graphic within the frame?

Any insight would be appreciated.

Known Participant
August 21, 2009

I have yet to determine why the behavior is different from CS3 to CS4 and how to correct the positioning within CS4.  To help explain the problem further I have included a sample script which demonstrates the problem.  I have run the script on both CS3 and CS4 and included screen shots of the results when the resulting INDD file is opened.  Could someone help explain why the position of the image is wrong in CS4 and what I can do to correct the problem?

Here is the sample script ...

for(i=app.documents.count()-1;i>=0;i--){app.documents.item(i).close();}
app.textPreferences.useOpticalSize = false;
app.textPreferences.typographersQuotes = false;
app.textImportPreferences.useTypographersQuotes = false;
app.taggedTextImportPreferences.useTypographersQuotes = false;
app.pasteboardPreferences.minimumSpaceAboveAndBelow = "300p";
app.textFramePreferences.firstBaselineOffset = FirstBaseline.ascentOffset;
app.colorSettings.cmsSettingsPath = File("C:\\etc\\Friesens_Yearbook_Custom_Color_Settings.csf");
app.marginPreferences.top = '24pt';
app.marginPreferences.bottom = '48pt';
app.marginPreferences.left = '36pt';
app.marginPreferences.right = '36pt';

var doc = app.documents.add();
doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
doc.documentPreferences.pageHeight = 792;
doc.documentPreferences.pageWidth = 612;
doc.documentPreferences.pageOrientation = PageOrientation.portrait;
doc.documentPreferences.pagesPerDocument = 2;
doc.documentPreferences.facingPages = true;
doc.sections.firstItem().continueNumbering = false;
doc.sections.firstItem().pageNumberStart = 2;

var pg = doc.pages.item(0);

var frm = pg.rectangles.add();
frm.geometricBounds = ['200.5pt','200.2pt','447.8551pt','415.5206pt'];
try{frm.place (File('c:\\test.jpg'), false);}catch(err){};
if(frm.graphics.count() > 0) {frm.graphics.firstItem().geometricBounds = [frm.geometricBounds[0]-147, frm.geometricBounds[1]-49, 407.04+frm.geometricBounds[0]-147, 271.68+frm.geometricBounds[1]-49];};

var objStyle = doc.objectStyles.add();
objStyle.enableStroke= false;
objStyle.transparencySettings.blendingSettings.opacity = 100;
frm.applyObjectStyle(objStyle, true, true);

frm.rotationAngle = 59;

doc.label = '824203.indd';
doc.packageForPrint('c:\\test\\824203\\', true, true, true, true, true, false, '', false, false);
for(i=app.documents.count()-1;i>=0;i--){app.documents.item(i).close();}

The line that I highlighted is the one that adjusts the images position within its frame.  It uses a formula to determine the exact position relative to the containing frames position.  This is why you will see the calculations to determine the geometric bounds.

Here is the result of the script using InDesign Server CS3, notice the position of the image based on the 'Direct Selection Tool' highlight area (this is the desired result):

And, here is the result after running the script against InDesign Server CS4:

As you can see the Image is placed at the lot left corrner of the frame which is wrong.  Any insight into the diffrences in the behavior would be appreciated.

Thanks

Inspiring
August 22, 2009

I don't know why the behavior is different. Have you considered using the move method rather than messing with the bounds?

Dave