Calculate with attributes

Calculate with attributes

jeroendewind
Enthusiast Enthusiast
700 Views
9 Replies
Message 1 of 10

Calculate with attributes

jeroendewind
Enthusiast
Enthusiast

Hi,

 

I've a couple of hundred blocks in my drawing with all manually chosen heights (for example: +1.234). Now the design has changed, so all numbers need to be plussed with the same amount (for ecample all blocks +0.200). Is there a way to do this automatically? 

 

Thanks

0 Likes
Accepted solutions (1)
701 Views
9 Replies
Replies (9)
Message 2 of 10

hmsilva
Mentor
Mentor

Hi jeroendewind,

It should be possible to do what you need.

 

If you do a search in 'Search This Board' for 'add attrubutes' should appear some thread with some similar request.

If not, block name and TAG, it's a dynamic block?

 

Henrique

EESignature

0 Likes
Message 3 of 10

jeroendewind
Enthusiast
Enthusiast

Hi,

Well, I see a lot of solutions with FIELDS. But the problem is that these things are working like a formula and can subtract and add values of given numbers.

I just want to do come calculation with an old attribute definition to create a new one, keeping my block the same. Not A=B+C, but A(new)=A+200.

Otherwise I have to change my block, add field or more attributes, fill these in, in order to get my new value. More work than just change it manually.

0 Likes
Message 4 of 10

3wood
Advisor
Advisor

You can try ALTEXT,

Settings as below:

altext5.JPG

0 Likes
Message 5 of 10

hmsilva
Mentor
Mentor
Accepted solution

@jeroendewind wrote:

Hi,

Well, I see a lot of solutions with FIELDS. But the problem is that these things are working like a formula and can subtract and add values of given numbers.

I just want to do come calculation with an old attribute definition to create a new one, keeping my block the same. Not A=B+C, but A(new)=A+200.

Otherwise I have to change my block, add field or more attributes, fill these in, in order to get my new value. More work than just change it manually.



@hmsilva wrote:

Hi jeroendewind,

It should be possible to do what you need.

 

If you do a search in 'Search This Board' for 'add attrubutes' should appear some thread with some similar request.

If not, block name and TAG, it's a dynamic block?

 ...


Change to your BLOCKNAME and correct TAG...

Untested

 

(vl-load-com)
(defun c:demo (/ a dz i newval val obj oldval ss val)
    (cond ((and (setq ss (ssget "_:L" '((0 . "INSERT") (2 . "BLOCKNAME") (66 . 1))));<- change to correct
                (setq val (getreal "\nEnter value to increase/decrease: "))
           )
           (setq dz (getvar 'dimzin))
           (setvar 'dimzin 0)
           (repeat (setq i (sslength ss))
               (setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
               (mapcar '(lambda (a)
                            (if (= (vla-get-TagString a) "TAG");<- change to correct
                                (progn
                                    (setq oldval (atof (vla-get-TextString a)))
                                    (setq newval (+ oldval val))
                                    (vla-put-TextString
                                        a
                                        (strcat (if (> newval 0.0)
                                                        "+"
                                                    ""
                                                    )
                                                (rtos newval 2 3)
                                        )
                                    )
                                )
                            )
                        )
                       (vlax-invoke obj "GetAttributes")
               )
           )
           (setvar 'dimzin dz)
          )
    )
    (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 6 of 10

jeroendewind
Enthusiast
Enthusiast

@3wood wrote:

You can try ALTEXT

[image]

Settings as below:


Thanks, that's what I mean. Tho the software seems a bit suspecious. Do you know/think it's worth registering?

0 Likes
Message 7 of 10

jeroendewind
Enthusiast
Enthusiast

 


hmsilva wrote:

Hi jeroendewind,

It should be possible to do what you need.

 

If you do a search in 'Search This Board' for 'add attrubutes' should appear some thread with some similar request.

If not, block name and TAG, it's a dynamic block?

 ...


Change to your BLOCKNAME and correct TAG...

Untested

(vl-load-com)
(defun c:demo (/ a dz i newval val obj oldval ss val)
    (cond ((and (setq ss (ssget "_:L" '((0 . "INSERT") (2 . "BLOCKNAME") (66 . 1))));<- change to correct
                (setq val (getreal "\nEnter value to increase/decrease: "))
           )
           (setq dz (getvar 'dimzin))
           (setvar 'dimzin 0)
           (repeat (setq i (sslength ss))
               (setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
               (mapcar '(lambda (a)
                            (if (= (vla-get-TagString a) "TAG");<- change to correct
                                (progn
                                    (setq oldval (atof (vla-get-TextString a)))
                                    (setq newval (+ oldval val))
                                    (vla-put-TextString
                                        a
                                        (strcat (if (> newval 0.0)
                                                        "+"
                                                    ""
                                                    )
                                                (rtos newval 2 3)
                                        )
                                    )
                                )
                            )
                        )
                       (vlax-invoke obj "GetAttributes")
               )
           )
           (setvar 'dimzin dz)
          )
    )
    (princ)
)

Hope this helps,
Henrique


This is too difficult for me, what am I supposed to do? Change TAG or blockname?

0 Likes
Message 8 of 10

hmsilva
Mentor
Mentor

@jeroendewind wrote:

 


@hmsilva wrote:

Hi jeroendewind,

It should be possible to do what you need.

 

If you do a search in 'Search This Board' for 'add attrubutes' should appear some thread with some similar request.

If not, block name and TAG, it's a dynamic block?

 ...


Change to your BLOCKNAME and correct TAG...

...


This is too difficult for me, what am I supposed to do? Change TAG or blockname?


????

You need to change both

(cond ((and (setq ss (ssget "_:L" '((0 . "INSERT") (2 . "BLOCKNAME") (66 . 1))));<- change to correct

and

 

(if (= (vla-get-TagString a) "TAG");<- change to correct

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 9 of 10

jeroendewind
Enthusiast
Enthusiast

Wow, that works perfectly!

 

Thanks a lot!

0 Likes
Message 10 of 10

hmsilva
Mentor
Mentor

@jeroendewind wrote:

Wow, that works perfectly!

 

Thanks a lot!


You're welcome, jeroendewind
Glad I could help!

Henrique

EESignature

0 Likes