add or minus digit value for digit mtext, leader or block attributes

add or minus digit value for digit mtext, leader or block attributes

mruPRQUJ
Advocate Advocate
2,478 Views
22 Replies
Message 1 of 23

add or minus digit value for digit mtext, leader or block attributes

mruPRQUJ
Advocate
Advocate

Hi,

Attatched lisp can add or minus digit value for digit mtext, leader or block attributes. I wonder if it is possible to modify many objects at one time. Also, can I get spitted lisp? one for mtext ,one for leader, one for block attribute, many thanks. 🙂

0 Likes
Accepted solutions (1)
2,479 Views
22 Replies
Replies (22)
Message 2 of 23

Kent1Cooper
Consultant
Consultant

Some questions:

If you hit Enter at the Add-or-Subtract prompt, to get the Add option that it is showing as the default <A>, you would really get the value Subtracted, because the 'as' variable will be nil, not "A".  I assume you would prefer to have that corrected.

And it looks like the Block category assumes a Block with only one Attribute, since it appears to work with only the first Attribute in the list of all Attributes, whether or not that's the one you want to change.  Do you really want that?  Will you always use it only on Blocks with only one Attribute?

Kent Cooper, AIA
Message 3 of 23

mruPRQUJ
Advocate
Advocate

Hi,

Please correct the first mistake. the block is ok, thanks a million! 🙂 

0 Likes
Message 4 of 23

mruPRQUJ
Advocate
Advocate

Hi,

I wonder if it is possible to divide the lisp to three lisp? one for mtext ,one for leader, one for block attribute, many thanks. 🙂

0 Likes
Message 5 of 23

calderg1000
Mentor
Mentor

Regards @mruPRQUJ 

Try this code to add or subtract a value to numeric text objects. The option Enter has been blocked, Select A or S

