grandhougday Posted June 1, 2013 Posted June 1, 2013 I need a lisp to explode a Cylindrical Solid shape. in fact explode 2 times. first it become to surface and after another explosion it become to two circles. then i want to do something with that circles. How i can do this? in VBA by Explode Function by default return objects: explodedObjects = BlockObj.Explode but how is it in lisp? Quote
Lee Mac Posted June 1, 2013 Posted June 1, 2013 (vlax-invoke [color=green][/color] 'explode) Will return a list of exploded objects (where is the object to be exploded); note that this method will retain the original object. Quote
pBe Posted June 1, 2013 Posted June 1, 2013 or (defun c:demo (/ qf) (setq qf (getvar 'Qaflags ) ) (setvar 'qaflags 1) (if (setq ss (ssget "_:L" '((0 . "3DSOLID")))) (progn (command "_explode" ss "") (command "_explode" "_Previous" "") (sssetfirst nil (ssget "P" '((0 . "[color=blue][b]CIRCLE"[/b][/color][color=black]))))[/color] (setvar 'qaflags qf) ) ) ) Quote
vanowm Posted March 12, 2015 Posted March 12, 2015 Hello. I'm trying pBe's code on ruled surface: (defun c:demo (/ qf) (setq qf (getvar 'Qaflags ) ) (setvar 'qaflags 1) (if (setq ss (ssget '((100 . "AcDbPolygonMesh")))) (progn (command "_explode" ss "") (command "_explode" "_Previous" "") (sssetfirst nil (ssget "P" '((0 . "3DFACE")))) (setvar 'qaflags qf) ) ) ) but it returns Command: demoSelect objects: 1 found Select objects: _explode Select objects: 1 found Select objects: Command: _explode Select objects: _Previous 12 found 12 were not able to be exploded. Select objects: None found. Command: 1 Any ideas how I can retrieve 3dface's out of a ruled surface without possibly affecting the original surface? Thank you. Quote
pBe Posted March 12, 2015 Posted March 12, 2015 (defun c:demo (/ qf) (setq qf (getvar 'Qaflags ) ) (setvar 'qaflags 1) (if (setq ss (ssget '((100 . [b]"Mesh"[/b])))) (progn [b] (command "_copy" ss "" "0,0" "@" "")[/b] (command "_explode" ss "") (sssetfirst nil (ssget "P" '((0 . "3DFACE")))) (setvar 'qaflags qf) ) ) ) Quote
vanowm Posted March 13, 2015 Posted March 13, 2015 Thank you very much! The problem was (command "_explode" "_Previous" "") Removed that line and it worked. Copy object on top of itself also worked, thank you. P.S. rulesurf creates mesh with (100 . "AcDbPolygonMesh") Quote
3dwannab Posted December 4, 2024 Posted December 4, 2024 (edited) Here's the program I wrote based on @pBe's code. See header for the additions. (vl-load-com) ;; ;; 3dwannab_Explode.lsp ;; ;; WHAT THIS DOES: ;; - Redefines the explode command 'X'; ;; - Avoids exploding hatches; ;; - keeps the exploded objects selection set afterwards; ;; - If no valid objects need to be exploded the original selection is retained; ;; - Outputs to the commandline, info on the count for exploded and not so exploded objects; ;; - Undo handling. ;; ;; ABOUT ;; Written on 2024.12.03 by 3dwannab. ;; Based on pBe's code found here: https://www.cadtutor.net/forum/topic/46380-retrieve-objects-after-explode/#findComment-379156 ;; (defun c:X (/ *error* acDoc cntExploded cntExplodedNot ss ssExploded ssSel var_cmdecho var_qaflags) (defun *error* (errmsg) (and acDoc (vla-EndUndoMark acDoc)) (and errmsg (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*")) (princ (strcat "\n<< Error: " errmsg " >>\n")) ) (setvar 'cmdecho var_cmdecho) (setvar 'qaflags var_qaflags) ) ;; Start the undo mark here (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object))) (or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc)) ;; Get any system variables here (setq var_cmdecho (getvar "cmdecho")) (setq var_qaflags (getvar "Qaflags")) (setvar 'cmdecho 0) (setvar 'qaflags 1) ;; Helps to get the selection set after the explode command. ;; Initialize the merged selection set (setq ssSel (ssadd)) ; Start with an empty selection set (setq ss nil) ; Start with an empty selection set (setq ssExploded nil) ; Start with an empty selection set (if (setq ss (ssget "_:L" '((0 . "~HATCH")))) (progn (command "_explode" ss "") ;; Explode the selected objects (setq ssExploded (ssget "P")) ;; Get the exploded items. QAFLAGS variable must be set to 1. (setq ssSel (_mergeSS ss ssExploded)) ;; Merge the two selection sets. ;; If there were no exploded items, make sure ssExploded is an empty set (if (not ssExploded) (progn (setq ssExploded (ssadd)) ;; Regen if the selection set ssSel is valid ;; Use this to select all objects again if there was no valid objects to explode (if ssSel (progn (sssetfirst nil ssSel) (command "_.regen") ) ) ) ;; Select the exploded objects only (sssetfirst nil ssExploded) ) ;; Count objects not exploded and exploded (setq cntExplodedNot (abs (- (sslength ssSel) (sslength ssExploded)))) (setq cntExploded (abs (sslength ssExploded))) ;; Print the results (princ (strcat "\n" (itoa cntExploded) (if (or (= cntExploded 0) (> cntExploded 1)) " objects" " object") " exploded")) (princ (strcat "\n" (itoa cntExplodedNot) (if (or (= cntExplodedNot 0) (> cntExplodedNot 1)) " objects" " object") " not exploded")) ) ) ;; if ss (vla-EndUndoMark acDoc) (*error* nil) (princ) ) ;; Merges two selection sets. Checks each entity first before adding it to the newly created selection set. ;; Returns new selection set. (defun _mergeSS (ss1 ss2 / en i ssNew) (setq ssNew (ssadd)) ; Start with an empty selection set ;; Check and merge the first selection set (ss1) (if ss1 (progn (setq i 0) (while (< i (sslength ss1)) ; Loop through ss1 (setq en (ssname ss1 i)) ; Get the object from ss1 (if (entget en) ; Check if the object is valid (setq ssNew (ssadd en ssNew)) ; Add valid object to merged set ) (setq i (1+ i)) ; Increment the counter ) ) ) ;; Check and merge the second selection set (ss2) (if ss2 (progn (setq i 0) (while (< i (sslength ss2)) ; Loop through ss2 (setq en (ssname ss2 i)) ; Get the object from ss2 (if (entget en) ; Check if the object is valid (setq ssNew (ssadd en ssNew)) ; Add valid object to merged set ) (setq i (1+ i)) ; Increment the counter ) ) ) ssNew ; Return the merged selection set ) (princ "\n3dwannab_Explode.lsp is loaded. Type 'explode' to run...") ; (c:X) ;; Unblock for testing Edited December 4, 2024 by 3dwannab Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.