CADan Posted February 3, 2009 Posted February 3, 2009 I am just starting to write my own LISP routines. I have a bunch of drawings that have had their borders was inserted and not xreferenced. I am writing a program to delete the block and bring in the xreference border. So far I have this started using ssget to get the block name and then I want to use entdel to erase the block. How ever when i test it I get a bad argument type error. What I am I doing wrong. (defun c:dlbd () (setq BD (ssget "X" '((2 . "AIA_D1-L000")))) (entdel BD) ) Any help will be greatly appreciated. Quote
uddfl Posted February 3, 2009 Posted February 3, 2009 The selection set in the entdel function is the bad argument type. You cannot entdel an entire selection set, it HAS to be an entity name. So if you must use entdel you have to cycle (loop) through each of the selection set's entities, and entdel them individually. Look at this example: (defun loop () (setq ss1 (ssget)) (setq ent-index 0) (setq update-index 0) (repeat (sslength ss1) (setq entname (ssname ss1 ent-index)) (princ "\n") (princ entname) (setq update-index (1+ update-index)) (setq ent-index (1+ ent-index)) ); repeat (princ (strcat "\nLooped through " (itoa update-index) " entity(ies).")); sample closing msg (princ) ) Edit: Welcome to the boards. Quote
rkmcswain Posted February 3, 2009 Posted February 3, 2009 Not to start a debate on which way is better, but this will work also: [color=blue][font="Courier New"] (defun c:dlbd ( / bd) (if (setq BD (ssget "X" '((2 . "AIA_D1-L000")))) (command "._erase" bd "") ) (princ) ) [/font][/color] Quote
uddfl Posted February 3, 2009 Posted February 3, 2009 Not to start a debate on which way is better, but this will work also: [font=Courier New][color=blue](defun c:dlbd ( / bd)[/color][/font] [font=Courier New][color=blue] (if (setq BD (ssget "X" '((2 . "AIA_D1-L000"))))[/color][/font] [font=Courier New][color=blue] (command "._erase" bd "") [/color][/font] [font=Courier New][color=blue] )[/color][/font] [font=Courier New][color=blue] (princ)[/color][/font] [font=Courier New][color=blue])[/color][/font] Of course. But it looks like OP wants to entdel. That's why I said "if you must use entdel". Quote
rkmcswain Posted February 3, 2009 Posted February 3, 2009 Of course. But it looks like OP wants to entdel. True, but the OP also said "I am just starting to write my own LISP routines"... so I was just offering an alternative since a beginner may not know about the (command) function. Quote
uddfl Posted February 3, 2009 Posted February 3, 2009 True, but the OP also said "I am just starting to write my own LISP routines"... so I was just offering an alternative since a beginner may not know about the (command) function. Point taken. Quote
ASMI Posted February 3, 2009 Posted February 3, 2009 Transformation Selection Set -> List and mapcar 'entdel at once. (defun c:dlbd ( / bd) (if(setq BD (ssget "X" '((2 . "AIA_D1-L000")))) (mapcar 'entdel (vl-remove-if 'listp(mapcar 'cadr(ssnamex BD)))) ); end if (princ) ); end c:dlbd Quote
CAB Posted February 3, 2009 Posted February 3, 2009 The problem with entdel is that it only works for Model space and the most recently active Layout. Therefore if you use (ssget "_X") you should not use entdel. (vl-load-com) (mapcar '(lambda (x) (vla-delete (vlax-ename->vla-object x))) (mapcar 'cadr (ssnamex ss))) Quote
Lee Mac Posted February 3, 2009 Posted February 3, 2009 Who'd have thought there'd be so many ways to delete something... Quote
CADan Posted February 3, 2009 Author Posted February 3, 2009 Thank you to everyone for your responses. My first try at this looked similar to rkmcswain's code. I was having proplems with it that I think where syntax proplems. So I Googled until I found the entdel. Now that part works great. The lastest version looks like this. (defun c:dlbd ( / bd) (if (setq BD (ssget "X" '((2 . "AIA_D1-L000")))) (command "._erase" bd "") (command "._purge" "b" "n") (command "._xref" "a" "X:\\PATH\\AIA_D1-L000.dwg" "0,0,0" "" "" "") ) (princ) ) I know get a syntax error when a load it. I think is related to the purge command when I take it out the it loads fine. But I since the old border block and new border xref share the same name I need to purge the block out. Quote
CarlB Posted February 3, 2009 Posted February 3, 2009 syntax error is that there are 3 options after an 'if', I think you meant just one, so enclose the 3 'commands' with a 'progn' Quote
Lee Mac Posted February 3, 2009 Posted February 3, 2009 Carl is right - when you take out the purge command the IF statement has the correct number of terms in it, but the last term will not be evaluated as it is the "else do this" term - if you see what I mean. for more information on Progn, see here: http://www.cadtutor.net/forum/showpost.php?p=173196&postcount=10 Quote
CADan Posted February 3, 2009 Author Posted February 3, 2009 I see, you must group all your "if" actions with (progn). Here is the final working version. (defun c:bfix ( / bd) (if (setq BD (ssget "X" '((2 . "AIA_D1-L000")))) (progn (command "._erase" bd "") (command "._purge" "b" "" "n") (command "._xref" "a" "X:\\path\\AIA_D1-L000.dwg" "0,0,0" "" "" "") ) ) (princ) ) Thank you to every one for you help. Trying to learn this from a book and the internet is near impossible. I will try to use my new found powers for good. Quote
Lee Mac Posted February 3, 2009 Posted February 3, 2009 Nice one Dan, Bear in mind that progn wraps the code as if it were one statement so that it can be evaluated, so if you only have say three statements, a test expression, a resultant expression and an "else" expression, then no progn is needed. Quote
Lee Mac Posted February 3, 2009 Posted February 3, 2009 Ahh, and one more thing I forgot to mention: You can wrap the "else" expressions as well: (if (this is true) (progn (do this) (and this) (and this) ) (progn (else do this) (and this) (and this) ) ) 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.