Right now I do it like this: (foreach a '
("ACDB3DSOLID" "ACDBBODY" "ACDBREGION" "ACDBPOLYLINE" "ACDBPOLYGONMESH" "ACDB3DPOLYLINE") ))
)
)
)
)
)
)
)
;;; this is supposed to work in the model space
(if (= (cdr(assoc 2 LstBlk
)) "*Model_Space") ;; this should only let you into the model space block ;;; buit I never get there
(foreach a '
("ACDB3DSOLID" "ACDBBODY" "ACDBREGION" "ACDBPOLYLINE" "ACDBPOLYGONMESH" "ACDB3DPOLYLINE") ))
)
"*Model_Space"
)
)
)
)
)
)
Sorry, but I cannot stress strongly enough how terribly inefficient your code is.
Here is what your code is currently doing (pseudo-code):
For every block in the block table
If the block is not an anonymous block
For every objectname in the list
Convert the collection of block components into a list
Iterate over the list of block components
If the objectname of the component matches the item currently processed
Explode the object
Erase the original object
end if
end foreach
end if
end foreach
For every block in the block table (again)
If the block is the Modelspace block
For every objectname in the list
Convert the collection of all objects in Modelspace into a list
Iterate over the list of every object in Modelspace
If the objectname of the component matches the item currently processed
Explode the object
Erase the original object
end if
end foreach
end if
end foreach
Think about what the code is doing for each block processed:
Process first block in block table
Block is not anonymous
Process "ACDB3DSOLID"
Convert the collection of every object in the block into a list
Iterate over this list
If objectname = "ACDB3DSOLID"
Explode object
Erase object
end if
Process "ACDBBODY"
Convert the collection of every object in the block into a list (again)
Iterate over this list (the same list)
If objectname = "ACDBBODY"
Explode object
Erase object
end if
Process "ACDBREGION"
Convert the collection of every object in the block into a list (and again)
Iterate over this list (the same list again)
If objectname = "ACDBREGION"
Explode object
Erase object
end if
...
...
Process second block in block table...
...
Notice that, for every block, the collection of objects in each block definition (which could potentially be hundreds, if not thousands of objects) is being converted to a list and iterated over... 6 times!
And that's before you do the same thing and iterate over EVERY object in Modelspace another 6 times!
Furthermore, you are needlessly retrieving the AutoCAD Application object & Block Collection object (an inefficient & slow process in itself) 6 times for EVERY block processed, and another 6 times for the Modelspace block!
Note also that your code will not account for nested blocks (or other explodable nested objects) - if a block reference or block definition were to contain a nested block or explodable object (such as a polyline), or even perhaps multiple blocks nested within each other several levels deep, when the parent block is exploded, the nested blocks & objects will now be present within the containing object (Modelspace / Block Definition) and will remain in the drawing since the code will have already iterated over the block definition.
Consider the following alternative:
)
)
(defun explode
( obj
/ lst
) )
)
)
)
The above will iterate over all objects in all block definitions (including all drawing layouts), and will attempt to explode every object. To account for the possibility of nested blocks & other nested explodable objects, the function will recursively iterate over the set of exploded objects, repeating the process to ensure every explodable object is exploded.