Jump to content

Recommended Posts

Posted

My name is Neil and I am new at autolisp. I am trying to write a lisp file that will explode all blocks but the ones selected by the user. The purpose for this is when I receive a file from architect that I will be using as a base file for my work I want to be able to explode all the blocks. Some times the architect use blocks with attributes for room tags. Which I do not want to explode. Below is the code I have written so far. I may be going about it all wrong so if there is a better way please let me know. Also if you could explain any code you post so that I may be able to learn. Below is my code:

 

(defun C:eselected ()

(Prompt "Select all blocks you do not want to explode. ")

(setq a (ssget "_X" '((0 . "INSERT"))))

(setq b (ssget()))

(setq c (?))

(command "_.explode" c "")

(princ)

)

Posted

Welcome to CADTutor Neil :beer:

 

Try the following code:

(defun c:myexplode ( / all ent inc qaf sel )
   (if
       (and
           (setq sel (ssget      '((0 . "INSERT"))))
           (setq all (ssget "_X" '((0 . "INSERT"))))
       )
       (progn
           (repeat (setq inc (sslength all))
               (if (ssmemb (setq ent (ssname all (setq inc (1- inc)))) sel)
                   (ssdel ent all)
               )
           )
           (setq qaf (getvar 'qaflags))
           (setvar 'qaflags 1)
           (command "_.explode" all "")
           (setvar 'qaflags qaf)
       )
   )
   (princ)
)

Just ask if there is something you do not understand about the code.

Posted

(defun c:dontexplode(/ contss contssall ss ssall)
(setq contss 0)
(setq contssall 0)
(princ "Select the blocks you don't want to explode.")
(setq ss (ssget '((0 . "INSERT"))))
(setq ssall (ssget "_X" '((0 . "INSERT"))))
(repeat (sslength ss)
(repeat (sslength ssall)
	(if (not(eq (ssname ss contss) (ssname ssall contssall)))
	(command "explode" (ssname ssall contssall))
	)
(setq contssall( + 1 contssall))
)
(setq contss(+ 1 contss))
(setq contssall 0)
)
)

 

I got this, but Lee was faster and I'm sure his code is better haha

Posted

And wow, I didn't know about qaflags and ssmemb, good to know (:

Posted

Lee, that worked great. Thanks for your help. :D

Posted
Lee, that worked great. Thanks for your help. :D

 

You're very welcome Neil, happy to help.

 

And wow, I didn't know about qaflags and ssmemb, good to know (:

 

The QAFLAGS System Variable is a weird one; its undocumented and has some obscure effects on commands for different values - I only really tend to use it when I need to pass the explode command a selection set rather than individual entity names.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...