Jump to content

Block Attributes


Ark Angel

Recommended Posts

Is there a way of editing an attribute of a block so it will add a constant number (say 5) to all values in the block across the drawing. e.g. Assume 'A 125' and 'A 126' are blocks, can I edit the attribute so they become 'A 130' and 'A 131' and so on. Similiar to adding a formula to a cell in MS Excel.

Link to comment
Share on other sites

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • Ark Angel

    11

  • Tharwat

    8

  • Commandobill

    2

  • Lee Mac

    1

Top Posters In This Topic

Posted Images

Thanks commando but it doesn't seem to do the trick unless I'm using it improperly.

 

I misread your original post. Sorry about that!

Link to comment
Share on other sites

Yes. The default, prompt and tag are just 'A' before the block is created. What I want to do is retain the existing value in all blocks, but add 302. So when the block is redefined it will read ' A + 302 '

Link to comment
Share on other sites

You want to sum current number in attribute string with a specific number or concatenate current attribute string with a number ?

 

Did you try the program that posted by Lee above ?

Link to comment
Share on other sites

Tharwat,

 

The former, add 302 to random numbers entered as an attribute value in a block. had to look up what 'concatenate' meant.

 

Thanks.

Link to comment
Share on other sites

had to look up what 'concatenate' meant.

 

It means to append two or more strings with each others .

 

Can you upload a sample drawing or a snapshot ?

Link to comment
Share on other sites

attachment.php?attachmentid=55091&cid=1&stc=1

I dont know if you can see this but on the the left is the unexploded block with values entered, on the right the exploded block. I want to add 302 to the digits after the B. There are about 400 of the same block in the drawing and they all need to have 302 added to the value. looking for an easy (quick) fix. I have about 10 of these drawings to change, each with diffrent values, some need to add 32, some 24, some 619 etc.

CAD.jpg

Link to comment
Share on other sites

Try this :

 

(defun c:Test (/ st s)
;;	Tharwat 04.Aug.2015	;;
 (if (and (/= "" (setq st (getstring "\nEnter a string to add to attributes in blocks:")))
          (princ "\nSelect Attributed Blocks")
          (setq s (ssget "_:L" '((0 . "INSERT")(66 . 1))))
          )
   ((lambda (i / sn)
      (while (setq sn (ssname s (setq i (1+ i))))
      (mapcar '(lambda (u) (vla-put-textstring u (strcat (vla-get-textstring u) st)))
             (vlax-invoke (vlax-ename->vla-object sn) 'getattributes)
             )
        ))
     -1)
   )
 (princ)
 ) (vl-load-com)

Link to comment
Share on other sites

Open Notepad with new file , copy and paste the codes inside that file then save it with any name you like with extension .lsp then go back to Autocad and run the command appload or ap then select the previous saved file and then success , type test to run the lisp routine .

Link to comment
Share on other sites

It just adds '302' to the end of the text. i.e. 12345 becomes 12345302 not 12647

 

12345

+ 302

-------

12647

 

You just answered my question that I asked you along replies ago . :D

 

I need to go now and if no one gave you a solution till tomorrow , I would be back to you to write a new program .

Link to comment
Share on other sites

Sorry for late reply , I had to finish my urgent work first .

 

Try this program and let me know.

 

(defun c:Test (/ s val)
 ;;	Tharwat 06.Aug.2015	;;
 (if (and (/= ""
              (setq
                val (getstring
                      "\nEnter a number to add to attributes in blocks :"
                      )
                )
              )
          (numberp (read val))
          (princ "\nSelect Attributed Blocks")
          (setq s (ssget "_:L" '((0 . "INSERT") (66 . 1))))
          )
   ((lambda (i / sn str l no st)
      (while (setq sn (ssname s (setq i (1+ i))))
        (mapcar
          '(lambda (u)
             (setq str (vla-get-textstring u)
                   l   nil
                   no nil
                   st nil
                   l   (vl-string->list str)
                   )
             (mapcar '(lambda (n)
                        (if (< 47 n 58)
                          (setq no (append no (list n)))
                          (setq st (append st (list n)))
                          )
                        )
                     l
                     )
             (if no
               (vla-put-textstring
                 u
                 (vl-string-subst
                   (itoa (+ (read val) (read (vl-list->string no))))
                   (vl-list->string no)
                   str
                   )
                 )
               )
             )
          (vlax-invoke (vlax-ename->vla-object sn) 'getattributes)
          )
        )
      )
     -1
     )
   )
 (princ)
 )(vl-load-com)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...