Skip to main content
Sparth369
Known Participant
December 16, 2015
Question

Script - Create a small circle at the corner of the artboard

  • December 16, 2015
  • 1 reply
  • 6109 views

Can someone help me or guide me to the right direction of how to do this?

Basically, this is what I want the script to do

1. Make artboard the size of my selected artwork + 1" offset

2. Create a circle at each of the corner of the artboard

I figured out the script for #1 but I can't find figure out #2. Could anyone help?

Thanks in advance

This topic has been closed for replies.

1 reply

Silly-V
Legend
December 16, 2015

Wherever you want to put a circle, use the document.pathItems.ellipse() function. Into this function you pass 4 numbers separated by commas, the 1st 2 numbers are the top and the left coordinates, while the next 2 are width and height, respectively.

One such examples is:
var doc = app.activeDocument;

var newCircle = doc.pathItems.ellipse(0,0,10,10);

It creates a 10-diameter circle with the top/left of its bounding box at 0,0

For me it produced the following result:

Sparth369
Sparth369Author
Known Participant
December 16, 2015

‌i just figured out that part but now how do I make it align to top right based on my artboard size?

Disposition_Dev
Legend
December 17, 2015

Although, this is the very 1st google search result, and the only relevant bit is in the 1st paragraph for our purposes. The rest is web-oriented javascript drivel which only gets in the way, sometimes even confuses not only due to references to the Web DOM but also with usage of a more modern javascript implementation which is available for web browsers, while our ExtendScript is currently working off the EcmaScript 3 standard. For example, we can't use Array.indexOf() natively because it's not bult-in until EcmaScript 5, so that kind of feature has to be plopped in manually.


isn't that just a 'wrapper' type function? I understand closures a little differently, as i've run into some issues with attempting to set onClick events to multiple document objects via a loop, and it turned out 'function closures' was the answer.

From what i read, a function closure is another name for an "IIFE" (or, immediately invoked function expression). IIFE's solve the problem of scope issues during run time (for example, attempting to set an event handler at run time, and then access the value during the event). IIFE's look like this:

(function(arg){

     //do something

     //do something else

})(arg);

I wish i could explain the underlying logic of what makes that work and how it solves any scope issues that may arise.. but it's well over my head.

Anyway, all this to say be careful when googling 'function closures' because you might get results that are very different from what Vasily is talking about.