Copy link to clipboard
Copied
I am wondering how to select existing paths (normal paths and compound paths) and make a new compound path. Google does nothing for me on this....
I have begun to understand the basics of targeting objects and doing some basic changes such as width, height, textFont, positioning and such...but the Scripting Guide is hard for me to wrap my head around as far as compound paths.
I am also having issues understanding the differences between object references that either do or don't have an "s" at the end. I assume there is some uniformity to why many object references have both. Could someone explain the reasoning?
Example
pathItem
pathItems
Thanks in advance!!
James
Copy link to clipboard
Copied
Any help guys? I find it hard to believe this isn't a common task. Please help....
Copy link to clipboard
Copied
pathItems - a collection of items
pathItem - a single object in a collection
further more
var allPaths = app.activeDocument.pathItems;
var firstPath = allPaths[0];
var thirdPath = allPaths[2];
Copy link to clipboard
Copied
this is the sample in the documentation, let us know what you need help with.
Creating and modifying a compound path item
// Creates a new compound path item containing 3 path
// items, then sets the width and the color of the stroke
// to all items in the compound path
if ( app.documents.length > 0 ) {
doc = app.activeDocument;
newCompoundPath = doc.activeLayer.compoundPathItems.add();
// Create the path items
newPath = newCompoundPath.pathItems.add();
newPath.setEntirePath( Array( Array(30, 50), Array(30, 100) ) );
newPath = newCompoundPath.pathItems.add();
newPath.setEntirePath( Array( Array(40, 100), Array(100, 100) ) );
newPath = newCompoundPath.pathItems.add();
newPath.setEntirePath( Array( Array(100, 110), Array(100, 300) ) );
// Set stroke and width properties of the compound path
newPath.stroked = true;
newPath.strokeWidth = 3.5;
newPath.strokeColor = app.activeDocument.swatches[3].color;
}
Copy link to clipboard
Copied
Hi CarlosCanto,
Thank you very much for the reply....Thank you for the clarification for the pathItem versus pathItems!
As far as making a compound path, the example shows creating new paths to form the compound path. My issue is that I would like to learn to create a compound path from existing path/compound path items.
if ( app.documents.length > 0 ) {
doc = app.activeDocument;
newCompoundPath = doc.activeLayer.compoundPathItems.add();
--> newCompoundPath.MyExistingCompoundPath(s)ByNameOrGroupName;
--> newCompoundPath.MyExistingPath(s)ByNameOrGroupName;
}
To give you a quick example, In one of my scripts I create some text, convert it to outlines and then I position it over a solid element and need to knock out the converted text from the solid element.
I at first created custom actions but soon found out that Illustrator CC has issues with retaining the specifics of custom actions (must be a bug) so I decided to do start building a script instead.
The text when converted to outlines makes a <Group> that contains many <Compound Path> items (each represent a letter of the text).
Along with learning to make a compound path from existing paths, I was wondering if I would have to target pathItems specifically or can I target a Group of pathItems and have it still work.
I name my items whenever possible so they are easier to target and would like to keep that going if possible.
Thank you for your time and response!
James
Copy link to clipboard
Copied
this example creates the solid background, a text item, makes outlines, then makes a compound path out of those two items.
// knockout text
// carlos canto 1/26/14
// http://forums.adobe.com/thread/1388230?tstart=0
var idoc = app.activeDocument;
var background = idoc.pathItems.rectangle( 200, 200, 200, 40);
background.name = 'path_background';
var itext = idoc.textFrames.add();
itext.contents = 'Outlined Text';
itext.textRange.characterAttributes.size = 20;
itext.position = [240, 190];
var textOutline = itext.createOutline(); // this is a group
textOutline.name = 'text_outlined';
var icompound = idoc.compoundPathItems.add();
var myExistingPath = idoc.pathItems['path_background']; // get this named path
var myExistingOutlinedGroup = idoc.groupItems['text_outlined']; // get this named group
myExistingPath.evenodd = true;
myExistingOutlinedGroup.evenodd = true;
myExistingPath.moveToBeginning(icompound);
myExistingOutlinedGroup.moveToBeginning(icompound);
Copy link to clipboard
Copied
I am not so sure you need a script for this if I am understanding your problem correctly. You can probably use the Pathfinder tool to Unite the selected elements into a compound shape. Then you just have to select that newly created object entirely, ungroup it and make it a compound path (command + 8 is the key command, but I forget where that may be in the menus).
So you select the objects you want
Open your Pathfinder window - Window > Pathfinder
Click on the Unite button in there - Should be the first one under Shape Modes
While everythign is still selected, ungroup it all - Object > Ungroup (repeat until completely ungrouped)
Then make a compound path - Object > Compound Path > Make
You can record an action ofo this process if you think this will be a common task, but I do not think you need a script to do it. This is the process I use all the time.
I apologize if I misunderstood your problem. I came here looking for something else and stumbled on this one.
Copy link to clipboard
Copied
https://forums.adobe.com/message/8993551?et=notification.mention#8993551
- app.executeMenuCommand("compoundPath");
Find more inspiration, events, and resources on the new Adobe Community
Explore Now