Author Topic: Alert when attempt to del a block  (Read 910 times)

0 Members and 1 Guest are viewing this topic.

mohan

  • Newt
  • Posts: 98
Alert when attempt to del a block
« on: November 24, 2021, 01:27:31 PM »
While deleting objects if a block is selected appear a warning alert message !
Please fix the bug.
Code: [Select]
(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))
"Save Energy"

ribarm

  • Gator
  • Posts: 3272
  • Marko Ribar, architect
Re: Alert when attempt to del a block
« Reply #1 on: November 24, 2021, 01:36:26 PM »
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: [Select]
(if (tblsearch "BLOCK" bnme)
  ... then
  ... else
)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

mhupp

  • Bull Frog
  • Posts: 250
Re: Alert when attempt to del a block
« Reply #2 on: November 29, 2021, 03:38:43 AM »
Uses the dxf codes instead.
Code: [Select]
(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")
  )
)