abobneil Posted April 26, 2013 Posted April 26, 2013 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) ) Quote
Lee Mac Posted April 26, 2013 Posted April 26, 2013 Welcome to CADTutor Neil 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. Quote
fabriciorby Posted April 26, 2013 Posted April 26, 2013 (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 Quote
fabriciorby Posted April 26, 2013 Posted April 26, 2013 And wow, I didn't know about qaflags and ssmemb, good to know (: Quote
abobneil Posted April 26, 2013 Author Posted April 26, 2013 Lee, that worked great. Thanks for your help. Quote
Lee Mac Posted April 26, 2013 Posted April 26, 2013 Lee, that worked great. Thanks for your help. 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. 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.