;| SEP.lsp - finally, smart separation for one or more 3Dsolids SEP.lsp separates one or more lumpy, i.e, composite, 3DSOLIDs and puts each of the resulting 'child' solids on the layer of its 'parent' solid, rather than one on the parent layer and the rest on the current layer, as is the default action. Command: sep Select 3Dsolids to be separated: Select objects: Specify opposite corner: 12 found Select objects: Solids on locked layers: 5 Solids with no lumps...: 3 Solids separated.......: 4 Command: by Bill Gilliss bill at realerthanreal dot com Comments and suggestions always welcome. No warranty, either expressed or implied, is made as to the fitness of this information for any particular purpose. All materials are to be considered 'as-is', and use thereof should be considered as at your own risk. version 1.0 Feb 07 2010 - initial public release ======================================================================== |; (defun c:sep (/ myerror olderror *clayer *cmdecho ss n en lay locked ssLumpy unlumpy) (vl-load-com) (setq acadObject (vlax-get-acad-object)) (setq acadDocument (vlax-get-property acadObject 'ActiveDocument)) (setq olderror *error*) (vla-StartUndoMark acadDocument) (defun myerror (errmsg) (vla-EndUndoMark acadDocument) (setvar 'clayer *clayer) (setq *error* olderror) (setvar 'cmdecho *cmdecho) (princ) ) (setq *error* myerror) (setq *clayer (getvar 'clayer)) (setq *cmdecho (getvar 'cmdecho)) (setvar 'cmdecho 0) (prompt "\nSelect 3Dsolids to be separated: ") (setq ss (ssget '((0 . "3DSOLID")))) (setq locked 0) (setq ssLumpy (ssadd)) (if ss (progn (setq n 0) (while (< n (sslength ss)) ;;put lumpy ones in ssLumpy (setq en (ssname ss n)) (setq lay (cdr (assoc 8 (entget en)))) (if (= 4 (cdr (assoc 70 (tblsearch "LAYER" lay)))) (setq locked (1+ locked)) (progn (setvar 'clayer (cdr (assoc 8 (entget en)))) (setq file (vl-filename-mktemp "scoop.sat")) (vl-cmdf "export" file en "") (setq lumps 0) (setq f (open file "r")) (while (setq lin (read-line f))(if (= "lump" (substr lin 1 4)) (setq lumps (1+ lumps)))) (close f) (vl-file-delete file) (if (> lumps 1)(ssadd en ssLumpy)) ) ) (setq n (1+ n)) );while (if (> (sslength ssLumpy) 0) (progn (setq n 0) (while (< n (sslength ssLumpy)) (setq en (ssname ssLumpy n)) (setvar 'clayer (cdr (assoc 8 (entget en)))) (command "._solidedit" "_body" "_separate" en "_x" "_x") (setq n (1+ n)) ) (setq unLumpy (- (sslength ss) locked (sslength sslumpy))) (if (> locked 0) (princ (strcat "\nSolids on locked layers: " (itoa locked)))) (if (> unLumpy 0) (princ (strcat "\nSolids with no lumps...: " (itoa unLumpy)))) (princ (strcat "\nSolids separated.......: " (itoa (sslength sslumpy)))) ) (progn (if (> locked 0) (princ (strcat "\nSolids on locked layers: " (itoa locked)))) (princ "\nNone of the solids on unlocked layers are lumpy.") ) ) ) (progn (princ "\nNo 3DSOLIDs were selected.") (vlr-beep-reaction) ) ) (myerror) ;; for cleanup )