Delete attributes

Delete attributes

drew_dewit
Advocate Advocate
817 Views
2 Replies
Message 1 of 3

Delete attributes

drew_dewit
Advocate
Advocate

Hi,

 

I am looking for some LISP code to go through the drawing and delete all attribute definitions except for those defined in a list. The attributes are not contained in blocks but in the drawing itself.

0 Likes
Accepted solutions (1)
818 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant

Assuming you have a list of tags.

 

(vl-load-com)

(defun c:RemoveAttdefs ( / lst ss i en )

  (setq lst '("Tag1"
	      "Tag2"
	      "Tag3"
	      ))

  (if (setq ss (ssget "_:L" '((0 . "ATTDEF"))))
    (repeat (setq i (sslength ss))
      (setq en (ssname ss (setq i (1- i))))
      (if (vl-position (cdr (assoc 2 (entget en))) lst)
	(ssdel en ss))))
  (if (and ss (> (sslength ss) 0))
    (command "_.erase" ss ""))
  (princ)
  )
0 Likes
Message 3 of 3

pbejse
Mentor
Mentor
Accepted solution

@drew_dewit wrote:

Hi,

 

I am looking for some LISP code to go through the drawing and delete all attribute definitions except for those defined in a list. The attributes are not contained in blocks but in the drawing itself.


 

Curios, why would you have ATTDEF's on your drawing? Obviously from exploded attributed blocks,  why not take it one step further and convert the excluded ATTDEF into TEXT entity.

 

Building off @BeekeeCZ 's suggestion

 

 

(defun c:RemoveAttdefs (/ dxf_ lst ss i en ent data)
  (setq	dxf_ '(2 7 8 10 40 41)
	lst  '("TAG1"
	       "TAG2"
	       "TAG3"
	      )
  )
  (if (setq ss (ssget "_:L" '((0 . "ATTDEF"))))
    (repeat (setq i (sslength ss))
      (setq en	 (ssname ss (setq i (1- i)))
	    ent	 (entget en)
	    data (mapcar '(lambda (dx)
			    (Cdr (assoc dx ent))
			  )
			 dxf_
		 )
      )
      (if (vl-position (car data) lst)
	(entmakex (append '((0 . "TEXT"))
			  (mapcar 'cons (Cons 1 (cdr dxf_)) data)
		  )
	)
      )
      (entdel en)
    )
  )
  (princ)
)

 

 

HTH

 

0 Likes