Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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]

Posted
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".

Posted
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.
Posted
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.

Posted

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

Posted

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)))

Posted

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.

Posted

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'

Posted

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.

Posted

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.

Posted

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)
   )
)

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...