Skip to main content
Participating Frequently
November 23, 2022
Answered

Graphic Lines script

  • November 23, 2022
  • 2 replies
  • 1046 views

Hi! Is there a way to produce a horizontal line using script. That is 30" long, 2pt line thickness, dashed (4pt dash 4pt gap) in 30% black, placed in the X, Y axis. And another line that is the same but vertical. Thanks!

This topic has been closed for replies.
Correct answer rob day

Thank you Rob! Also how do you go about adding another vertical line on its own at X: 170mm, Y: 148mm?


You would want to settle on a measurement unit, so if you want to use Millimeters, set the length of the line in millimetrs rather than inches—30" = 762mm

 

You create a line by adding it to the page. In my example the lines are getting added to the activePage—my p variable:

 

var p = app.activeWindow.activePage;

 

The position of the line is set via the geometricBounds property, which is an array of 4 points [y1,x1,y2,x2], so a 3rd vertical line could be added as:

 

var vLine2 = p.graphicLines.add({geometricBounds: [148,170,148+l,170]});
vLine2.properties = lp;

 

Here the units are millimeters:

app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;
var doc = app.activeDocument;
var p = app.activeWindow.activePage;
var l = 762; //30" as millimeters
var xy = 100 
var lp = { 
    strokeColor:"Black", 
    strokeWeight:1, 
    strokeType: "Dashed",
    strokeTint: 30,
    strokeDashAndGap: [4,4],
    strokeAlignment:StrokeAlignment.CENTER_ALIGNMENT
    }

var hLine = p.graphicLines.add({geometricBounds: [xy,0,xy,l]});
var vLine = p.graphicLines.add({geometricBounds: [0,xy,l,xy]});
hLine.properties = lp;
vLine.properties = lp;

//X: 170mm, Y: 148mm?
var vLine2 = p.graphicLines.add({geometricBounds: [148,170,148+l,170]});
vLine2.properties = lp;

app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;

 

 

 

 

 

 

2 replies

rob day
Community Expert
Community Expert
November 23, 2022

Hi @lalaland_ , Try this:

 

app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var doc = app.activeDocument;
var p = app.activeWindow.activePage;
var l = 30;
var lp = { 
    strokeColor:"Black", 
    strokeWeight:2, 
    strokeType: "Dashed",
    strokeTint: 30,
    strokeDashAndGap: [4,4],
    strokeAlignment:StrokeAlignment.CENTER_ALIGNMENT
    }

var hLine = p.graphicLines.add({geometricBounds: [0,0,0,l*72]});
var vLine = p.graphicLines.add({geometricBounds: [0,0,l*72,0]});
hLine.properties = lp;
vLine.properties = lp;

app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;
lalaland_Author
Participating Frequently
November 23, 2022

Thank you! Is there a way to place the lines on X: 100mm, Y: 0 for the vertical, and X:0, Y:100mm for the horizontal one?

rob day
Community Expert
Community Expert
November 23, 2022

 

I’ve set the measurement units as points, so 100mm = 283.465pts

app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var doc = app.activeDocument;
var p = app.activeWindow.activePage;
var l = 30;
var xy = 283.465 //100mm as points
var lp = { 
    strokeColor:"Black", 
    strokeWeight:1, 
    strokeType: "Dashed",
    strokeTint: 30,
    strokeDashAndGap: [4,4],
    strokeAlignment:StrokeAlignment.CENTER_ALIGNMENT
    }

var hLine = p.graphicLines.add({geometricBounds: [xy,0,xy,l*72]});
var vLine = p.graphicLines.add({geometricBounds: [0,xy,l*72,xy]});
hLine.properties = lp;
vLine.properties = lp;

app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;

 

brian_p_dts
Community Expert
Community Expert
November 23, 2022

Sure, you'd use the Line object. What do you mean by "Placed on the X, Y axis"? Where exactly would it go in relation to the page. And what page are you building it on, every page? What is the use for this script as part of your workflow that can't be solved by leveraging parent pages? 

 

lalaland_Author
Participating Frequently
November 23, 2022