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

Graphic Lines script

New Here ,
Nov 23, 2022 Nov 23, 2022

Copy link to clipboard

Copied

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!

TOPICS
How to , Scripting

Views

591

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 , Nov 23, 2022 Nov 23, 2022

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.
...

Votes

Translate

Translate
Community Expert ,
Nov 23, 2022 Nov 23, 2022

Copy link to clipboard

Copied

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? 

 

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
New Here ,
Nov 23, 2022 Nov 23, 2022

Copy link to clipboard

Copied

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 ,
Nov 23, 2022 Nov 23, 2022

Copy link to clipboard

Copied

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;

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
New Here ,
Nov 23, 2022 Nov 23, 2022

Copy link to clipboard

Copied

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?

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 ,
Nov 23, 2022 Nov 23, 2022

Copy link to clipboard

Copied

 

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;

 

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
New Here ,
Nov 23, 2022 Nov 23, 2022

Copy link to clipboard

Copied

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

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 ,
Nov 23, 2022 Nov 23, 2022

Copy link to clipboard

Copied

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;

 

 

 

 

 

 

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
New Here ,
Nov 24, 2022 Nov 24, 2022

Copy link to clipboard

Copied

LATEST

Thank you!!! I learnt a lot!

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