Change Attribute text height by Tag name

Change Attribute text height by Tag name

zafera5VK85
Contributor Contributor
1,297 Views
17 Replies
Message 1 of 18

Change Attribute text height by Tag name

zafera5VK85
Contributor
Contributor

Dear Forum,

 

I have same attribute tagname in multiple blocks. I've found "GlobalChangeAttHeight.lsp" in forums but it changes all Tags. Is it possible to change Attribute text height by Tagname?

 

Best Regards

Victor. 

0 Likes
Accepted solutions (1)
1,298 Views
17 Replies
Replies (17)
Message 2 of 18

EnM4st3r
Advocate
Advocate

try this

(defun c:allAttHeight (/ h tag ss)
  (initget 7)
  (setq h (getreal "\nEnter textheight: "))
  (setq tag "part") ; <-------------------- change Tag -------------- ;
  (setq ss (ssget "_X" '((0 . "INSERT"))))
  (if (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
    (progn
      (vlax-for obj ss
        (foreach attref (vlax-invoke obj 'getattributes)
          (if (= (strcase tag)(vla-get-tagstring attref))
              (vla-put-height attref h)
          )
        )
      )
      (vla-delete ss)
    )
  )
)
0 Likes
Message 3 of 18

zafera5VK85
Contributor
Contributor

Thank you for respond. Its function same as "GlobalChangeAttHeight.lsp". My intention to modify each tag as diffrent text height. ( Exp: DOORTYPE=133, MagneticLock=99, Harware=55)

 

Best regards

Victor

0 Likes
Message 4 of 18

EnM4st3r
Advocate
Advocate

i mean it changes the tag thats specified in the code only

 

0 Likes
Message 5 of 18

EnM4st3r
Advocate
Advocate

you could also go like this and change the specific tags / height values or add new ones in the list.

(defun c:allAttHeight (/ setAttHeight lst ss)
  (defun setAttHeight (blk lst / item)
    (foreach item lst
     (foreach attref (vlax-invoke obj 'getattributes)
        (if (= (strcase (car item))(vla-get-tagstring attref))
            (vla-put-height attref (cdr item))
        )
      )
    )
  )
  
  (setq lst '(
              ("DOORTYPE" . 133) ;; (<tag> . <height>)
              ("MagneticLock" . 99)
              ("Harware" . 55)
            )
  )
  
  (setq ss (ssget "_X" '((0 . "INSERT"))))
  (if (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
    (progn
      (vlax-for obj ss
       (setAttHeight obj lst)
      )
      (vla-delete ss)
    )
  )
)
0 Likes
Message 6 of 18

zafera5VK85
Contributor
Contributor

thank you once again. I don't know where am I doing wrong. The code is changind textheght of "DOORTYPE" only. However after "Command: ATTSYNC" everything go back to previous textsize. 

 

Help Pls.

Victor. 

0 Likes
Message 7 of 18

EnM4st3r
Advocate
Advocate

if your tags are set correctly those should change aswell.
The height resetting is because that code changes only the attribute references height not the definiton.. i didnt think of that

0 Likes
Message 8 of 18

komondormrex
Mentor
Mentor

hey there,

for starting

 

(defun c:change_att_height (/ insert_sset insert_list tag_list selected_tag att_height attribute_list)
  (prompt "\nSelect target blocks...")
  (if (setq insert_sset (ssget "_:L" '((0 . "insert") (66 . 1))))
	   (progn
		 (foreach insert (setq insert_list (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex insert_sset)))))
		   (foreach attribute (vlax-invoke insert 'getattributes)
				(if (not (member (vla-get-tagstring attribute) tag_list)) (setq tag_list (append tag_list (list (vla-get-tagstring attribute))))) 
		   )
		 )
		 (setq tag_list (acad_strlsort tag_list))
		 (while (and
			     (if tag_list (not (initget (apply 'strcat (cdr (apply 'append (mapcar '(lambda (tag) (list " " tag)) tag_list)))))) nil)   
		      	     (setq selected_tag (getkword (strcat "\nTag filter, select to remove [" 
							 	  (apply 'strcat (cdr (apply 'append (mapcar '(lambda (tag) (list "/" tag)) tag_list)))) 
							 	  "]"
						          )
				                )
		  	     )
		    	)
				(setq tag_list (vl-remove selected_tag tag_list))
		 )
	       	 (if tag_list
		   (progn
	     	 	(setq att_height (getreal "\nEnter desirable attribute height: "))
	     	 	(foreach insert insert_list
			  (setq attribute_list (vlax-invoke insert 'getattributes))
			  (foreach tag tag_list
			    (if (vl-some '(lambda (attribute) (= tag (vla-get-tagstring (setq attribute_found attribute)))) attribute_list)
			      (vla-put-height attribute_found att_height)
			    )
		    	  )
			)
		   )
		 )
	   )
  )
)

 

 

Message 9 of 18

EnM4st3r
Advocate
Advocate
Accepted solution

try this

 

(defun c:allAttHeight (/ setAttHeight lst doc ss bname blks blkcol tag item)
  (defun setAttHeight (blk lst / item)
    (foreach item lst
     (foreach attref (vlax-invoke obj 'getattributes)
        (if (= (strcase (car item))(strcase (vla-get-tagstring attref)))
            (vla-put-height attref (cadr item))
        )
      )
    )
  )

  (setq lst '(
              ("DOORTYPE" 13) ;; (<tag> <height>)
              ("MagneticLock" 50)
              ("Harware" 100)
            )
  )
  (setq lst (mapcar '(lambda (x) (list (strcase (car x)) (cadr x))) lst))
  
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq ss (ssget "_X" '((0 . "INSERT")(66 . 1))))
  (if (setq ss (vla-get-activeselectionset doc))
    (progn
      (vlax-for obj ss
        (setq bname (vla-get-effectivename obj))
        (if (not (member bname blks))
          (setq blks (cons bname blks))
        )
        (setAttHeight obj lst)
      )
      (vla-delete ss)
    )
  )
  (setq blkcol (vla-get-blocks doc))
  (foreach blk (mapcar '(lambda (b) (vla-item blkcol b)) blks)
    (vlax-for obj blk
      (if (and
            (= (vla-get-objectname obj) "AcDbAttributeDefinition")
            (setq tag (strcase (vla-get-tagstring obj)))
            (setq item (vl-some '(lambda (x) (member tag x)) lst))
          )
        (vla-put-height obj (cadr item))
      )
    )
  )
  (princ)
)

 

 

 

0 Likes
Message 10 of 18

cadffm
Consultant
Consultant

Hi,

 

start this tool (GlobalChangeAttHeight) AND READ the following command flow.

This Tool is to change all attribute heights and for specific Tags as well

 

 

Sebastian

0 Likes
Message 11 of 18

cadffm
Consultant
Consultant

@zafera5VK85 

You shouldn't use lowercase in Tags, Acad&Tools doesn't support it everywhere

 

@EnM4st3r 

You should compare STRCASE to STRCASE Tag value in your code,

my 2c

Sebastian

0 Likes
Message 12 of 18

EnM4st3r
Advocate
Advocate

You are right, but i thougth strcase for the tags from the user would be enough, since the tags from the attributes themselves can be uppercase only

0 Likes
Message 13 of 18

zafera5VK85
Contributor
Contributor

Thats perfect. Its works well now. Thank you again all.. 

 

All the best

Victor

 

 

0 Likes
Message 14 of 18

cadffm
Consultant
Consultant

>>"since the tags from the attributes themselves can be uppercase only"

 

1. This is right for ATTDEF and TEXTEDIT command ONLY,

2. in AutoCAD ONLY

 

but you can edit the Tag and use lowercase (use properties palette, or "a Tool")

and other programs (one of 100.000, which may have created the DWG/DXF) don't care anyway

 

that's why it is a good idea to compare strcase with strcase strings

Sebastian

Message 15 of 18

paullimapa
Mentor
Mentor

Also as @komondormrex included in his code, why not have ssget to only  include inserts with attributes?

(0 . "insert") (66 . 1)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 16 of 18

zafera5VK85
Contributor
Contributor

Thank you for your advise. I had no idea of Lowercase Tags will be trouble. I will for sure consider on that. 

 

Thanks all again

Best Regars

Victor

0 Likes
Message 17 of 18

cadffm
Consultant
Consultant

You should at least know it and keep it in mind.
If a function doesn't work as expected (ATTEXT, or one of the many great tools),
then just test whether it's because of the lowercase letters.

Sebastian

0 Likes
Message 18 of 18

EnM4st3r
Advocate
Advocate

@cadffm ah ok, good to know.

@paullimapa thx, included that in the code, didnt know 66 is a flag if the block has attributes or not

0 Likes