: Selecting same shapes in vector files I have a vector file contains over 500 circle , the diameter of circles are different ( 5mm , 5.5mm and 10mm). are there any ways to select all same
I have a vector file contains over 500 circle , the diameter of circles are different ( 5mm , 5.5mm and 10mm). are there any ways to select all same shape circle (for example all 5mm diameter ) and change the back color ?
More posts by @Holmes874
2 Comments
Sorted by latest first Latest Oldest Best
Technically illustrator does not know they are circles. I mean they are implementing this feature slowly (in all the wrong ways), and it wouldn't really solve any problems not related to SVGs. Long story short internally they are just paths. In fact if one is really pedantic illustrator can not even make circles, just something close to circle.
So obviously illustrator can not select circles, since it has no clue about such things. However that does not mean we can not detect them we just need a bit different way to define what we are looking for.
First we could just detect the area of objects. Since we know that the are a of circle is π r2. We can select all the objects that qualify for this.
Well so far so fun. But this could detect a number of shapes that are not circles. But we could add more checks, we know that the perimeter of a circle is 2 π r, now we are on quite safe ground, but we could still select a bunch of things that are same so we might as well throw some more checks in and say that the number of points shall be 4 and the path is closed. We could go even further and make sure the bounding box is square and the bb center is at point average, and that the tangents have a specific length but that's a bit overkill for most scenarios.
This is how you would do that:
#target illustrator
var objs = app.activeDocument.pageItems;
traverseSceneObjects(objs, selectCircle);
//Define radius to appenf to selection
var radius = 10;
var circle_perimeter = 2 * Math.PI * mm2points(radius);
var circle_area = Math.PI * Math.pow(mm2points(radius), 2);
function selectCircle(item){
if ( compare(item.length, circle_perimeter) &&
compare(item.area, circle_area) &&
item.pathPoints.length == 4 &&
item.closed
)
item.selected = true;
}
function traverseSceneObjects(pageItems, func){
for (var iter=0 ; iter<pageItems.length; iter++ ){
var item = pageItems[iter];
var typename = item.typename;
// apply action or get the subitems of object
if (typename === "PathItem"){
func(item);
} else if (typename === "GroupItem") {
traverseSceneObjects( item.pageItems );
} else if (typename === "CompoundPathItem" ) {
traverseSceneObjects( item.pathItems );
}
}
}
function compare(a, b){
return Math.abs( a - b) < 0.01 * a;
}
function mm2points(mm){
return 2.83464567 * mm;
}
Illustrator offers no ability to select objects which are the same size or dimensions.
All the options to select similar objects are in Select > Same:
You may be able to accomplish this via scripting, but that's out of my wheelhouse.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.