femkeblanco
Guide
femkeblanco
Guide
Activity
‎Nov 03, 2020
12:13 PM
1 Upvote
hhas01's solution works nicely. So I think the job is done.
... View more
‎Nov 03, 2020
02:26 AM
1 Upvote
I will make no promises, but if you upload a CS6-compatible version of your AI document, I will have a look.
... View more
‎Nov 02, 2020
10:51 AM
2 Upvotes
groupOverlappingObjects by John Wundes: /////////////////////////////////////////////////////////////////
//Group Overlapping (Beta) -- CS, CS2, CS3
//>=--------------------------------------
//
// Groups all overlapping objects in selection into discreet groups.
// The definition for 'overlaping' is based on objects bounding boxes, not their actual geometry.
// Each new groups zOrder is determined by the depth of the front-most object in each group.
// There is no limit to the number of groups created.
// Any non-overlapping objects are ignored.
//
// Note: Currently, this is not very efficient code. It works well on small groups (less than 120 objects)
// and works faster on smaller groupings. Running this on a huge number of objects will likely crash illustrator.
// It serves my purposes, but test it's limits on your machine, and use at your own risk.
// On a 2.53GHz P4, a group of 100 objects took 20 seconds with 2 groups.
//
//
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( john@wundes.com ) www.wundes.com
//copyright full text here: http://www.wundes.com/js4ai/copyright.txt
//////////////////////////////////////////////////////////////////
//this little section is just for testing
//the number of times each function is called.
var testmode = 0;
var t1=t2=t3=t4=t5=t6=t7=0;
var testmsg="";
//
//
//
var go=true;
if(selection.length>120){
go = confirm("You have selected "+selection.length+" objects. It is highly recommended that you select less than 120 objects at a time. Do you want to continue anyway?");
}
if(selection.length>1 && go == true){
var groups=0;
var slen = selection.length;
var hitList= new Array(slen);
var groupArr = new Array(slen);
// for each element in selection
for (var sx=0;sx<slen;sx++){
//t6++; //---------------------------------------------loop tracker
var tArr = new Array(0);
// for each element in selection (again)
for (var si=0;si<slen;si++){
//t7++; //-------------------------------------loop tracker
groupArr[sx] = tArr;
//note each object hits itself once.
if(hitTest(selection[sx],selection[si])){
groupArr[sx].push(selection[si]);
}
}
}
minimize(groupArr);
var zError = 0;
var gaLen = groupArr.length;
for(var each=0;each<gaLen;each++){
if(groupArr[each].length>1){
groupArr[each].sort(sortBy_zOrder);
}
if(zError==1){
alert("cannot read some objects zOrderPosition");
}
//alert("halftime");
for(var each =0;each<gaLen;each++){
t1++; //----------------------------------------------loop tracker
if(groupArr[each].length>1){
groups++;
groupAll(groupArr[each]);
}
}
//
//---all done with main code, now display statistics if you care...
//
testmsg="\nObjects processed: "+t1+"\nObjects grouped: "+t2+"\nObjects ignored: "+(t1-t2);
if(testmode==1){
testmsg+="\n\n---testmode data---\nhits compared: "+t5+"\nfunction 'minimize' called: "+t3+
"\nitems tested within 'minimize': "+t4;
"\nelements: "+t6+
"\nelements*elements: "+t7;
}
var x=0;
while(x<selection.length){
if(selection[x].name == "wundes_GO_group"){
selection[x].name = "";
}else{
selection[x].selected = false;
x--;
}
x++;
}
redraw();
alert(groups+" groups created.\n----------------"+testmsg);
}
}
//----------------------------------------------------------->
//--------------------------------functions------------------<
//----------------------------------------------------------->
function sortBy_zOrder(a, b) {
if(a.zOrderPosition==undefined){
alert(a.zOrderPosition);
zError = 1;
return 0;
}
var x = Number(a.zOrderPosition);
var y = Number(b.zOrderPosition);
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
function groupAll(arr){
var tempGroup = arr[0].parent.groupItems.add();
tempGroup.move(arr[0],ElementPlacement.PLACEBEFORE);
var max = arr.length;
for(var i=max-1;i>=0;i--){
t2++; //-----------------------------------------loop tracker
arr[i].move(tempGroup,ElementPlacement.INSIDE);
}
//name the object for selection at end... (will be removed later)
tempGroup.name = "wundes_GO_group";
tempGroup.selected = true;
}
//---------------hitTest functions ---------------
function hitTest(a,b){
var OK=0;
if(isWithinX(a,b) || isWithinX(b,a)){
OK++;
}
if(isWithinY(a,b) || isWithinY(b,a)){
OK++;
}
if (OK<2){
//alert("miss.");
return false;
}else{
//alert("Hit!")
return true;
}
}
function isWithinX(a,b){
var p1 = a.geometricBounds[0];
var p2 = b.geometricBounds[0];
if(p2<=p1 && p1<=p2+b.width){
return true;
}else{
return false;
}
}
function isWithinY(a,b){
var p3 = a.geometricBounds[1];
var p4 = b.geometricBounds[1];
if(p3>=p4 && p4>=(p3-a.height)){
return true;
}
return false;
}
/*
//-----------------------------------OK, finding groups is done, now do the grouping---------------
*/
function itemize(a){
var out="";
return(a.join("\n"));
}
function minimize(arr){
for(var e in arr){
t3++; //-----------------------------------------loop tracker
for (ot in arr){
t4++; //-------------------------------------loop tracker
if(arr[e]!=arr[ot]){
//if it's not THIS element,
//test for overlaps
if(overlaps(arr[e],arr[ot])){
merge(arr[e],arr[ot]);
arr[e] = new Array(0);
minimize(arr);
break;
}
}
}
}
}
function merge(a,b){
var alen = a.length;
for (var all=0;all<alen;all++){
if(contains(b,a[all])){
//do nothing
}else{
b.push(a[all]);
}
}
}
function contains(ar,i){
for (var all in ar){
if (ar[all] == i){
return true;
}
}
return false;
}
function overlaps(ar1,ar2){
for (var each in ar1){
t5++; //------------------------------------loop tracker
if(contains(ar2,ar1[each])){//
return true;
}
}
return false;
}
... View more
‎Oct 30, 2020
01:15 PM
1 Upvote
Add this line at the beginning of the script // make a new group
var group = app.activeDocument.activeLayer.groupItems.add(); and add this line // move the circle into the group
pi.move(group, ElementPlacement.PLACEATBEGINNING); before the closing curly bracket (}) before the line m1b mentioned, i.e. before this }
if(err_fail_to_find_center == 1)
... View more
‎Oct 29, 2020
07:22 AM
1 Upvote
Yes, this corresponds to the pathfinder effect in the effect menu and applies an effect, an appearance attribute, which would then need expanding. There is no counterpart to the pathfinder panel in ExtendScript.
... View more
‎Oct 29, 2020
02:33 AM
1 Upvote
Unfortunately, that's the way it is with the scripting references. To make ​matters worse, there are things left out of the references completely, even though they have been an open secret for years. I suspect that this is apathy rather than cynicism. On a positive note, this forum will more often than not give you the answer you're looking for. Edit: Similarly, I seem to remember that the x and y elements of the "position" property cannot be assigned individually, i.e. "position" must be assigned an array [x, y].
... View more
‎Oct 26, 2020
03:49 AM
1 Upvote
I am not at my PC, so I cannot run your code, but before anything else activeDocument is not a collection. So your first two lines (in both snippets) should contain activeDocument and documents[1], respectively, or documents[0] and documents[1], respectively.
... View more
‎Oct 25, 2020
04:01 AM
1 Upvote
Assuming one artboard, this should resize it: var AB = app.activeDocument.artboards[0];
var w = 24 * 72;
var h = 24 * 72;
AB.artboardRect = [AB.artboardRect[0], AB.artboardRect[1], w, -h]; Adding this line app.executeMenuCommand("unitundoPref"); at the end will bring up the units dialog box, but you will have to select your units manually. Also, this causes buggy behaviour for me in CS6.
... View more
‎Oct 22, 2020
05:20 PM
2 Upvotes
I'm late, but here is my easy-to-make version. var d = app.activeDocument.artboards[0].artboardRect;
var paths = app.activeDocument.pathItems;
var circle1 = paths.ellipse(d[3]/2+250, d[2]/2-250, 500, 500);
var polygon1 = paths.polygon(d[2]/2, d[3]/2, 250, 12);
polygon1.rotate(15);
var points1 = polygon1.pathPoints;
var group1 = app.activeDocument.groupItems.add();
for (var i = 0; i < points1.length; i++) {
for (var j = 0; j < points1.length; j++) {
var line1 = paths.add();
var points2 = [points1[i].anchor, points1[j].anchor];
line1.setEntirePath(points2);
line1.moveToEnd(group1);
}
}
var group2 = group1.duplicate();
group2.resize(70.7, 70.7);
group2.rotate(15);
var group3 = group2.duplicate();
group3.resize(73.2, 73.2);
var group4 = group3.duplicate();
group4.resize(70.7, 70.7);
group4.rotate(15);
... View more
‎Oct 22, 2020
10:38 AM
4 Upvotes
app.executeMenuCommand("Live Pathfinder Subtract"); Group the pathItems first.
... View more
‎Oct 21, 2020
05:01 AM
embedLinkedFiles and IllustratorSaveOptions are used with the saveAs() function. You do not have a saveAs() function in your code. Alternatively, you can go through your placedItems and embed them individually for (var i = 0; i < app.activeDocument.placedItems.length; i ++) {
app.activeDocument.placedItems[i].embed();
}
... View more
‎Oct 20, 2020
03:44 PM
1 Upvote
This is a basic idea: var groups = app.activeDocument.groupItems;
var d = app.activeDocument.artboards[0].artboardRect;
rect1 = app.activeDocument.pathItems.rectangle(d[1], d[0], d[2], -d[3]);
app.executeMenuCommand( "selectall" );
app.executeMenuCommand( "group" );
groups[0].rotate(-90);
app.executeMenuCommand( "deselectall" );
rect1.selected = true;
app.executeMenuCommand( "setCropMarks" );
app.activeDocument.artboards[0].remove();
app.executeMenuCommand( "selectall" );
app.executeMenuCommand( "ungroup" );
app.executeMenuCommand( "deselectall" );
... View more
‎Oct 20, 2020
02:29 PM
var docs = app.documents;
var saveOptions = new IllustratorSaveOptions();
saveOptions.embedLinkedFiles = true;
for (var i = docs.length - 1; i > -1; i--) {
var path1 = "/C/Users/.../Desktop/" + docs[i].name;
var file1 = new File(path1)
docs[i].saveAs(file1, saveOptions);
docs[i].print();
docs[i].close(SaveOptions.SAVECHANGES);
} NB Change "..." in the path in line 5 to your destination. I have not tested the print function. To centre your view (Ctrl+0), you can add executeMenuCommand("fitin");​ but I suspect this is not what you want (it'll centre your view, not your objects).
... View more
‎Oct 13, 2020
06:38 AM
See Charu's suggestion below: https://community.adobe.com/t5/illustrator/can-someone-please-give-me-a-script-that-changes-the-ruler-metric/m-p/11286198?page=1#M185500
... View more
‎Oct 09, 2020
12:43 PM
The only suggestion I can think of is to save as an even earlier version. Change the 17 in the script to 16. If the message still shows, there must be something in your document which is incompatible with earlier versions.
... View more
‎Oct 09, 2020
12:37 PM
1 Upvote
To save as PDF, change this thisDoc.saveAs(newFile); to this thisDoc.saveAs(newFile, saveOpts);
... View more
‎Oct 08, 2020
02:48 PM
1 Upvote
Copy and paste it in a jsx file. (You can create a txt file and change the extension to jsx.) Then, while your document is open in Illustrator, go to File > Scripts > Other Script (Ctrl+F12). Find your script and open it.
... View more
‎Oct 08, 2020
02:46 PM
2 Upvotes
You beat me to it, Silly-V. This is what I cam up with: var doc = app.activeDocument;
for (var i = 0; i < doc.artboards.length; i++) {
doc.artboards.setActiveArtboardIndex(i);
doc.selectObjectsOnActiveArtboard();
for (var j = 0; j < selection.length; j++) {
if (selection[j].typename == "PlacedItem") {
doc.artboards[i].name = selection[j].name;
}
}
}
... View more
‎Oct 08, 2020
02:01 AM
1 Upvote
I use CS6 and cannot test it, but try this: (Again, replace "..." in the path in line 3 below with your destination.) var layer1 = app.activeDocument.layers["Layer 1"];
var layer2 = app.activeDocument.layers["Layer 2"];
var file1 = new File("/C/Users/.../Desktop/yourFileName");
var AI = new IllustratorSaveOptions();
AI.compatibility = Compatibility.ILLUSTRATOR17;
var PDF = new PDFSaveOptions();
layer2.remove();
app.activeDocument.saveAs(file1, AI);
app.undo();
layer1.remove();
app.activeDocument.saveAs(file1, PDF);
app.undo(); And see: https://community.adobe.com/t5/illustrator/illustratorsaveoptions-compatibility-javascript-reference-for-cc2019/td-p/11200247?page=1
... View more
‎Oct 07, 2020
02:14 PM
Which lower version of AI do you need?
... View more
‎Oct 07, 2020
01:45 PM
Adobe will get right on it and rebuild it for you from scratch.
... View more
‎Oct 05, 2020
01:22 PM
I cannot help you, but I will suggest Hiroyuki Sato's script Join Reasonably. http://shspage.com/aijs/en/#join_reasonably This will work on simple 2D shapes, but will produce extra lines on 2D representations of 3D objects.
... View more
‎Oct 04, 2020
11:36 PM
This is a primitive way of grouping path items with the same stroke color. var paths = app.activeDocument.pathItems;
for (var i = 0; i < paths.length; i++) {
if (paths[i].parent != "GroupItem") {
paths[i].selected = true;
app.executeMenuCommand("Find Stroke Color menu item");
app.executeMenuCommand("group");
app.executeMenuCommand("deselectall");
}
} I'm afraid I don't understand the second part of your question.
... View more
‎Oct 02, 2020
10:25 AM
Silly-V When I run your snippet, the copied compound paths are released.
... View more
‎Oct 02, 2020
10:14 AM
3 Upvotes
As Charu Rajput said, test for it as such textFonts[i].style == "Bold" For example, this should produce a list of your bold fonts: var list1 = "";
for (var i = 0; i < textFonts.length; i++){
if (textFonts[i].style == "Bold") {
list1 = list1 + textFonts[i].name + ", "
}
}
alert ( list1 );
... View more
‎Oct 02, 2020
01:08 AM
pic1 is a placedItem, the background picture, and file1 is the file containing the picture.
... View more
‎Oct 01, 2020
04:02 PM
I don't know where to take this next. It's working for me.
... View more
‎Oct 01, 2020
03:25 PM
And if you have your srcDoc open and your targetDoc open and you run the script while in targetDoc? Also, there was an "app" missing in the second line in the snippet I posted above. So it should be: var file1 = File.openDialog();
var pic1 = app.activeDocument.placedItems.add();
pic1.file = file1;
var srcDoc = app.documents[1];
var targetDoc = app.documents[0].layers.add();
var _sel = app.activeDocument.selection[0];
for (var i = 0; i < srcDoc.pathItems.length; i++) {
if (srcDoc.pathItems[i].parent.typename == "CompoundPathItem") {
continue;}
srcDoc.pathItems[i].duplicate(targetDoc, ElementPlacement.PLACEATBEGINNING);
}
for (var i = 0; i < srcDoc.compoundPathItems.length; i++) {
srcDoc.compoundPathItems[i].duplicate(targetDoc, ElementPlacement.PLACEATBEGINNING);
... View more
‎Oct 01, 2020
02:36 PM
Assuming you're running the script while in the last created document, and replacing the whole code in your original post with the below, what happens? var file1 = File.openDialog();
var pic1 = activeDocument.placedItems.add();
pic1.file = file1;
var srcDoc = app.documents[1];
var targetDoc = app.documents[0].layers.add();
var _sel = app.activeDocument.selection[0];
for (var i = 0; i < srcDoc.pathItems.length; i++) {
if (srcDoc.pathItems[i].parent.typename == "CompoundPathItem") {
continue;}
srcDoc.pathItems[i].duplicate(targetDoc, ElementPlacement.PLACEATBEGINNING);
}
for (var i = 0; i < srcDoc.compoundPathItems.length; i++) {
srcDoc.compoundPathItems[i].duplicate(targetDoc, ElementPlacement.PLACEATBEGINNING);
}
... View more
‎Oct 01, 2020
01:31 PM
for (var i = 0; i < srcDoc.pathItems.length; i++) {
if (srcDoc.pathItems[i].parent.typename == "CompoundPathItem") {
continue;}
srcDoc.pathItems[i].duplicate(targetDoc, ElementPlacement.PLACEATBEGINNING);
}
for (var i = 0; i < srcDoc.compoundPathItems.length; i++) {
srcDoc.compoundPathItems[i].duplicate(targetDoc, ElementPlacement.PLACEATBEGINNING);
}
... View more