- (DEFUN C:RS (/ SS ENT1 IP)(setq ss (ssget "_X" '((0 . "INSERT") ( 2 . "IFC stamp"))))(SETQ ENT1 (ENTGET (ENTLAST)))(SETQ IP (CDR (ASSOC 10 ENT1)))(COMMAND "ERASE" "L" "")(COMMAND "INSERT" "Y:/Piping Department/Blocks/Stamps/BID_ONLY.DWG" IP "" "" "" "08/6/13"))
This routine, though once was working for us to delete a specified block and insert another in it's place, stopped working for us.
The (SETQ ENT1 (ENTGET (ENTLAST))) line was pulling the wrong block as the "entlast" and I am not sure why, because it was adding the correct block to the selection set and holding it there.
But was giving information about a wrong block even though the correct block was added to the selection set in the previous command.
Why?
...it was causing the insertionpoint of our new block to be any of random places on our drawing, depending on which block was selected in the (entlast) line, as mentioned just above.
I was able to do some scouring and was able to construct the following routine in it's place, devoid of any (entlast) calls. Bravo for that, self, problem solving, but if any guru would care to explain the reason behind my troubles I would be grateful.
The following works correctly and does as we expect,
- (DEFUN C:RS (/ Blks ENT1 IP oldatt);;; Erases all blocks named "IFC stamp" and replaces with "BID_ONLY";;; (ax:EraseBlock doc "IFC stamp");;; routine works as expected(defun ax:EraseBlock (doc bn / layout i)(vl-load-com)(setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for layout (vla-get-layouts doc) (vlax-for i (vla-get-block layout) (if (and (= (vla-get-objectname i) "AcDbBlockReference") (= (strcase (vla-get-name i)) (strcase bn)) ) (vla-Delete i) ) ) ))(setq IP (cdr (assoc 10 (entget (ssname (ssget "_X" '((2 . "IFC stamp"))) 0)))))(ax:EraseBlock doc "IFC stamp")(setq oldatt (getvar "ATTREQ"))(setq oldattd (getvar "ATTDIA"))(setvar "ATTREQ" 1)(setvar "ATTDIA" 0)(COMMAND "INSERT" "Y:/Piping Department/Blocks/Stamps/BID_ONLY.DWG" IP "" "" "" "8/30/13")(setvar "ATTREQ" oldatt)(setvar "ATTDIA" oldattd))
Differences are fairly striking, the new one uses a combination of lisp and vlisp, though I wish I could have had the correct way to do this in lisp explained to me as I would truly prefer to understand the code that we use on our drawings, and although I'm exactly sure that the vlisp portion of this code is meant to delete out the old block, I would still like to know which each line does specifically, but being vlisp I would need to have it explained in depth. That said, the rest is fairly simple, setting "ip" to be the assoc 10 of the selected block to be replaced. We wrapped the ssget in the setq for the insertion point to ensure that it would get the IP of the correct block this time, the other lines call the vlisp subfunction to erase the old block after the insertion point is set to a var, then some block attribute system vars are modified so that when the new block is inserted the attributes will be filled correctly.
Thanks to anyone in advance who will care to go over the entlast, or any of the (ent) questions I've laid out above this post.
Cheers