Thursday, December 01, 2022

On the speed of change.

Hi all, I haven't posted in a while, as I've been focused in other things, but I had an experience I thought needed sharing. Please indulge me, I promise, there is a nice script at the end of the story. :) 

A couple nights ago, I was working on an illustration, and wanted to 'explode' all the objects, such that they were spaced out from each other instead of touching, like this: 

I fired up my editor and started coding, and quickly realized, it has been so long, I've forgotten most of the Adobe scripting API. I looked at a few of my old examples, and re-looked up a quick script for creating vectors so I could calculate distances, and about 20 or so minutes in, realized how fiddly js4ai can be, and this was more effort than I wanted to spend right now on this, and that would have likely been the end of that.

...until today, when a friend at work posted a link to, saying "Check this out, it's cool."

"Cool" might have been the understatement of the year. The site, exposes a conversational AI agent that can dialog. It was like talking to c3p0, but for real. So, I ran it through the gauntlet. 

It intelligently refused to predict the stock market.

It gave a logical response about the nature of consciousness.

It gave me a nice haiku about the nature of consciousness.

So I gave it some coding questions. I asked it to give me a regex that could parse a url. It did so, along with a nice explanation of what it was doing. 

... ok well this information is well known, google can do that. So I thought, let's give it something harder.

Here's where the magic happens. I entered into the prompt, something like: 

"Write me a javascript for Adobe Illustrator that moves each element in the selection 30 percent away from the selections center"

Four seconds later, it poops out the following script, and it WORKS!

   if (app.documents.length > 0) {

   // Get the current document and selection
   var doc = app.activeDocument;
   var sel = doc.selection;
   // Calculate the center of the selection
   var xCenter = 0;
   var yCenter = 0;
   for (var i = 0; i < sel.length; i++) {
     xCenter += sel[i].position[0];
     yCenter += sel[i].position[1];
   xCenter /= sel.length;
   yCenter /= sel.length;
   // Move each selected object by 30% of its current distance from the center of the selection
   for (var i = 0; i < sel.length; i++) {
     var xDist = sel[i].position[0] - xCenter;
     var yDist = sel[i].position[1] - yCenter;
     var dist = Math.sqrt(xDist * xDist + yDist * yDist);
     var xMove = xDist * 0.3;
     var yMove = yDist * 0.3;
     sel[i].position = [sel[i].position[0] + xMove, sel[i].position[1] + yMove];

Please appreciate what this is doing. Based on a text description, an ai, in real time is writing a script using a proprietary API, and it added code comments too!!!

OMG. @#JNK$U)(@# :mind-blown: JFC 

Anyway. If you're a designer that wants a script, I am now obsolete. Sign up for an account with openai, and have fun! The sky is the limit. Link in the comments if you create anything cool! 

Wednesday, February 26, 2014

Select Text By Size

Hi All,

I was just asked by user Seth if it was possible to write a script that would select text by a given size in Adobe Illustrator.
So I now present to you, my newly added script "selectTextBySize."  Honestly, I'm not sure why I didn't write this years ago... I would assume that I didn't because someone else had already written something similar. In any case, now you have my version...

This simple script just scours the current open document and selects all text of a given pixel size.
The default behavior of the script is to unlock text and layers if the correct sized text is locked or hidden.
This behavior can be changed by swapping the variables at the top of the script.

Hope you find this useful.

Update 3/19/14:
Just added range selection so you can grab text between, for example, 5px and 25px, or whatever...


Thursday, December 20, 2012

Hey All,

 I just got a message on  from user Vaughn, who was having problems getting copyToObject working in CS6.  He didn't leave an email, so I'm responding here. I've tested the script in CS6 on PC, and it seems to be working fine.  Vaughn, if you read this, please send me the problematic file so I can troubleshoot further. Otherwise, is anyone else having CS6 script issues?

Also, got a neat request from user Blair, who wanted a script to do multiple offsets like this:

 It's a great idea for an action, but sadly when you create an action, and select "Path>Offset Path..." from the Object menu, when you run the action, Illustrator stupidly keeps the source object selected, so multiple runs would create extra useless geometry.

I goofed around with the actions pallet, and discovered that when creating your action, if you use the actions fly-out to select "Insert Menu Item", and type in "Offset Path", you'll get a slightly different version of Offset Path with the expected behavior of only having the offset geometry selected, so the action can be run again immediately.

While recording your action, do this:

 When you run your new action, the "Offset" dialog cannot be suppressed  but this can be made negligible by hitting return/enter to close.  If you find that you often need to do lots of custom multi-offsets this might be a good workflow.

If you just want the same type of multiple offset for many objects, you'd be better served manually creating several offset stroke/fill combos in the appearance pallet, and saving it as a style. (which could be expanded later if you needed the geometry.)  If this sounds confusing, Google "create custom styles in illustrator". It's one of Illustrator's killer features.

 Thanks for the inspiration, and happy illustrating.


Wednesday, August 08, 2012

Update to Vary Hues

Minor update. Vary Hues will now create color variations on compound objects, and on objects in groups. Soon, I'll add some controls to give you better control.

  Sorry about not posting more, I've been busy writing a circular calendar widget for Android OS...

Sunday, April 15, 2012

Hey All!
Yes, I know... You like using my scripts, but you get a new computer with a fresh install of Illustrator, and you loathe having to download all my scripts individually. Have I got news for you...

I've finally joined the 21st century and created a GitHub repository for all my scripts. If you've never used GitHub, don't worry, all you need to know is that now you can download ALL of my public scripts in one handy zip file. Get them ALL here.

If you customize any of my scripts and think the modified version would be helpful for someone else, please feel free to fork the code.  I believe strongly in the community of JS4AI developers, and have been a little surprised at how that the playing field has been so sparse for so long.  I know there are a lot of awesome JS developers out there, so hopefully GitHub will provide a connection point to facilitate more co-development for the benefit illustrator community.  Let me know if you have any custom scripts that you want to add. Otherwise, get to downloading, and as always, happy illustrating!!!

Thursday, March 29, 2012

Matthew Ericson's MultiExport

Reader Dan just alerted me to the existence of Matthew Erickson's awesome multiExport script. His script is very similar to my exportLayers script in that it will export selected layers as various image files, but his script also manages to export layers as PDF files, and can handle multiple artboards at the same time.

The only downside is, I believe it only works for CS5 and above.  So if you're rocking CS5, check out Matt's script and his incredibly clear and thorough walk-through of how it works on Matt's blog.

I had a lot of fun looking through how he solved the dialogue/ persistent data issue. My solution was to write an entire script on the fly, and then export the script and execute it remotely.  I think Matt's closure solution is much more elegant.

Also, to save variable state between runs, his script generates an XML string, and stores it in a new textField in a hidden layer on the top of the document and then on the next run, the dialog can remember the selected values. Mad Genius. I love seeing solutions that think farther outside the box than my own efforts. 

Props to Matt for providing this open source, and for sharing his work with the world. Matt, you sir, are a Hacker with a capital 'H', and I mean that in the best possible way. 

Saturday, March 17, 2012

Draw control handles as geometry

All the anchor points and control handles below are actual geometry!

Want to be able to actually draw an objects control handles AS geometry? I have occasionally wanted this functionality while creating my script icon illustrations for 'scallop' and 'zoom and center', but I always did so by hand.

It occurred to me that this would be a good script to write,  but after doing a little Googling, I discovered that GFBroo of Jongware beat me to the punch on this one.

The discussion on the Adobe forums is here, and the direct download to the script is here.

 Very handy.... Thank's GFBroo!