Delete Invisible and empty attribute by selection window

Delete Invisible and empty attribute by selection window

Anonymous
Not applicable
1,296 Views
5 Replies
Message 1 of 6

Delete Invisible and empty attribute by selection window

Anonymous
Not applicable

Hi, I'm newbie in lisp programming. so I need a little help in this lisp routine which can delete invisible attribute by selecting blocks manually on screen . so I want it to be selected automatically by window selection set ex ( 0.0 5.5)

and also to delete any visible empty attribute.

 

 

0 Likes
Accepted solutions (2)
1,297 Views
5 Replies
Replies (5)
Message 2 of 6

dlanorh
Advisor
Advisor
Will it always be a window from 0,0 to 5,5?

I am not one of the robots you're looking for

0 Likes
Message 3 of 6

Anonymous
Not applicable

This is just example , but the exact coordination is (27.2 60.0 0.0) '(634.5 405.0 0.0).

0 Likes
Message 4 of 6

dlanorh
Advisor
Advisor
Accepted solution

Using the given information this should work

 

(defun c:DIA nil (c:DeleteInvisibleAttributes))

(defun c:DeleteInvisibleAttributes ( / ss ) (vl-load-com)
  ;; Example by Lee Mac 2010 - www.lee-mac.com
  (if (ssget "_W" '(27.2 60.0) '(634.5 405.0) '((0 . "INSERT") (66 . 1)))
    (progn
      (vlax-for obj
        (setq ss
          (vla-get-ActiveSelectionSet
            (vla-get-ActiveDocument (vlax-get-acad-object))
          )
        )
        (mapcar
          (function
            (lambda ( attrib )
              (if (eq :vlax-true (vla-get-Invisible attrib))
                (vla-delete attrib)
              )
            )
          )
          (vlax-invoke obj 'GetAttributes)
        )
      )
      (vla-delete ss)
    )
  )
  (princ)
)

This Website is an excellent resource for all things selection set related, as well as Autolisp in general.

I am not one of the robots you're looking for

0 Likes
Message 5 of 6

Anonymous
Not applicable

Thanks a lot , yes it's working as I want except that it not deleting the empty visible attributes. but that's ok

0 Likes
Message 6 of 6

dlanorh
Advisor
Advisor
Accepted solution

@Anonymous  My apologies. I missed the empty bit. Try this version, but be aware that the text string must be truly empty (strlen = 0). If the attribute text string contains spaces it won't be deleted. Would you like this added as well?

 

(defun c:DIA nil (c:DeleteInvisibleAttributes))

(defun c:DeleteInvisibleAttributes ( / ss ) (vl-load-com)
  ;; Example by Lee Mac 2010 - www.lee-mac.com
  (if (ssget "_W" '(27.2 60.0) '(634.5 405.0) '((0 . "INSERT") (66 . 1)))
    (progn
      (vlax-for obj
        (setq ss (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object))))
        (mapcar
          (function
            (lambda ( attrib )
              (if (or (eq :vlax-true (vla-get-Invisible attrib)) (= (strlen (vla-get-textstring attrib)) 0))
                (vla-delete attrib)
              )
            )
          )
          (vlax-invoke obj 'GetAttributes)
        )
      )
      (vla-delete ss)
    )
  )
  (princ)
)

I am not one of the robots you're looking for