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

Illustrator Script to apply Symbol to end points of selected lines

Community Beginner ,
Feb 16, 2020 Feb 16, 2020

Copy link to clipboard

Copied

Hi all

 

I need a script to apply a Symbol to the end points of selected lines. Ideally this would function as follows:

1. Create Symbol called 'EndPoint'

2. Select lines

3. Run script that applies the 'EndPoint' symbol to the end of all of the selected lines

Any help would be much appreciated.

Cheers

Mike

I want to be able to select a bunch of lines and use a script to apply a symbol titled 'EndPoint' to the end point of all of the linesI want to be able to select a bunch of lines and use a script to apply a symbol titled 'EndPoint' to the end point of all of the linesHere's the Symbol titled 'EndPoint'Here's the Symbol titled 'EndPoint'Here's the end result I'm afterHere's the end result I'm after

TOPICS
Draw and design , Scripting , Tools

Views

1.8K

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 2 Correct answers

Community Expert , Feb 21, 2020 Feb 21, 2020

Hi Mike, grab the small white circle in your symbol and make a second symbol. I need just the white circle by itself to grab its dimensions. Name it "marker".

 

then select 1 or more path items and run this script

 

// place destination symbol
// carlos canto
// https://community.adobe.com/t5/illustrator/illustrator-script-to-apply-symbol-to-end-points-of-selected-lines/td-p/10928347?page=1

function main() {
    var idoc = app.activeDocument;
    var sel = idoc.selection;

    var p, pp, marker
...

Votes

Translate

Translate
Community Expert , Apr 02, 2020 Apr 02, 2020

Hi Mike, here you go

 

// place destination symbol
// carlos canto
// https://community.adobe.com/t5/illustrator/illustrator-script-to-apply-symbol-to-end-points-of-selected-lines/td-p/10928347?page=1

function main() {
    var idoc = app.activeDocument;
    var sel = idoc.selection;

    var p, pp, marker, endPoint, markerSymbol, endPointSymbol;
    markerSymbol = idoc.symbols['marker'];
    endPointSymbol = idoc.symbols['EndPoint'];

    marker = idoc.symbolItems.add(markerSymbol);

    for (v
...

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

How do you determine which end of the line is the endpoint and which one is the start point?

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 ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

I can't figure out whether it's possible to place a symbol instance into the document via a script.. You can create an action to do so, but it's generic and requires the symbol to be pre-selected in the symbols panel.. So, i hope someone else has some advice on this portion..

 

But as to the rest of your question, here's a little snippet that shows how to position the symbol relative to an endpoint of a path. (you may need to fiddle with some buffer to get the circle of your symbol to line up properly. as it stands, this snippet will simply align the top left coordinate to the end of the line. So you'll probably need to add or subtract a few points to fine tune the positioning).

 

function alignSymbolToPathPoint()
{
	var docRef = app.activeDocument;
	var layers = docRef.layers;
	var myPath = layers[0].pageItems[0];
	var symbol = layers[0].pageItems[1];
	myPath.selected = true;

	symbol.position = myPath.selectedPathPoints[0].anchor;

	//use this one instead to get the other end of the path.
	// symbol.position = myPath.selectedPathPoints[myPath.selectedPathPoints.length-1].anchor;

}
alignSymbolToPathPoint();

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 ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

here's how to add symbols to the canvas william

 

var idoc = app.activeDocument;
var endPointSymbol = idoc.symbols['EndPoint'];

var symbolInstance = idoc.symbolItems.add(endPointSymbol);

 

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 ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

Thanks carlos.. My syntax must have been off.. It just kept throwing a runtime error saying "undefined is not an object". 

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 ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

it happens 🙂

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 Beginner ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

This places the symbol. Any ideas on how to place it at the end of multiple selected lines?

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 Beginner ,
Feb 20, 2020 Feb 20, 2020

Copy link to clipboard

Copied

Hey Carlos

Any chance you could provide the whole script? This one places the symbol but just places it randomly into the document.

 

Maybe if this is combined with williamdowling's script it will add the symbol to the end of a line? I'm a total script noob so I can't figure out how to write the final script.

 

Any help would be greatly appreciated

 

Cheers

Mike

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
Advocate ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

There is a pretty easy way to add a circle or shape at the end of your line using your stroke panel. Make sure "show options" is selected on the stroke panel so that you can see the arrow menus. Then you can select your line, and choose what arrow symbol endpoint you'd like to apply.

arrows.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 ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

But we are obviously not just talking about a simple circle, meganchi. See the original request.

 

In case it does not necessarily have to be a native Illustrator symbol, I would do it with a Scatter brush. I've posted similar approaches in the past on this forum.

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
Advocate ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

Oh, goodness, my bad. Thanks for explaining to look at the original request, Kurt. Your advice is spot on. 

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 Beginner ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

The end result has to have Symbols placed into the document. A scatter brush will not achieve this

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 ,
Feb 21, 2020 Feb 21, 2020

Copy link to clipboard

Copied

Hi Mike, grab the small white circle in your symbol and make a second symbol. I need just the white circle by itself to grab its dimensions. Name it "marker".

 

then select 1 or more path items and run this script

 

// place destination symbol
// carlos canto
// https://community.adobe.com/t5/illustrator/illustrator-script-to-apply-symbol-to-end-points-of-selected-lines/td-p/10928347?page=1

function main() {
    var idoc = app.activeDocument;
    var sel = idoc.selection;

    var p, pp, marker, endPoint, markerSymbol, endPointSymbol;
    markerSymbol = idoc.symbols['marker'];
    endPointSymbol = idoc.symbols['EndPoint'];

    marker = idoc.symbolItems.add(markerSymbol);

    for (var a=0; a<sel.length; a++) {
        if(sel[a].typename == "PathItem") {
            pp = sel[a].pathPoints;
            p = pp[pp.length-1];

            
            endPoint = idoc.symbolItems.add(endPointSymbol);
            
            endPoint.position = [p.anchor[0]-marker.width/2, p.anchor[1]+marker.height/2];
        }
    }

    marker.remove();

}

main();

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 Beginner ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

Hi Carlos

Thanks for doing this script. It does what I want it to do, however, it always places the symbol on the top layer, regardless of whether that is the layer the line is on or not.

 

How would you alter the script so that it places the symbol on the same layer as the line that's selected?

 

Cheers

 

Mike

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 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

Hi Mike, here you go

 

// place destination symbol
// carlos canto
// https://community.adobe.com/t5/illustrator/illustrator-script-to-apply-symbol-to-end-points-of-selected-lines/td-p/10928347?page=1

function main() {
    var idoc = app.activeDocument;
    var sel = idoc.selection;

    var p, pp, marker, endPoint, markerSymbol, endPointSymbol;
    markerSymbol = idoc.symbols['marker'];
    endPointSymbol = idoc.symbols['EndPoint'];

    marker = idoc.symbolItems.add(markerSymbol);

    for (var a=0; a<sel.length; a++) {
        if(sel[a].typename == "PathItem") {
            pp = sel[a].pathPoints;
            p = pp[pp.length-1];

            
            endPoint = sel[a].layer.symbolItems.add(endPointSymbol);
            
            endPoint.position = [p.anchor[0]-marker.width/2, p.anchor[1]+marker.height/2];
        }
    }

    marker.remove();

}

main();

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 Beginner ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

Amazing! That has saved me literally days of work haha

 

Thank you so much!

 

Mike

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 Beginner ,
Apr 05, 2020 Apr 05, 2020

Copy link to clipboard

Copied

LATEST

One more thing

 

How do you add the symbol to the opposite end of the line?

 

Thanks

 

Mike

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