-
1. Re: object dimensions to text
PrepressPro1 Jul 30, 2009 2:29 PM (in response to PrepressPro1)Wow, totally snubed. I'm new to scripting and need help but I don't see any responce. Is this an extremely difficult script to learn, or write, or find?
-
2. Re: object dimensions to text
grizzlyburr Jul 30, 2009 6:47 PM (in response to PrepressPro1)Can you be a little more specific about what you're attempting?
Do you just want a text frame that has the same dimensions as the page item, or are you wanting the your text to be typed along a path with the same path points as your reference object (see the "Type on a Path Tool" in your tools palette).
Cheers.
-
3. Re: object dimensions to text
PrepressPro1 Jul 30, 2009 9:58 PM (in response to grizzlyburr)I want to have several shapes which I have grouped. So I need the dimensions of all these shapes when grouped (the parameter or foot print) to a single stand alone line of text. I can cut and paste these dimensions from the W and H in the transform panel to a line of text to indicate the foot print of all the shapes selected. In essence I need to get the W and H to magically appear as a line of text in the illustrator file. Then I could add the script to the current set of actions I use for this process and automate the process. Does this make more sense?
-
4. Re: object dimensions to text
grizzlyburr Jul 30, 2009 11:27 PM (in response to PrepressPro1)Okay, I think I follow now. Something like this might work:
myDoc = app.activeDocument;
findDims(myDoc.groupItems);
findDims(myDoc.pathItems);
function findDims(objs) {
for (i=objs.length-1;i>=0;i--) { //loop through your collection of objects
if (objs[i].parent.constructor != GroupItem) { // Check if parent is a groupItem and skip if it is
descFrame = myDoc.textFrames.add(); // Create the text frame
descFrame.contents = "W: "+objs[i].width + "pts\rH: " + objs[i].height + "pts"; // Adds contents to frame
descFrame.position = [objs[i].left,objs[i].top - objs[i].height - 5]; // Positions the frame
}
}
}
Cheers.
-
5. Re: object dimensions to text
Larry G. Schneider Jul 31, 2009 10:14 AM (in response to grizzlyburr)Works fine even for grouped objects, but remember that a script added to an action does not survive a restart. The action must be remade each time.
-
6. Re: object dimensions to text
PrepressPro1 Jul 31, 2009 10:35 AM (in response to grizzlyburr)myDoc = app.activeDocument;
findDims(myDoc.groupItems);
findDims(myDoc.pathItems);
function findDims(objs) {
for (i=objs.length-1;i>=0;i--) { //loop through your collection of objects
if (objs[i].parent.constructor != GroupItem) { // Check if parent is a groupItem and skip if it is
descFrame = myDoc.textFrames.add(); // Create the text frame
descFrame.contents = "W: "+objs[i].width + "pts\rH: " + objs[i].height + "pts"; // Adds contents to frame
descFrame.position = [objs[i].left,objs[i].top - objs[i].height - 5]; // Positions the frame
}
}
}
Seeing as I'm so new to the scripting process I need to get more information. I have saved the text I'm quoting into a text file with a .scpt extension. Then I run this in Illustrator under File>Script>Other Script. Currently all I get is a blank dialog box with an OK button. Can you help clue me into what i might do to get this to run.
-
7. Re: object dimensions to text
Larry G. Schneider Jul 31, 2009 11:14 AM (in response to PrepressPro1)The script provided is a cross-platform JavaScript. You will need to paste it into a text editing program (BBEdit, TextEdit or the like) and save it with a .jsx extension. Put that file in AICS3 (or CS4)>Presets>Scripts folder and restart AI. The script will appear in File>Scripts and can be selected from there. A couple of other points. If you want inches, just add a /72 behind the objs[i].width and objs[i].height. You might also want to add a space in front of the units in both places.
-
8. Re: object dimensions to text
PrepressPro1 Jul 31, 2009 12:10 PM (in response to Larry G. Schneider)Larry G. That's not good news that I can't have the action work after restart. Perhaps I can use the Insert Menu Item… as a work around. Thanks for the heads up on this being a javascript and not a applescript, as you can see I don't know a script from a hole in the ground. I will try running it as a java.
-
9. Re: object dimensions to text
Larry G. Schneider Jul 31, 2009 12:22 PM (in response to PrepressPro1)It doesn't matter how you make the Action. It won't survive the restart. It's be the same since AI10 so don't expect is to change anytime soon.
-
-
11. Re: object dimensions to text
Larry G. Schneider Jul 31, 2009 12:32 PM (in response to PrepressPro1)From the Format menu in TextEdit, choose Make Plain Text and then save. Make sure you override the .txt and call it a.jsx file.
-
12. Re: object dimensions to text
Larry G. Schneider Jul 31, 2009 2:39 PM (in response to Larry G. Schneider)The script as written uses the geometric bounds of the items. If you want to use the visible bounds, you can do something like the following
myDoc = app.activeDocument;
findDims(myDoc.groupItems);findDims(myDoc.pathItems);
function findDims(objs) {for (i=objs.length-1; i>=0; i--) { //loop through your collection of objects
var vb = objs[i].visibleBounds; // left, top, right, bottom
var w = (vb[2] - vb[0]);
var h = (vb[1] - vb[3]);if (objs[i].parent.constructor != GroupItem) { // Check if parent is a groupItem
descFrame = myDoc.textFrames.add(); // Create the text frame
descFrame.contents = "W: "+ w/72 + " in\rH: " + h/72 + " in"; // Adds contents to frame
descFrame.position = [objs[i].left, objs[i].top - objs[i].height - 5]; // Positions the frame
}
}
}
-
13. Re: object dimensions to text
PrepressPro1 Aug 3, 2009 3:12 PM (in response to Larry G. Schneider)This script is giving me the dimensions of all the object in the document. Is there a way to edit this script so it only gives the geometric dimensions for the currently selected objects, in inches, with only four decimal places? I know, I'm asking alot more then the orignal question.
-
14. Re: object dimensions to text
Larry G. Schneider Aug 4, 2009 1:20 PM (in response to PrepressPro1)If you comment out the line
findDims(myDoc.pathItems)
with two slashes (//findDims(myDoc.pathItems)) it will only do the grouped items in the file. I haven't had any luck figuring out how to set it to the selection yet.
-
15. Re: object dimensions to text
grizzlyburr Aug 4, 2009 5:41 PM (in response to Larry G. Schneider)You should be able to target the currently selected items by changing the function's parameter.
findDims(app.selection);
If you want the width and height rounded to four decimals you can multiply your w and h values by 10000, use the round() method, and then divide the result by 10000.
var w = (vb[2] - vb[0]);
var w = Math.round(w*10000);
var w = w/10000;
or
var w = Math.round((vb[2]-vb[0])*10000)/10000;
var h = Math.round((vb[1]-vb[3])*10000)/10000;
-
16. Re: object dimensions to text
PrepressPro1 Dec 2, 2010 1:56 PM (in response to grizzlyburr)I'm just getting back into this project and finding the current java script has the habbit of adding dimensions to all objects in the document and not just the ones selected. Any way to get this to run on the objects which are current selected or objects which are not hidden. The first script will spit out dimensions even for the items which are currently hidden.
-
17. Re: object dimensions to text
PrepressPro1 May 11, 2011 12:01 PM (in response to grizzlyburr)Here is my current script which you told me to add finddim(app.selection); to and it worked to give the dimentions of only the selected group of items. I can't seem to get the four decimal lines to work. Not sure where they go or if they replace other lines. The attempts I have made to add the math round and devide lines has not yielded any results. I was also trying to figure out how the text is placed and if I can make the script place the resulting text to the top center of the selected objects as well as making the objects dimentions of the actual vectors and not the visiable object (vectors + stroke).
myDoc = app.activeDocument; findDims(app.selection); function findDims(objs) { for (i=objs.length-1; i>=0; i--) { //loop through your collection of objects var vb = objs[i].visibleBounds; // left, top, right, bottom var w = (vb[2] - vb[0]); var h = (vb[1] - vb[3]); if (objs[i].parent.constructor != GroupItem) { // Check if parent is a groupItem descFrame = myDoc.textFrames.add(); // Create the text frame descFrame.contents = "W: "+ w/72 + " in\rH: " + h/72 + " in"; // Adds contents to frame descFrame.position = [objs[i].left, objs[i].top - objs[i].height - 5]; // Positions the frame } } } -
18. Re: object dimensions to text
Larry G. Schneider May 11, 2011 2:41 PM (in response to PrepressPro1)Does this help
#target illustrator
if (app.documents.length > 0)
{
var idoc = app.activeDocument;
sel = idoc.selection;
if (sel.length==1)
{
//alert("selection = 2")
var vb = sel[0].visibleBounds; // left, top, right, bottom
var w = (vb[2] - vb[0])/72;
var h = (vb[1] - vb[3])/72;
descFrame = myDoc.textFrames.add(); // Create the text framedescFrame.contents = "W: "+ w.toFixed (4) + " in\rH: " + h.toFixed (4) + " in"; // Adds contents to frame
descFrame.position = [sel[0].left, sel[0].top + 25]; // Positions the frame
}
} -
19. Re: object dimensions to text
CarlosCanto May 11, 2011 2:55 PM (in response to PrepressPro1)I took the liberty to modify grizzlyburr script
#target Illustrator // script by grizzlyburr? myDoc = app.activeDocument; findDims(app.selection); function findDims(objs) { for (i=objs.length-1; i>=0; i--) { //loop through your collection of objects var vb = objs[i].geometricBounds; // left, top, right, bottom var w = (vb[2] - vb[0]); var h = (vb[1] - vb[3]); if (objs[i].parent.typename != "GroupItem") { // Check if parent is a groupItem descFrame = myDoc.textFrames.add(); // Create the text frame var W = w/72; var H = h/72; W = W.toFixed(4); H = H.toFixed(4); descFrame.contents = "W: "+ W + " in\rH: " + H + " in"; // Adds contents to frame descFrame.position = [objs[i].left, objs[i].top + descFrame.height + 5]; // Positions the frame } } } -
20. Re: object dimensions to text
PrepressPro1 May 11, 2011 3:26 PM (in response to Larry G. Schneider)Very nice, I had to tweek the start lines to get it to run. Now the dimensions appear as text at the upper left of the object/group of objects selected. The dimensions are still showing the appearance size and not the actual vector size, but now there're down to the four decimal places I was looking for. So I will review the previous scripts and see if I can figure out how the visibleBounds line might be changed to affect the size results I'm getting. What line relates to the placement of the text position? I'm guessing it's descFrame.position. How would I change this line to arrive at the text being centered and 1.125" away from the object? Here is what I ended up with after changing your last post…
#target illustrator
myDoc = app.activeDocument;
if (app.documents.length > 0)
 {
 
 var idoc = app.activeDocument;
 sel = idoc.selection;
 if (sel.length==1)
 {
 //alert("selection = 2")
 var vb = sel[0].visibleBounds; // left, top, right, bottom

 var w = (vb[2] - vb[0])/72;
 var h = (vb[1] - vb[3])/72;

 
descFrame = myDoc.textFrames.add(); // Create the text frame
descFrame.contents = "W: "+ w.toFixed (4) + " in\rH: " + h.toFixed (4) + " in"; // Adds contents to frame
descFrame.position = [sel[0].left, sel[0].top + 25]; // Positions the frame

}

} -
21. Re: object dimensions to text
PrepressPro1 May 11, 2011 3:33 PM (in response to CarlosCanto)Carlos, yours seems to be working out the best so far. Have to leave for the day. hopefully I will be able to work on this tomorrow. Thanks all.
-
22. Re: object dimensions to text
CarlosCanto May 11, 2011 7:07 PM (in response to PrepressPro1)here you go
#target Illustrator // script by grizzlyburr? myDoc = app.activeDocument; findDims(app.selection); function findDims(objs) { for (i=objs.length-1; i>=0; i--) { //loop through your collection of objects var vb = objs[i].geometricBounds; // left, top, right, bottom // * changed to geometricBounds var w = (vb[2] - vb[0]); var h = (vb[1] - vb[3]); if (objs[i].parent.typename != "GroupItem") { // Check if parent is a groupItem descFrame = myDoc.textFrames.add(); // Create the text frame var W = w/72; // * var H = h/72; // * W = W.toFixed(4); // * H = H.toFixed(4); // * descFrame.contents = "W: "+ W + " in\rH: " + H + " in"; // Adds contents to frame var distanceFromTop = 1.125*72; // * var x = objs[i].left+w/2-descFrame.width/2; // * var y = objs[i].top + descFrame.height + distanceFromTop; // * descFrame.position = [x,y]; // * //descFrame.position = [objs[i].left, objs[i].top + descFrame.height + 1.125*72]; // Positions the frame } } } -
23. Re: object dimensions to text
PrepressPro1 May 12, 2011 9:29 AM (in response to CarlosCanto)That did it. This worked Great.
-
24. Re: object dimensions to text
PrepressPro1 May 12, 2011 11:20 AM (in response to PrepressPro1)I think I should rail on Adobe for not allowing me to use Java Script in an Action. This menu item in Illustrator is still broken, does anyone think Adobe will ever fix this known BUG?!? Any way to set up a keyboard shortcut in Illustrator to run Java Scripts? The only Keyboard shortcut I could find only allows you to navigate to a Script, and not to run a specific Script.
Anyway, thanks to all who contributed to this Script.
-
25. Re: object dimensions to text
Larry G. Schneider May 13, 2011 9:32 AM (in response to PrepressPro1)This may give you some more information of what's happening with using a script in an action.






