how to edit block text to overwrite values

how to edit block text to overwrite values

mbracciahubbard
Contributor Contributor
351 Views
2 Replies
Message 1 of 3

how to edit block text to overwrite values

mbracciahubbard
Contributor
Contributor

I currently have a block that looks like an arrow on both sides and has a text over it that typically says something like "2x8 @ 16" o.c.". I am very new (today) to the use of lisp in AutoCAD. i'm curious if I can use them to perform an action for me that basically lets me click on the text (which is within a block) and prompts me twice; once for the "8" portion of the text and then for the "16" portion of the text. 

 

I am hoping whatever command will be able to replace whatever numbers are already in those spaces, or even just replace the whole text with a new text while still only prompting me for the two select values.

 

Thanks in advance!

0 Likes
352 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant

Instead of having one Attribute with all of that, make the  2x  and the  @  and the  " o.c.  parts as regular Text, and only the  8  and  16  parts as Attributes, with their prompts worded appropriately.  If properly set up with ATTDIA and ATTREQ settings, the process of Inserting the Block will then ask you for those values.

Kent Cooper, AIA
Message 3 of 3

ec-cad
Collaborator
Collaborator

Your block is kind of unique..nested, and with ATTDEF that 'contains' Text..

However, if you use the attached block "SPAN_ARROW.dwg", it has a 'normal' attribute

attached in the same location / size / layer/ ect. as your sample block.

With this Lisp, you can appload it, and at command prompt, just type DO  to run it.

You select as many blocks as you need to modify, instead of just 1 at a time.

 

ECCAD

 

(defun C:DO ()
 (vl-load-com)
 (princ "\nPick the Blocks to modify:")
 (setq ss (ssget))
  (if ss
   (progn
    (setq NewWidth (getstring "\nNew Width:"))
    (setq NewLength (getstring "\nNew Length:"))
    (setq C 0)
    (repeat (sslength ss)
     (setq NewValue (strcat "2x" NewWidth " @ " NewLength (chr 34) " O.C.")); form the new string
      (setq blk (vlax-ename->vla-object (ssname ss c)))
      (if (safearray-value (setq atts (vlax-variant-value (vla-getattributes blk))))
       (progn
        (setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes blk))))
         (foreach att atts
          (setq Tag (vla-get-tagstring att))
            (if (and (/= NewValue "")(= Tag "NOTE"))
              (vla-put-textstring att NewValue)
            ); if
          ); foreach
        ); progn
       ); if 
      (setq C (+ C 1))
     ); repeat
   ); progn
  ); if
); defun

 

0 Likes