Code Red > AutoLISP (Vanilla / Visual)

Alert when attempt to del a block

(1/1)

mohan:
While deleting objects if a block is selected appear a warning alert message !
Please fix the bug.

--- Code: ---(defun c:cleanob ( / bNme )
(setq bNme (ssget))
(if (= bNme (tblsearch "BLOCK" bNme))
(alert "_.you are attempted to delete a block")); if
(Command "_.erase" bNme "") (princ))
--- End code ---

ribarm:
bnme is variable that stores selection set - not block name...
Even more, if you supply correct filter '((0 . "INSERT")) - you have to extract bnme from it - iterate or something else (INSERT type can also be xref, not only block, so pay attention to that too)...
(tblsearch) approach is good, but like I said, supply correct argument to it - bnme that is string with desired reference block name...
(= bnme (tblsearch "BLOCK" bnme)) is not needed that way - (tblsearch) returns not block name, but table list with block definition dxf basic data...
Only this is enough :

--- Code: ---(if (tblsearch "BLOCK" bnme)
  ... then
  ... else
)

--- End code ---

mhupp:
Uses the dxf codes instead.

--- Code: ---(defun c:cleanob (/ SS)
  (if (setq SS (ssget))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (if (= (cdr (assoc 0 (entget e))) "INSERT")
        (alert "\nYou are attempted to Delete a Block")
        (entdel e) ;deletes anything else not a block
      )
    )
    (prompt "\nNothing Selected")
  )
)

--- End code ---

Navigation

[0] Message Index

Go to full version