Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

edit block attribute properties

12 REPLIES 12
Reply
Message 1 of 13
bdsmls
5163 Views, 12 Replies

edit block attribute properties

I'm looking for a lisp routine that i can globally change the text height and width factor of a particular block attribute. The name of the attribute tag is "TAG". I would like to be able to select all the blocks that i need to edit and then specify what text height and width factor i want to change to.

 

Thanks in advance,

Larry

12 REPLIES 12
Message 2 of 13
gjrcmb
in reply to: bdsmls

Test out the following.  Will not work with multileaders.

 

(defun c:attsize (/ atttag sset ssln txht txwd n enam elst nelst)
    (setq atttag (getstring "\nSpecify Name of Attribute Tag to Change: "))
    (princ "\nSelect Attributed Blocks to Update: ")
    (setq sset (ssget))
    (setq ssln (sslength sset))
    (setq txht (getreal "\nSpecify New Text Height: "))
    (setq txwd (getreal "Specify New Text Width: "))
    (setq n 0)
    (repeat ssln
        (setq enam (ssname sset n))
        (setq elst (entget enam))
        (while (and (setq enam (entnext enam)) (/= (cdr (assoc 0 elst)) "SEQEND"))
            (setq elst (entget enam))
            (if (and (= (cdr (assoc 0 elst)) "ATTRIB") (= (cdr (assoc 2 elst)) (strcase atttag)))
                (progn
                    (setq nelst (subst (cons 40 txht) (assoc 40 elst) elst))
                    (setq nelst (subst (cons 41 txwd) (assoc 41 nelst) nelst))
                    (entmod nelst)
                )
            )
        )
        (setq n (+ n 1))
    )
    (princ)
)

Message 3 of 13
bdsmls
in reply to: bdsmls

Thanks. Worked perfectly

 

Larry

Message 4 of 13
gjrcmb
in reply to: bdsmls

Nice.  Glad I could help.

Message 5 of 13
Jonathan3891
in reply to: gjrcmb

This is a lisp that I use on a daily basis.

 

It allows you to change attributed text properties:

Height

Rotation

Color by number

 

All you need to do is edit to fit your needs.


Jonathan Norton
Blog | Linkedin
Message 6 of 13
moin_cad
in reply to: bdsmls

thanks for your list. nice lisp.

 

How to change width factor of all attributes in a drawing file.

Please reply

 

my email is is moin_cad@yahoo.com

Message 7 of 13
pbejse
in reply to: moin_cad


@moin_cad wrote:

thanks for your list. nice lisp.

 

How to change width factor of all attributes in a drawing file.

Please reply

 

my email is is moin_cad@yahoo.com


(defun GlobalWidth  (wid / blks a)
      (vl-load-com)
      (setq Blks (vla-get-blocks
                       (vla-get-activedocument
                             (vlax-get-acad-object))))
      (while (setq a (tblnext "BLOCK" (null a)))
            (if (= (cdr (Assoc 70 a)) 2)
                  (progn
                        (vlax-for
                               itm
                               (vla-item
                                     Blks
                                     (setq bn (cdr (assoc 2 a))))
                              (if (eq (vla-get-ObjectName
                                            itm)
                                      "AcDbAttributeDefinition")
                                    (vla-put-ScaleFactor itm wid)))
                        (vl-cmdf "_.AttSync" "Name" bn)
                        )
                  )
            )
      (princ)
      )

 

usage:

(globalwidth 0.85)

 

 HTH

 

Message 8 of 13
moin_cad
in reply to: pbejse

How to use this lisp.?

 

i make lsp file of this  but  what command i have to give to run this lisp.

please reply

Message 9 of 13
pbejse
in reply to: moin_cad

I did post a USAGE

 

(GlobalWidt 0.85)

 

otherwise

 

(defun C:Gw  (/ blks a)
      (vl-load-com)
      (setq Blks (vla-get-blocks
                       (vla-get-activedocument
                             (vlax-get-acad-object))))
      (if (not wid)
            (setq wid 1.00))
      (setq wid (cond
                       ((getreal
                              (strcat "\nEnter Width <"
                                      (rtos wid 2 2)
                                      ">: ")))
                       (wid))) 
      (while (setq a (tblnext "BLOCK" (null a)))
            (if (= (cdr (Assoc 70 a)) 2)
                  (progn
                        (vlax-for
                               itm
                               (vla-item
                                     Blks
                                     (setq bn (cdr (assoc 2 a))))
                              (if (eq (vla-get-ObjectName
                                            itm)
                                      "AcDbAttributeDefinition")
                                    (vla-put-ScaleFactor itm wid)))
                        (vl-cmdf "_.AttSync" "Name" bn)
                        )
                  )
            )
      (princ)
      )

 command: GW

Enter Width:

Message 10 of 13
moin_cad
in reply to: pbejse

thanks very nice lisp.

 

but some of my attribute text are moved away from isertion points.. & after running this lisp attirbute text goes to actual

insertion points. 

 

Because of this all text leaves its fix location..

 

Is there any possibility that location will not change. Only we can change the text width .

Please reply..

Tags (1)
Message 11 of 13
pbejse
in reply to: moin_cad

ohh i see then..

Changing the width within the block collection doesnt cut it. we had to do it individually

 

<Untested>

 

