lisp to delete zero attributes

DOODLEANU
Enthusiast
Enthusiast

lisp to delete zero attributes

DOODLEANU
Enthusiast
Enthusiast

hi ,

Can anyone please help me to give a lisp;

check all attributes values of few block selection, if there is any att value zero, make all of them empty.

0 Likes
Reply
Accepted solutions (3)
492 Views
9 Replies
Replies (9)

komondormrex
Advisor
Advisor
Accepted solution

hey,

do you mean by 'value zero' "0" value or "" value?

=========

if "0" value

 

(defun c:empty_atts_if_zero (/ insert_sset all_atts_list )
  (if (setq insert_sset (ssget '((0 . "insert") (66 . 1))))
    	(mapcar '(lambda (attribute) (if (= "0" (vla-get-textstring attribute)) (vla-put-textstring attribute "")))
		  (setq all_atts_list (apply 'append (mapcar '(lambda (insert) (vlax-invoke insert 'getattributes))
						   	      (mapcar 'vlax-ename->vla-object
								      (vl-remove-if 'listp
										    (mapcar 'cadr (ssnamex insert_sset))
								      )
							      )
						     )
				      )
		  )
	)
  )
  (princ)
)

 

updated

Moshe-A
Mentor
Mentor
Accepted solution

@DOODLEANU  hi,

 

check this EMPTYATT command

 

enjoy

moshe

 

(defun c:emptyatt (/ ss ent AcDbBlkRef AcDbAttrib)

 (if (setq ss (ssget '((0 . "insert") (66 . 1))))
  (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (setq AcDbBlkRef (vlax-ename->vla-object ent))
   (foreach AcDbAttrib (vlax-invoke AcDbBlkRef 'GetAttributes)

    (if (eq (vla-get-textString AcDbAttrib) "0")
     (vla-put-textString AcDbAttrib "")
    )

    (vlax-release-object AcDbAttrib)
   )
   (vlax-release-object AcDbBlkRef)
  ); foreach
 ); if

 (princ)
)

 

 

 

 

DOODLEANU
Enthusiast
Enthusiast

I wanna make 0 to """

0 Likes

DOODLEANU
Enthusiast
Enthusiast

its works perfect for me thank you

0 Likes

DOODLEANU
Enthusiast
Enthusiast
Thank you
0 Likes

DOODLEANU
Enthusiast
Enthusiast

@Moshe-A @komondormrex 

 

how about  all blocks with a specific name lets say

block name example Block1

 

instead of selecting them

0 Likes

komondormrex
Advisor
Advisor

and 'Block1' is static or dynamic?

0 Likes

DOODLEANU
Enthusiast
Enthusiast

Dynamic block.

0 Likes

komondormrex
Advisor
Advisor
Accepted solution

check the following

(defun c:empty_atts_if_zero (/ insert_sset all_atts_list )
  (if (setq insert_sset (ssget "_x" '((0 . "insert") (66 . 1))))
    	(mapcar '(lambda (attribute) (if (= "0" (vla-get-textstring attribute)) (vla-put-textstring attribute "")))
		  (setq all_atts_list (apply 'append (mapcar '(lambda (insert) (vlax-invoke insert 'getattributes))
								  (vl-remove-if-not '(lambda (insert) (member (strcat (vla-get-effectivename insert)) 
								  											  (mapcar 'strcat '("block1")))
													 )
								  					 (mapcar 'vlax-ename->vla-object
								  					    	(vl-remove-if 'listp
								  								    (mapcar 'cadr (ssnamex insert_sset))
								  					    	)
							      					 )
								  )
						     )
				      )
		  )
	)
  )
  (princ)
)