The routine is used to erase objects from block definition ( lines, arc, etc.... ) by selecting them. It works well, for me so far. I was wondering how one would implement an undo feature? I couldn't just add an ' entdel ' to bring back the entity, since I couldn't delete it with same function. I don't want to have to save the block definition ( all entities ) and then recreate it all with code, so I was trying to find a simpler way.
(defun c:EraseObjectFromBlock (/ ActDoc Sel EntList DiaRtn tempName)
; Erase object selected from block, in block collection, so all blocks will update.
; Will let you select from dialog box if item is more that one nesting deeep.
; Sub's - 'SingleSelect
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-EndUndoMark ActDoc)
(vla-StartUndoMark ActDoc)
(setvar 'Errno 0)
(while (not (equal (getvar 'ErrNo) 52))
(if
(and
(setq Sel (nentsel "\n Select nested item to erase: "))
(> (length Sel) 2)
(setq EntList (last Sel))
(not
(wcmatch
(setq tempName (cdr (assoc 2 (entget (car EntList)))))
"*|*"
)
)
(not
(equal
(logand
(cdr (assoc 70 (entget (tblobjname "block" tempName))))
4
)
4
)
)
(setq Entlist (cons (car Sel) EntList))
(setq Ent
(if (< (length EntList) 3)
(car EntList)
(if
(setq DiaRtn
(SingleSelect
(mapcar
'(lambda (x)
(cdr (assoc 0 (entget x)))
)
(reverse (cdr (reverse EntList)))
)
"Select item to be erased ( lowest to highest, nesting )."
nil
)
)
(nth (setq DiaRtn (car DiaRtn)) EntList)
)
)
)
;(entdel Ent)
(or
(vla-Delete (vlax-ename->vla-object Ent))
(vlax-erased-p Ent)
)
)
(progn
(or
DiaRtn
(setq DiaRtn 0)
)
(foreach i (cdr (member Ent EntList))
(vla-Update (vlax-ename->vla-object i))
)
(prompt "\n Item deleted.")
)
(prompt "\n No item deleted.")
)
)
(vla-EndUndoMark ActDoc)
(princ)
)
Sub-function
(defun SingleSelect (Listof Message Toggle / DiaLoad tmpStr tmpTog tmpList)
(setq DiaLoad (load_dialog "MyDialogs.dcl"))
(if (new_dialog "SingleSelect" DiaLOad)
(progn
(start_list "listbox" 3)
(mapcar 'add_list Listof)
(end_list)
(if Message
(set_tile "text1" Message)
)
(if (not Toggle)
(mode_tile "toggle1" 1)
)
(action_tile "listbox"
"(if (= $reason 4)
(progn
(setq tmpStr (get_tile \"listbox\"))
(if Toggle
(setq tmpTog (get_tile \"toggle1\"))
)
(done_dialog 1)
)
)"
)
(action_tile "accept"
"(progn
(setq tmpStr (get_tile \"listbox\"))
(if Toggle
(setq tmpTog (get_tile \"toggle1\"))
)
(done_dialog 1)
)"
)
(action_tile "cancel" "(done_dialog 0)")
(if (= (start_dialog) 1)
(progn
(setq tmpList (read (strcat "(" tmpStr ")")))
(if (= tmpTog "1")
(cons T tmpList)
tmpList
)
)
)
)
)
)