Copy link to clipboard
Copied
Basically, we get DXF files that are exported from SolidWorks. Every individual line is in its own group. Not everyone remembers to ungroup everything until it's only paths before grouping lines together as parts. This wreaks havoc when we need to add color to parts, as we need to ungroup everything to use Live Paint.
What I want to be able to do is go through all items (say, on the current layer) and drill down to find nested groups that contain only one item (either a group, or a path, or text) and move that item up one level, either to the parent group or even the layer.
Any thoughts?
Copy link to clipboard
Copied
Found the following script (worked great):
// RefineGroup.js
// http://www.pictrix.jp/ Umezawa
// 05.4.16 3:56 PM
var Count = 0;
function engine( obj )
{
var i, itm;
if ( obj.layer.locked == true || obj.layer.visible == false) return;
if ( obj.locked == true || obj.hidden == true ) return;
if ( obj.groupItems.length ){
for ( i = 0; i < obj.groupItems.length; i++ ){
engine( obj.groupItems[ i ] );
}
}
else{
itm = obj.pathItems.length
+ obj.compoundPathItems.length
+ obj.textFrames.length
+ obj.placedItems.length
+ obj.rasterItems.length
+ obj.meshItems.length
+ obj.pluginItems.length
+ obj.graphItems.length
+ obj.symbolItems.length ;
if ( itm == 1 ){
if ( obj.pathItems.length ) itm = obj.pathItems[ 0 ];
else if ( obj.compoundPathItems.length ) itm = obj.compoundPathItems[ 0 ];
else if ( obj.textFrames.length ) itm = obj.textFrames[ 0 ];
else if ( obj.placedItems.length ) itm = obj.placedItems[ 0 ];
else if ( obj.rasterItems.length ) itm = obj.rasterItems[ 0 ];
else if ( obj.meshItems.length ) itm = obj.meshItems[ 0 ];
else if ( obj.pluginItems.length ) itm = obj.pluginItems[ 0 ];
else if ( obj.graphItems.length ) itm = obj.graphItems[ 0 ];
else if ( obj.symbolItems.length ) itm = obj.symbolItems[ 0 ];
if ( itm.locked == false && itm.hidden == false ){
itm.move ( obj, ElementPlacement.PLACEBEFORE );
Count++;
}
}
}
}
//************************************************************
if ( documents.length > 0 && activeDocument.groupItems.length > 0 ){
if ( activeDocument.selection.length > 0 ){
selObj = activeDocument.selection;
for ( i = 0; i < selObj.length; i++ ){
if ( selObj[ i ].typename == "GroupItem" )
engine( selObj[ i ] );
}
gCount = Count;
while( Count != 0 ){
redraw( );
selObj = activeDocument.selection;
Count = 0;
for ( i = 0; i < selObj.length; i++ ){
if ( selObj[ i ].typename == "GroupItem" )
engine( selObj[ i ] );
}
}
}
else{
selObj = activeDocument.groupItems;
for ( i = 0; i < selObj.length; i++ ){
engine( selObj[ i ] );
}
gCount = Count;
while( Count != 0 ){
redraw( );
selObj = activeDocument.groupItems;
Count = 0;
for ( i = 0; i < selObj.length; i++ ){
engine( selObj[ i ] );
}
}
}
alert( "Refine Groups : " + gCount );
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now