(defun C:Gw  (/ aDoc a ss)
      (vl-load-com)
      (setq aDoc (vla-get-activedocument
                       (vlax-get-acad-object)))
      (if (not wid)
            (setq wid 1.00))
      (setq wid (cond
                      ((getreal
                             (strcat "\nEnter Width <"
                                     (rtos wid 2 2)
                                     ">: ")))
                      (wid)))
      (if (ssget "_X" '((0 . "INSERT") (66 . 1)))
            (progn
                  (vlax-for  itm
                         (setq ss (vla-get-activeselectionset aDoc))
                        (foreach
                               atb
                               (vlax-invoke itm 'GetAttributes)
                              (vla-put-ScaleFactor atb wid))
                        )(vla-delete ss)
                        ))
      (princ)
      )

 

HTH

 

Message 12 of 13
Anonymous
in reply to: gjrcmb

Hello,

 

I dont know how to make lisp. can you send to me the ready made lisp by e-mail. My addresss is w_mrd@yahoo.com. 

 

your kind respons will be highly appriciated. 

Message 13 of 13
pbejse
in reply to: Anonymous


@Anonymous wrote:

Hello,

 

I dont know how to make lisp. can you send to me the ready made lisp by e-mail. My addresss is w_mrd@yahoo.com. 

 

your kind respons will be highly appriciated. 


Hi w_mrd, Welcome to the forum.

 

What do you mean by "ready made lisp" ? I'm guessing you want to invoke from Autocad command prompt, correct?

 

Change width of ALL  Attribute definition.

 

 

(defun C:Gw  (/ aDoc a ss)
      (vl-load-com)
      (setq aDoc (vla-get-activedocument
                       (vlax-get-acad-object)))
      (if (not wid)
            (setq wid 1.00))
      (setq wid (cond
                      ((getreal
                             (strcat "\nEnter Width <"
                                     (rtos wid 2 2)
                                     ">: ")))
                      (wid)))
      (if (ssget "_X" '((0 . "INSERT") (66 . 1)))
            (progn
                  (vlax-for  itm
                         (setq ss (vla-get-activeselectionset aDoc))
                        (foreach
                               atb
                               (vlax-invoke itm 'GetAttributes)
                              (vla-put-ScaleFactor atb wid))
                        )(vla-delete ss)
                        ))
      (princ)
      )

 

 

Command: GW

Enter Width <1.00>: .75

 

Change width of  Attribute definition of a particular  Block name via selection

 

 

 

(defun C:Gws  (/ aDoc a ss bn )
      (vl-load-com)
      (setq aDoc (vla-get-activedocument
                       (vlax-get-acad-object)))
      (if (not wid)
            (setq wid 1.00))
      (setq wid (cond 
                      ((getreal
                             (strcat "\nEnter Width <"
                                     (rtos wid 2 2)
                                     ">: ")))
                      (wid)))
      (if (and 	(setq s (ssget "_:S:L" '((0 . "INSERT")(66 . 1))))
	       	(setq bn (strcase  (vla-get-effectivename (vlax-ename->vla-object (ssname s 0)))))
		(ssget "_X" (list '(0 . "INSERT")'(66 . 1)(cons 2 (strcat bn ",`*U*"))))
		)
            (progn
                  (vlax-for itm
			    (setq ss (vla-get-activeselectionset aDoc))
		    (if	(Eq (strcase (vla-get-effectivename itm)) bn)
		      (foreach atb (vlax-invoke itm 'GetAttributes)
			(vla-put-ScaleFactor atb wid)
		      )
		    )
		  )
		    (vla-delete ss)
		  ))
      (princ)
      )

 

 

 

Command: GWS

Enter Width <1.00>: .75

Select objects:

 

 

Specific block / specific Tag via selection

 

 

(defun C:Gwt  (/ aDoc a ss bn nobj tag)
      (vl-load-com)
      (setq aDoc (vla-get-activedocument
                       (vlax-get-acad-object)))
      (if (not wid)
            (setq wid 1.00))
      (setq wid (cond 
                      ((getreal
                             (strcat "\nEnter Width <"
                                     (rtos wid 2 2)
                                     ">: ")))
                      (wid)))
      (if (and	(setq s (entsel "\nSelect Attribute: "))
	    	(setq nobj (car (nentselp (cadr s))))
		(eq (cdr (assoc 0 (entget nobj))) "ATTRIB" )
	       	(print (setq bn (strcase  (vla-get-effectivename (vlax-ename->vla-object (car s))))))
		(ssget "_X" (list '(0 . "INSERT")'(66 . 1)(cons 2 (strcat bn ",`*U*"))))
		)
            (progn
	      	(print (setq tag (strcase (cdr (assoc 2 (entget nobj))))))
                  (vlax-for itm
			    (setq ss (vla-get-activeselectionset aDoc))
		    (if	(Eq (strcase (vla-get-effectivename itm)) bn)
		      (foreach atb (vlax-invoke itm 'GetAttributes)
			(if (eq (strcase (vla-get-tagstring atb)) tag)
			(vla-put-ScaleFactor atb wid)
			  )
		      )
		    )
		  )
		    (vla-delete ss)
		  ))
      (princ)
      )

 

Command: GWT

Enter Width <1.00>: .75

Select Attribute:

"CIRCLE_BLOCK"
"CENTER_TAG"

 

 

HTH

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost