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

How to call for graphic line length using extendscript?

Explorer ,
Apr 21, 2022 Apr 21, 2022

Copy link to clipboard

Copied

So for example, if you run this code:

myLayer = app.activeDocument.layers.add({name:"Line"})
app.activeDocument.graphicLines.add(myLayer, undefined, undefined, {geometricBounds: [10,10, 13, 14]})

 You see it creates a line. If you go into the properties of the line you can see that the line's length is 5.

How can I call for this length value in Extendscript? Sure, I can do some math using the geometric bounds but I'm curious if there's a way to call it directly?

 

Thanks,

 

Ben

TOPICS
How to , Scripting

Views

375

Translate

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

Community Expert , Apr 21, 2022 Apr 21, 2022

Sorry, my function had x,y reversed, should be this:

 

 

 

 

/**
* Returns geometric bounds for a defined width 
* @ param x the line’s x start
* @ param y the line’s y start
* @ param w the line’s width
* @ return geometric bounds array 
* 
*/
function setLineWidth(x,y,w){
    return [y,x,y,x+w]
};

 

 

 

Votes

Translate

Translate
Community Expert ,
Apr 21, 2022 Apr 21, 2022

Copy link to clipboard

Copied

Hi @Ben-ind , there’s no width or length property, so you’ll have to set the bounds. Here’s the API property listing:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#GraphicLine.html

 

You could write and call helper functions to make it easier. Something like this where my setLineWidth function defines the x,y start and the width for the line—25pts in this case:

 

Edited code:

 

 

app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
myLayer = app.activeDocument.layers.add({name:"Line"})
app.activeDocument.graphicLines.add(myLayer, undefined, undefined, {geometricBounds: setLineWidth(10,15,25), strokeColor:"Black"})





/**
* Returns geometric bounds for a defined width 
* @ param x the line’s x start
* @ param y the line’s y start
* @ param w the line’s width
* @ return geometric bounds array 
* 
*/
function setLineWidth(x,y,w){
    return [y,x,y,x+w]
}

 

 

 

 

Screen Shot 13.png

 

Votes

Translate

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
Community Expert ,
Apr 21, 2022 Apr 21, 2022

Copy link to clipboard

Copied

Sorry, my function had x,y reversed, should be this:

 

 

 

 

/**
* Returns geometric bounds for a defined width 
* @ param x the line’s x start
* @ param y the line’s y start
* @ param w the line’s width
* @ return geometric bounds array 
* 
*/
function setLineWidth(x,y,w){
    return [y,x,y,x+w]
};

 

 

 

Votes

Translate

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
Community Expert ,
Apr 22, 2022 Apr 22, 2022

Copy link to clipboard

Copied

LATEST

Graphic lines don't have a length property, but they do have a strokeWeight property. Rob's approach -- to use the geometricBounds of a line to set its dimensions -- works perfectly fine, but for completeness' sake here is how you'd add a line and use its weight property:

line = app.activeDocument.graphicLines.add (myLayer, {strokeWeight: 2});
line.paths[0].entirePath = [[10,15],[35,15]];

So you create a line, then say that its path is between two points.

P.

Votes

Translate

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