17 Replies Latest reply on Sep 21, 2012 11:00 AM by Muppet Mark

# Looping problem...How to create and lock a set of PathItems?

Greetings all!

I'm a noob....a very confused one

And I'm trying to get this thing work

So here is what I have. The first loop grabs the geometries drawn in the current document and rotates it around itself creating duplicates. The second loop is supposed to circumvent more geometries around the newly created geometries.

But instead of creating a radiant pattern, this code builds a tower: for the second loop everytime it grabs the last drawn geometry instead of what is in the "Original"

Can somebody explain what is wrong? Thanks!

for NumPaths = 1 to frontDocument.PathItems.count

set myPath = frontDocument.PathItems.item(NumPaths)

For index = 0 To 30

set newPath = myPath.Duplicate

call newPath.translate(100*sin(6.14* index/30),100*cos(6.14* index/30))

call newPath.rotate(360 * index/30)

Next

Next

Set Original = frontDocument.PathItems

for NumPaths = 1 to Original.count

set myPath = Original.Item(NumPaths)

For index = 0 To 30

set newPath = myPath.Duplicate

call newPath.translate(100*sin(6.14* index/30),100*cos(6.14* index/30))

call newPath.rotate(360 * index/30)

Next

Next

• ###### 1. Re: Looping problem...How to create and lock a set of PathItems?

can you post a drawing showing how you want it layed out?

this is what I get after the first loop? is that ok, and you need help with the second loop?

• ###### 2. Re: Looping problem...How to create and lock a set of PathItems?

yes pretty much. For the second loop now it only grabs the last object created and then loop around it, while what I want is to find every object created in the first loop and then use that geometry to run the loop.

2nd loop now:

what i want:

Thanks!

• ###### 3. Re: Looping problem...How to create and lock a set of PathItems?

something like this?

first loop makes a "ring", in order to make this "ring" revolve around to make the sphere you have to make it a group, so the second loop duplicates the "ring" (grouped) and basically makes the same thing as the first one, but uses the group instead of pathItems.

```    For NumPaths = 1 To frontDocument.PathItems.Count
Set myPath = frontDocument.PathItems.Item(NumPaths)

For Index = 0 To 30
Set newPath = myPath.Duplicate(myGroup) 'add each duplicate to the group
Call newPath.translate(100 * Sin(6.14 * Index / 30), 100 * Cos(6.14 * Index / 30))
Call newPath.rotate(360 * Index / 30)
Next
Next

Set Original = frontDocument.GroupItems 'make original all groupItems instead of pathItems

For NumPaths = 1 To Original.Count
Set myGroup = Original.Item(NumPaths) '

For Index = 0 To 30
Set newGroup = myGroup.Duplicate     'duplicate the groups
Call newGroup.translate(100 * Sin(6.14 * Index / 30), 100 * Cos(6.14 * Index / 30))
Call newGroup.rotate(360 * Index / 30)
Next
Next
```
• ###### 4. Re: Looping problem...How to create and lock a set of PathItems?

Wow yes! Thank you!

I was also wonderint where my original script went wrong. My original logic was not that the "ring" loops around, but that to create new rings around new geometries. The result will look the same; I am just not sure what problem does pathitems have - it looks like it is always selecting the last drawn object?

• ###### 5. Re: Looping problem...How to create and lock a set of PathItems?

Yeah Nice.

@ WeishunX, would you mind, "if" CarlosCanto would be willing to convert this script to JS and post it here? If so that would be great from each of you. I have to be honest I was not sure at first if it was VB or AplS ;-).  Thanks to CarlosCanto if he would be willing to convert it, if you would allow it, many thanks to each of you for the consideration.

• ###### 6. Re: Looping problem...How to create and lock a set of PathItems?

Surely I wouldn't mind. I don't actually know JS so it will be a great opportunity for me to learn as well

• ###### 7. Re: Looping problem...How to create and lock a set of PathItems?

WeishunX wrote: Surely I wouldn't mind. I don't actually know JS so it will be a great opportunity for me to learn as well

Thanks WeishunX. Likewise the VB code you posted looks very foreign to me as well. ;-)

• ###### 8. Re: Looping problem...How to create and lock a set of PathItems?

no problem, here's the JS version

```var frontDocument = app.activeDocument;
var NumPaths = frontDocument.pathItems.length
for (i = 0; i<NumPaths; i++) {
var myPath = frontDocument.pathItems[i];

for (index = 0; index<=30; index++) {
var newPath = myPath.duplicate(myGroup);
newPath.translate(100 * Math.sin(6.14 * index / 30), 100 * Math.cos(6.14 * index / 30));
newPath.rotate(360 * index / 30);
}
}

var Original = frontDocument.groupItems;
var numGroups = Original.length;

for (j = 0; j<numGroups; j++) {
var myGroup = Original[j];

for (index = 0; index<=30; index++) {
var newGroup = myGroup.duplicate();
newGroup.translate(100 * Math.sin(6.14 * index / 30), 100 * Math.cos(6.14 * index / 30));
newGroup.rotate(360 * index / 30);
}
}
```

• ###### 10. Re: Looping problem...How to create and lock a set of PathItems?

CarlosCanto wrote: no problem, here's the JS version

Thanks CarlosCanto, really appreicate it (colorful examples!). I actually had a go at it last night and was able to come to the resulting outcome but my groups were messy. I was so confused for a while looking at the VB(?) code, things that tripped me up were the opening For line, along with the term frontDocument, then the groups for the second loop. So thanks for providing a clean fresh JS version, now its clear. I had no trouble with the loops, case sensitiveity and the correct math methods but the whole groups and frontDocument had me going bonkers, your post was a welcome sight this morning. Fun stuff, thanks again! ;-)

• ###### 11. Re: Looping problem...How to create and lock a set of PathItems?

you're welcome, yeah that's VB, the loops are implemented a little different

basically in vb

for....

next

is the same as js

for (....) {

}

• ###### 12. Re: Looping problem...How to create and lock a set of PathItems?

Yeah a few things looked quite foreign to me. Are you fluent to code in all three illustrator scripting options, JS, VB, AS? You along with a couple handful of others have so many great nuggets of info and scripts laying around these forums, many thanks for sharing your talents and scripting knowledge!

• ###### 13. Re: Looping problem...How to create and lock a set of PathItems?

I don't own a mac ...I just do vb, js...

while Mark is our AS, JS guru.

+ Larry, we got you all covered.

• ###### 14. Re: Looping problem...How to create and lock a set of PathItems?

Yes, you three (+others) are certainly stalwarts as I search through the forum, tons of goodness. I am eager to learn further so forgive me in advance. ;-)

• ###### 15. Re: Looping problem...How to create and lock a set of PathItems?

while Mark is our AS, JS guru… That's funny Carlos Im no 'guru' just willing to learn this stuff myself out in the public domain… The AppleScript has become a little rusty as I now do more with the ESTK. Indesign and Illustrator offer a set of example scripts that are in AS, ESTK & VB… You should get 2 of the 3 dependent on your OS at install… or so I think?

• ###### 16. Re: Looping problem...How to create and lock a set of PathItems?

Mark you're so humble...that's good, that's how it supposed to be...but yeah, you're great and willing.

• ###### 17. Re: Looping problem...How to create and lock a set of PathItems?

I have all the top posters of the Photoshop Scripting Forum to thank… They all helped me out… only passing it along… They would still say only a pup/noob whatever… but I can get by… I do still see posts in the PS & ID forums that I still can't even read/follow… looks like another language but Im hopefull its just the shorthand of experience…