Modify one attribute value and width factor in a block

Modify one attribute value and width factor in a block

Bin2009
Advocate Advocate
1,606 Views
8 Replies
Message 1 of 9

Modify one attribute value and width factor in a block

Bin2009
Advocate
Advocate

Hello,

I’d like to modify one attribute value and width factor in a block, for example, I need change the attribute value from “MASTER MAP” to “ASSUMED TELUS COMMUNICATIONS CABLE MASTER MAP” in the block, also I need change width factor to 0.7 to suit the space. Since I need repeat doing this adjustment for many drawing, so I am looking for a lisp can quickly do the change,

 
 

 I searched and find below code

(defun c:CH_ATTR_WIDTH ( / new_width atent atent_list)

(setq new_width (getreal "\nEnter new width factor: "))

(setq atent (car (nentsel "\nSelect multiline attribute to change width factor: ")))

(setq atent_list (entget atent))

(setq atent_list (subst (cons 41 new_width) (assoc 41 atent_list) atent_list ))

(entmod atent_list)

(princ)

)

From https://forums.autodesk.com/t5/autocad-forum/width-factor-of-multiline-attribute/td-p/3896512

It can only change the width factor.

I attached the cad file with the block TITLE.

Highly appreciate if anyone can help.

Thank very much in advance.

Bin

0 Likes
1,607 Views
8 Replies
Replies (8)
Message 2 of 9

Sea-Haven
Mentor
Mentor

The dxf code for the attribute text is 1 so just repeat the line changing widtH, plus entmod but with 1 and new_text.

0 Likes
Message 3 of 9

ВeekeeCZ
Consultant
Consultant

Try this one:

 

;; usage: (BlocksAttUpdate "BlockName" "AttTag" "NewAttValue" NewAttWidth)  ; note lastone without "" 

(vl-load-com)

(defun BlocksAttUpdate (blkname attname attval attwid  / s e i a attname blk val col)
  (if (setq s (ssget "_A" '((0 . "INSERT") (66 . 1))))
    (repeat (setq i (sslength s))
      (if (wcmatch (vla-get-effectivename (vlax-ename->vla-object (setq e (ssname s (setq i (1- i)))))) blkname)
	(while (/= "SEQEND" (cdr (assoc 0 (entget (setq e (entnext e))))))
	  (if (and (= "ATTRIB" (cdr (assoc 0 (entget e))))
		   (setq a (vlax-ename->vla-object e))
		   (= attname (strcase (vla-get-tagstring a))))
	    (progn
	      (vla-put-textstring a attval)
	      (vla-put-scalefactor a attwid)))))))
  (princ)
  )

 

0 Likes
Message 4 of 9

Bin2009
Advocate
Advocate

Hello @ВeekeeCZ 

Thank for your help,

I tried your code, but it shows " error: too few arguments", wondering if I missing something?

Thanks 

Bin

0 Likes
Message 5 of 9

ВeekeeCZ
Consultant
Consultant

Not having that. You must do something wrong. You should post what your expression was...

btw you might want to remove¨the strcase, it could be confusing.

 

(strcase (vla-get-tagstring a))

 

 
0 Likes
Message 6 of 9

pbejse
Mentor
Mentor

@Bin2009 wrote:

Hello,

I’d like to modify one attribute value and width factor in a block, for example, I need change the attribute value from “MASTER MAP” to “ASSUMED TELUS COMMUNICATIONS CABLE MASTER MAP” in the block, also I need change width factor to 0.7 to suit the space. Since I need repeat doing this adjustment for many drawing, so I am looking for a lisp can quickly do the change,


 

Sheet info on a titleblock with varying widths is not ideal, specially it belongs to the same info box.
Why not like this.?

this.png

or a fourth line, that is if every line refers to something specific

or this.png

There must be a better way to deal with your issue with space.  

I take it the attributes on your titleblock is not a multiline attribute. So i believe its easy to come up with a better solution compared to fudging the width.

 

Post a sample drawing and we will see what can come up as an alternative.

 

 

 

0 Likes
Message 7 of 9

Bin2009
Advocate
Advocate

 Hello, @pbejse

Thank for your response, the block I attached is what we should use, they want to the text width be 1 if can fit in the space, only when the line of text can't fit in, adjust the width factor to something smaller than 1, so we can't use same width factor for all 4 lines if one of the line have super long text value.

 Sample2.JPG

current I have to manually go to here type in the width factor.

Thanks

Bin

 

 

0 Likes
Message 8 of 9

Sea-Haven
Mentor
Mentor

Maybe it is ok to use shorter words abreviated.

 

ASSUMED TELUS COMMUNICATIONS CABLE MASTER MAP

ASSUMED TELUS COMM'S CABLE MASTER MAP

ASS'D TELUS COMM'S CABLE MASTER MAP

0 Likes
Message 9 of 9

pbejse
Mentor
Mentor

@Bin2009 wrote:

 Hello, @pbejse

Thank for your response, the block I attached is what we should use, they want to the text width be 1 if can fit in the space..


My point is, why does it need to be on one line, Why not on another line like what is shown on the images i posted on my previous reply. Clearly there's a lot of space for the long description. Who is they ? is there a restriction to what information goes on a specific line? 

 

I dont see any attached drawing of a block. I can assure you, what i suggested can easily be achieve thru coding.

It's still up to you.

 

Also, it appears that you are targetting a specific line and wanting to process multiple files 

You can  use a script in conjuction with @ВeekeeCZ  posted code.  

Or manually per file:

 

 

(defun c:Dothis (/ ss)
  (and
    (setq ss (ssget "_X" '((0 . "INSERT")(66 . 1)(2 . "YourSecretBlockName"))))
    (foreach x (mapcar 'vlax-ename->vla-object
		       (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
	       )
      (Vl-some '(lambda (at)
		(if (eq (vla-get-tagstring at) "LINE1")
		  (progn
		    (vlax-put at "Textstring" "ASSUMED TELUS COMMUNICATIONS CABLE MASTER MAP")
		    (vlax-put at "Scalefactor" 0.70)(Vlax-get at 'Textstring)
		  )
		)
	      )
	     (Vlax-invoke x 'GetAttributes)
	     )
	    )	
    )
    (princ)
  )

 

 

- Replace "YourSecretBlockName" with the block name ( you obviously dont want to share it)

- Replace "LINE1" with the correct TAG name, although it shows on the image i'm not sure if thats the line you really need to change

- Replace 0.70 with the desired width, on the posted image it shows 0.575

 

HTH

0 Likes