Skip to main content
Inspiring
February 3, 2017
Answered

graphicLines created are shifted problem

  • February 3, 2017
  • 2 replies
  • 1999 views

hi there,

i'm facing another problem with graphicLines.

Below scripts was run in 2 different templates of the same page size, margins, columns and zero origins.

app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.SPINE_ORIGIN;

myLine=app.activeDocument.graphicLines.add();

myLine.geometricBounds = ['200mm', '0mm', '200mm','300mm'];
myLine.strokeWeight ="8pt";

in the first template the Y was exactly 200mm, but in the 2nd template Y was 201.411mm

i've checked the margins, origin etc all are the same (even the " 9squares" all are the same..) the Y in fact is phyically 'shifted' in the 2nd template

please advise..

thanks much.

This topic has been closed for replies.
Correct answer Laubender

hi guys

i think i found the 'problem'...

solution to this is to set  StrokeAlignment.INSIDE_ALIGNMENT

Thanks much for everyone. i've learned new things from you guys. 


Hi eboda_snaf,

the following snippet should work for both specific templates.

Note: See my /* and more */ comment in the code.
A hint, that there are several other property/value pairs that can influence the creation of the object.

Or objects, that will be derived from the graphic lines in a later process.

Maybe you like to add some path points to create a polygon out of a duplicate, then it will be important how the fill color is defined, etc.pp.

var doc = app.documents[0];

var rulerOrigin = doc.viewPreferences.rulerOrigin;

doc.viewPreferences.rulerOrigin = RulerOrigin.SPINE_ORIGIN;

var geoBounds = [10,0,10,50];

var entirePath = [ [0,10] , [50,10] ];

var mutualProperties =

    {

        strokeWeight : "8pt" ,

        strokeTint : 100 ,

        strokeType : "$ID/Solid" ,

        strokeAlignment : StrokeAlignment.CENTER_ALIGNMENT ,

        endCap : EndCap.BUTT_END_CAP ,

        endJoin : EndJoin.MITER_END_JOIN ,

        leftLineEnd : ArrowHead.NONE ,

        rightLineEnd : ArrowHead.NONE

        /* and more */

    }

var gL1 = doc.spreads[0].graphicLines.add

(

    {

        geometricBounds : geoBounds ,

        strokeColor : doc.colors.itemByName("Magenta")

    }

);

var gL2 = doc.spreads[0].graphicLines.add

(

    {

        strokeColor : doc.colors.itemByName("Cyan")

    }

);

// Assigning mutual properties:

gL1.properties = mutualProperties;

gL2.properties = mutualProperties;

// Working with path points:

gL2.paths[0].entirePath = entirePath;

doc.viewPreferences.rulerOrigin = rulerOrigin;

What's the difference in the templates?

See this here:

Template 1:

Template 2:

Regards,
Uwe

2 replies

Braniac
February 3, 2017

eboda_snaf wrote:

… i've checked the margins, origin etc all are the same (even the " 9squares" all are the same..) the Y in fact is phyically 'shifted' in the 2nd template

Different preferences for setting the caps of the graphic line perhaps?

( just an assumption, not tested )

Check endCap and endJoin values of:

app.pageItemDefaults

app.documents[0].pageItemDefaults

Regards,
Uwe

Kai Rübsamen
Participating Frequently
February 3, 2017

Uwe, what is the benefit of using pathPoints instead of geometricBounds?

Thanks

Kai

Braniac
February 3, 2017

Hi Kai!

More "accurate" values perhaps. ?!

At least I can see a difference between:

app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.SPINE_ORIGIN;

myLine=app.activeDocument.graphicLines.add();

myLine.geometricBounds = ['200mm', '0mm', '200mm','300mm'];
myLine.strokeWeight ="8pt";

alert( myLine.paths[0].entirePath );

// Result with my open document A4 landscape:

// -5.01327374675182e-13,200,299.999999999998,200

and this:

app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.SPINE_ORIGIN;

var entirePath = [ [0,200],[300,200] ];

var doc = app.documents[0];

var gL = doc.spreads[0].graphicLines.add

(

    {

        strokeWeight : "8pt"

        // strokeColor : doc.colors.itemByName("Magenta")

        /* … */

    }

);

gL.paths[0].entirePath = entirePath;

alert(gL.paths[0].entirePath);

// Result with my open document A4 landscape:

// 0,200,300,200

when working with the same active document.

Regards,
Uwe

// EDITING: Removed a stray comma in the property definition of the method add().

Braniac
February 3, 2017

Cannot tell why this happens to you.

But I would not add a graphic line without giving the entire path and doing as many definitions as possible while adding:

// position of path points 1 and 2 defined in array [ [x,y],[x,y] ]

var entirePath = [ [0,200],[300,200] ];

var doc = app.documents[0];

// Do properties while adding:

var gL = doc.spreads[0].graphicLines.add

(

    {

        strokeWeight : "8pt" ,

        strokeColor : doc.colors.itemByName("Magenta")

        /* … */

    }

);

gL.paths[0].entirePath = entirePath;

Regards,
Uwe