Author Topic: Delete Invisible Dynamic Blocks ==> Error Message  (Read 1263 times)

0 Members and 1 Guest are viewing this topic.

Bluebird1973

  • Mosquito
  • Posts: 1
Delete Invisible Dynamic Blocks ==> Error Message
« on: August 02, 2018, 12:38:05 AM »
Hi,

I use this code with AutoCAD 2016 and it work perfect but we get the AutoCAD 2018 and the last few days I receive this message:

** Error: Automation Error. Description was not provided. **


Code: [Select]
(defun c:delinvb (/ acdoc ss i sset nme Blockdefinition)
  (vl-load-com)
  (setq acdoc (vla-get-activedocument
                (vlax-get-acad-object)
              )
  )
  (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
    (repeat
      (setq i (sslength ss))
      (setq sset (ssname ss (setq i (1- i))))
      (setq nme (cdr (assoc 2 (entget sset))))
      (setq Blockdefinition (vla-item (vla-get-blocks acdoc) nme))
      (if
        (and
          (eq :vlax-false (vla-get-isxref Blockdefinition))
          (eq :vlax-false (vla-get-islayout Blockdefinition))
        )
          (vlax-for x Blockdefinition
       (if(=(vla-get-Visible  x) :vlax-false)
        (vla-delete x)
    )
)
      )
    )
    (princ)
  )
  (vla-regen acdoc acAllViewports)
  (princ)
)


Could somebody help me to figure out what happens ?

(I found this code here http://www.theswamp.org/index.php?topic=32681.msg495238#msg495238)

Kind regards
Bluebird1973

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Delete Invisible Dynamic Blocks ==> Error Message
« Reply #1 on: August 02, 2018, 10:31:17 AM »
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ a c d n)
  2.   ;; RJP » 2018-08-02
  3.   ;; Deletes objects in blocks that are not visible
  4.     (cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
  5.   )
  6.     (if (and (= 0 (vlax-get b 'islayout))
  7.              (= 0 (vlax-get b 'isxref))
  8.              (not (wcmatch (setq c (vla-get-name b)) "*|*"))
  9.         )
  10.       (vlax-for o b
  11.         (cond ((and (vlax-write-enabled-p o) (= 0 (vlax-get o 'visible)))
  12.                (setq n (vla-get-objectname o))
  13.                (vla-delete o)
  14.                (print (strcat "Deleting: " n " from " c))
  15.               )
  16.         )
  17.       )
  18.     )
  19.   )
  20.   (foreach l a (vlax-put l 'lock -1))
  21.   (vla-regen d acallviewports)
  22.   (princ)
  23. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC