Copy link to clipboard
Copied
How can I determine the orientation of an item (GroupItem, TextFrameItem, PathItem, SymbolItem) placed on a layer? If it is rotated, how can I determine the angle of rotation? PageItem has a rotate method that causes it to be rotated, but I can't find anything that says how much it has been rotated.
Copy link to clipboard
Copied
You need to retrieve the objects matrix values and calculate from those.
Copy link to clipboard
Copied
Objects do not have "matrix" values, but they do have controlBounds, visibleBounds, and geometricBounds. Unfortunately, it is not possible to use these to distinguish whether the object is rotated 180 degrees, since the values of these will be identical at 0 and 180 degrees, or for that matter, any orientation 180 degrees apart from another orientation. If the object has equal width and length, it is not even possible to determine whether it has been rotated 90 degrees. Objects also have position, top, height, left, and width which can be derived from the above, so they don't provide any additional information. Determining rotation from 0 to 180 degrees using the above requires using time-consuming trig functions, but you still cannot determine whether you are off by 180 degrees. Illy knows how much the object has been rotated, but it does not appear willing to provide that information to the Javascript programmer.
Copy link to clipboard
Copied
Looking though documentation I do not see any way to retrieve or access any type of rotation history. What is it exactly you are trying to accomplish? Are the shapes of the objects known up front? You may be able to store the initial positions of each point in the object in tags as an array on points, assuming it's a path object, and figure out the rotation from watching how those numbers have changed. Would take some trig though.
Copy link to clipboard
Copied
This is NOT mine but an example of using matrix's found here in the forum. All being well it will turn a text frame back straight.
#target illustrator var docRef=app.activeDocument; if (docRef.selection.length > 0) { for (i = 0; i < docRef.selection.length; i++){ var objRef = docRef.selection; if (objRef.typename == "TextFrame") { var A = objRef.matrix.mValueA; var B = objRef.matrix.mValueB; var C = objRef.matrix.mValueC; var D = objRef.matrix.mValueD; if (B+C != 0){ var currScale = (D/A)*100; alert(currScale); objRef.width*=(D/A); } do{ var currSin = objRef.matrix.mValueC; var currDeg = Math.asin(currSin)*(180/Math.PI); objRef.rotate(currDeg,1,1,1,1,Transformation.CENTER); }while(objRef.matrix.mValueC != 0); } } redraw(); alert("Now select Object > Transform > Reset Bounding Box to unrotate the textFrame bounding boxes."); }
This should give you a good idea of the basic principle and the math required… Hope it helps you…
Copy link to clipboard
Copied
Of the descendents of PageItem (CompoundPathItem, GraphItem, GroupItem, LegacyTextItem, MeshItem, NonNativeItem, PathItem, PlacedItem, PluginItem, RasterItem, SymbolItem, and TextFrameItem), only PlacedItem, RasterItem, and TextFrameItem have a matrix property. For the others, how does one access the matrix values? It's possible the plug-in libraries in C might work, i.e. AISymbolSuite, AIRasterSuite, etc.. Is it possible to access these from javascript? How?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now