;;;---
(defun c:stx (/ n as stx tx)
  (Initget 1 "A S")
  (setq as (getkword "Select Adiction/Substraction [A/S]: "))
  (if (= as "A")
    (setq n (getreal "\nEnter Numeric Value To Add: "))
    (setq n (getreal "\nEnter Numeric Value To Subtract: "))
  )
  (princ "\nSelect Numeric Texts:")
  (setq stx (ssget '((0 . "*text")))
  )
  (if (= as "A")
    (setq n n)
    (setq n (* -1 n))
  )
  (repeat (setq i (sslength stx))
    (setq sn (vlax-ename->vla-object (ssname stx (setq i (1- i))))
          tx
             (vla-get-textstring
               sn
             )
          tx
             (+ (atof tx) n)
    )
    (vla-put-textstring sn tx)
  )
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 6 of 23

mruPRQUJ
Advocate
Advocate

Hi,

It works perfect for mtext. Can you please make same change to leader and block attributes? It is a little late today, I may not response today, many thanks. 🙂

0 Likes
Message 7 of 23

calderg1000
Mentor
Mentor
Accepted solution

Regards @mruPRQUJ 

There you have for mleaders...

;;;---
(defun c:slx (/ n as i sn stx tx)
  (Initget 1 "A S")
  (setq as (getkword "Select Adiction/Substraction [A/S]: "))
  (if (= as "A")
    (setq n (getreal "\nEnter Numeric Value To Add: "))
    (setq n (getreal "\nEnter Numeric Value To Subtract: "))
  )
  (princ "\nSelect Mleaders: ")
  (setq stx (ssget '((0 . "Multileader")))
  )
  (if (= as "A")
    (setq n n)
    (setq n (* -1 n))
  )
  (repeat (setq i (sslength stx))
    (setq sn (vlax-ename->vla-object (ssname stx (setq i (1- i))))
          tx
             (+ (atof (vla-get-textstring
                        sn
                      )
                )
                n
             )
    )
    (vla-put-textstring sn tx)
  )
)

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 8 of 23

mruPRQUJ
Advocate
Advocate

Hi,

 

The lisp did not work, I may make a mistake. If "1" was added, it changed the original value to 1 first. The original value should not be changed. If it was changed again, and then added 1 each time. MTEXT lisp has the same problem, thanks. 🙂

0 Likes
Message 9 of 23

Kent1Cooper
Consultant
Consultant

An little efficiency item in the original and carried into the modifications:

 

This is bloated:

 

(if (= as "A")
  (setq n n)
  (setq n (* -1 n))
)

 

Setting something to itself is pointless.  And the (-) function with just one argument can be used to make something negative directly, rather than multiply it by -1.  I would test for the Subtract option instead [if it's Add, do nothing], and do this:

 

(if (= as "S") (setq n (- n)))

Kent Cooper, AIA
Message 10 of 23

mruPRQUJ
Advocate
Advocate

same problem, I may make a mistake, many thanks. Also, could you please confirm to use 

(if (= as "S") (setq n (- n)))

to replace

(if (= as "A")
(setq n n)
(setq n (* -1 n))
)

0 Likes
Message 11 of 23

calderg1000
Mentor
Mentor

Regards @mruPRQUJ 

Although my code is not very elegant it should work, simplify the conditional for the negative value a bit. But the problem is not there, it is possible that you have "Mtext" texts with formats and therefore it does not recognize them when converting them to numeric values. I made some improvements so that it can be solved. I hope it helps you, otherwise show me your file, to make it custom, since a generic code takes time.

Try this code...

(defun c:slx (/ n as i sn tx ps)
  (Initget 1 "A S")
  (setq as (getkword "Select Adiction/Substraction [A/S]: "))
  (if (= as "A")
    (setq n (getreal "\nEnter Numeric Value To Add: "))
    (setq n (getreal "\nEnter Numeric Value To Subtract: "))
  )
  (princ "\nSelect Mleaders: ")
  (setq stx (ssget '((0 . "Multileader")))
  )
  (if (/= as "A")
    (setq n (- n))
  )
  (repeat (setq i (sslength stx))
    (setq sn (vlax-ename->vla-object (ssname stx (setq i (1- i))))
          tx
             (vla-get-textstring
               sn
             )
    )
    (if (/= (numberp (distof tx)) t)
      (progn
        (setq ps (vl-string-position (ascii ";") tx)
              tx (+ (distof (substr tx (+ ps 2))) n)
        )
        (vla-put-textstring sn tx)
      )
      (progn
        (setq tx (+ (distof tx) n))
        (vla-put-textstring sn tx)
      )
    )
  )
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 12 of 23

Sea-Haven
Mentor
Mentor

Why make the choice to add or subtract just enter the value as a positive or negative value.

 

5 + 1 = 6

5 + -1 = 4

0 Likes
Message 13 of 23

mruPRQUJ
Advocate
Advocate

Hi,

 

I am sorry to reply to you late as I am tied up with my work. It looks like it did not work, I may make a mistake. Please see the image below, thank you very much all of you! 🙂

mruPRQUJ_0-1690119815855.png

 

0 Likes
Message 14 of 23

calderg1000
Mentor
Mentor

Regards @mruPRQUJ 

The code is not generic for all cases. Most likely, you have texts with a special format, which is why it doesn't work. To avoid the error, first you have to delete the format to the Mtext, for this you can do it from ACAD, as I indicate in the image. Or you can use some of the lisp that have been posted on the forum. After that, apply the routine and you shouldn't have any problems.

Otherwise, attach your DWG, to give you a demonstration...

calderg1000_0-1690134315485.png

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 15 of 23

mruPRQUJ
Advocate
Advocate

Hi, is it possible to split the original lisp into three? one for mtext , one for leader, and one for block attribute? That one has no this issue, many thanks. 

mruPRQUJ_0-1690138516365.png

 

0 Likes
Message 16 of 23

calderg1000
Mentor
Mentor

Regards @mruPRQUJ 

The code maintains the same characteristics as the original. For me it works fine... I attach video.

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 17 of 23

mruPRQUJ
Advocate
Advocate

 I tested the original Lsp a few times, not too much, did not realized it, sorry about it. I think I used AutoCAD to created mtext and mleader, no special format. I am away from my computer, I am not sure about it. I can confirm it tomorrow. If no special format, can I send this dwg to you? After removing all the format, your lisp did works. It may be not good practice, thank you very much for your great help! 😀

0 Likes
Message 18 of 23

mruPRQUJ
Advocate
Advocate

The dwg is simple AutoCAD file, format is standard format. But it has the same problem, please see attached dwg, many thanks.

0 Likes
Message 19 of 23

Kent1Cooper
Consultant
Consultant

You do have special formatting in some of those things:

Kent1Cooper_0-1690219317746.png

 

Kent Cooper, AIA
Message 20 of 23

mruPRQUJ
Advocate
Advocate

Could you please advise me where these stuffs come from? I Created a simple new AutoCAD file, use AutoCAD standard text style and leader style. Also, the contents have special items. But if removing the format, the lisp will work. I am not sure if they are related each other, many  thanks. 🙂

0 Likes