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

Creating a specific shape with javascript

Participant ,
Jun 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

I was looking to have a script create the below shape, and place it within a document up to hundreds of times.  It's 2-3 circles and 2 rectangles, but I'm not sure of the best approach.  Would calling a function that creates it each time be most efficient?

 

mark.png

TOPICS
Scripting

Views

434

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 , Jun 20, 2020 Jun 20, 2020

Hi Maple_Stirrup,

 

I think it would be a good time to use Symbols. Drag your artwork into the symbol palette, call it "mySymbol" for example, and try out this script:

 

// make sure there's a symbol in the document called "mySymbol"
mySymbol = app.activeDocument.symbols.getByName("mySymbol");
placeSymbols(mySymbol, 10);

function placeSymbol(symbol, pos) {
    // create a symbol item, centred on pos
    symbolItem = app.activeDocument.symbolItems.add(symbol);
    symbolItem.left = pos[0] - symbolIt
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

Hi Maple_Stirrup,

 

I think it would be a good time to use Symbols. Drag your artwork into the symbol palette, call it "mySymbol" for example, and try out this script:

 

// make sure there's a symbol in the document called "mySymbol"
mySymbol = app.activeDocument.symbols.getByName("mySymbol");
placeSymbols(mySymbol, 10);

function placeSymbol(symbol, pos) {
    // create a symbol item, centred on pos
    symbolItem = app.activeDocument.symbolItems.add(symbol);
    symbolItem.left = pos[0] - symbolItem.width / 2;
    symbolItem.top = pos[1] - symbolItem.height / 2;
    return symbolItem;
}

function placeSymbols(symbol, howMany) {
    // place a bunch of symbols randomly
    for (var i =0 ; i < howMany ; i ++ ) {
        var x = Math.random() * 100;
        var y = Math.random() * -100;
        placeSymbol(symbol, [x,y]);
    }
}

 

Of course, you'd have to decide how your symbol needed to be positioned. I've just made it random for the illustration.

 

Regards,

Mark

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
Participant ,
Jun 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

I apprecaite the reply.  What if I wanted this to work on any machine, a symbol wouldn't work then right?

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 ,
Jun 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

I see, you need the script to draw it first. No problem. Extendscript has the basic drawing methods to make your object. (And then turn it into a symbol and position multiple instances.)

 

Have a look at Creating Paths and Shapes. Let me know how you go.

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
Participant ,
Jun 30, 2020 Jun 30, 2020

Copy link to clipboard

Copied

Just throwing in an udpate, I used a lot of your ideas for placing symbols, and it works really really well. : ) 

 

Many thanks!

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 ,
Jun 30, 2020 Jun 30, 2020

Copy link to clipboard

Copied

LATEST

Very glad it helped! Thanks for letting me know. 🙂

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