Jump to content

Add or Substract from a value


meric_u2003
 Share

Recommended Posts

Hi Mmebers,

I have some ground elevations in my drawing i want to substrat 0.3 or 0.5 from tht value and also after changing i need to change the colour of the value same time.Is there any lisp for that?? Any one can help me..

 

sorry for my bad Englsih

Link to comment
Share on other sites

This ... ?

 

(vl-load-com)
(defun c:Test (/ kw no s)
 ;;---- Tharwat 16. April. 2013 ----;;
 (if (and (progn
            (initget "Add Subtract")
            (setq kw (getkword "\n Choose one [Add,Subtract] :"))
          )
          (setq no (getdist "\n Specify the value :"))
          (progn
            (princ "\n Select Texts ")
            (ssget "_:L" '((0 . "*TEXT")))
          )
     )
   (progn
     (vlax-for x (setq
                   s (vla-get-ActiveSelectionSet
                       (vla-get-ActiveDocument (vlax-get-acad-object))
                     )
                 )
       (if (numberp (read (vla-get-textstring x)))
         (if (eq kw "Add")
           (vla-put-textstring
             x
             (strcat (rtos (+ (read (vla-get-textstring x)) no) 2 2))
           )
           (vla-put-textstring
             x
             (strcat (rtos (- (read (vla-get-textstring x)) no) 2 2))
           )
         )
       )
     )
     (vla-delete s)
   )
 )
 (princ)
)

Link to comment
Share on other sites

Add.jpg

I mean like this from those values i want to substract or add... there is a lot of values to be done

 

like 96.04-0.03=96.01 likewise

 

like while am clicking on tht number it automatically change

Link to comment
Share on other sites

Try this ... :)

 

(vl-load-com)
(defun c:Test (/ kw no s st v)
 ;;---- Tharwat 16. April. 2013 ----;;
 (if (and (progn
            (initget "Add Subtract")
            (setq kw (getkword "\n Choose one [Add,Subtract] :"))
          )
          (setq no (getdist "\n Specify the value :"))
          (progn
            (princ "\n Select Texts ")
            (ssget "_:L" '((0 . "*TEXT")))
          )
     )
   (progn
     (vlax-for x (setq
                   s (vla-get-ActiveSelectionSet
                       (vla-get-ActiveDocument (vlax-get-acad-object))
                     )
                 )
       (if (numberp (read (vla-get-textstring x)))
         (progn
           (setq st (vla-get-textstring x)
                 v  (rtos no 2 2)
           )
           (cond
             ((eq kw "Add")
              (vla-put-textstring
                x
                (strcat st "+" v "=" (rtos (+ (read st) (read v)) 2 2))
              )
             )
             (t
              (vla-put-textstring
                x
                (strcat st "-" v "=" (rtos (- (read st) (read v)) 2 2))
              )
             )
           )
         )
       )
     )
     (vla-delete s)
   )
 )
 (princ)
)

Link to comment
Share on other sites

Tharwat you dont need add or subtract as a option a negative value implies when added to a number to subtract anyway. Hence the wording enter height adjustment.

 

Just realised a simple problem in the code posted including mine need a extra question decimal places required set it say at a default value so can do a enter for default. 0 1 2 3 .

 

Also does the code need to be able to change the FL=90.36 to FL=90.06 this can be done quite easily as a variation on the code's posted thanks to Lee's parse number lisp.

 

Heres a double version pick pick etc or multi pick an oldy quite a few years ago

 

; Adds a fixed amount to a number
;(PRINC "\nTO USE JUST TYPE A2L or A2LM for multiple ")
(Alert "TO USE JUST TYPE A2L or A2LM for multiple ")

;(setvar "cmdecho" 1)
(setq olddimzin (getvar "Dimzin"))
(setvar "dimzin" 0)
(DEFUN c:A2L ()
(setq v2 (getreal "\nEnter ht adjustment "))
(setq test 1)
(while (= test 1)
     (setq en1 (car (entsel "\nSelect text number:" )))
      (if (/= en1 nil)
       (progn
       (setq el1 (entget en1))
       (setq v1 (atof (cdr (assoc 1 el1))))
       (setq a (+ v1 v2))
       (setq b (rtos a 2 3))
       (setq el (subst (cons 1 b) (assoc 1 el1) el1))
       (entmod el)
;        (entupd en1)
       );progn
      (princ "\nplease pick again"); else
    );if
); while true
(setq el nil)
(setq en nil)
(setq a nil)
(setq v1 nil)
(setvar "cmdecho" 1)
(setvar "dimzin" olddimzin)
(princ)
); END a2l DEFUN
(defun c:A2LM ()
(setq v2 (getreal "\nEnter ht adjustment "))
(setq ss (ssget (list (cons 0 "Text"))))
(setq len (sslength ss))
(setq x 0)
(repeat len
(setq en1 (ssname ss x))
       (setq el1 (entget en1))
       (setq v1 (atof (cdr (assoc 1 el1))))
       (setq a (+ v1 v2))
       (setq b (rtos a 2 3))
       (setq el (subst (cons 1 b) (assoc 1 el1) el1))
       (entmod el)
(setq x (+ x 1))
); repeat
(setq el nil
     ss nil)
(setq en nil)
(setq a nil)
(setq v1 nil)

(setvar "dimzin" olddimzin)
(setvar "cmdecho" 1)
(princ)
); END a2lm DEFUN

  • Thanks 1
Link to comment
Share on other sites

  • 8 years later...
On 4/17/2013 at 6:44 AM, BIGAL said:

Tharwat you dont need add or subtract as a option a negative value implies when added to a number to subtract anyway. Hence the wording enter height adjustment.

 

Just realised a simple problem in the code posted including mine need a extra question decimal places required set it say at a default value so can do a enter for default. 0 1 2 3 .

 

Also does the code need to be able to change the FL=90.36 to FL=90.06 this can be done quite easily as a variation on the code's posted thanks to Lee's parse number lisp.

 

Heres a double version pick pick etc or multi pick an oldy quite a few years ago

 

 



; Adds a fixed amount to a number
;(PRINC "\nTO USE JUST TYPE A2L or A2LM for multiple ")
(Alert "TO USE JUST TYPE A2L or A2LM for multiple ")

;(setvar "cmdecho" 1)
(setq olddimzin (getvar "Dimzin"))
(setvar "dimzin" 0)
(DEFUN c:A2L ()
(setq v2 (getreal "\nEnter ht adjustment "))
(setq test 1)
(while (= test 1)
     (setq en1 (car (entsel "\nSelect text number:" )))
      (if (/= en1 nil)
       (progn
       (setq el1 (entget en1))
       (setq v1 (atof (cdr (assoc 1 el1))))
       (setq a (+ v1 v2))
       (setq b (rtos a 2 3))
       (setq el (subst (cons 1 b) (assoc 1 el1) el1))
       (entmod el)
;        (entupd en1)
       );progn
      (princ "\nplease pick again"); else
    );if
); while true
(setq el nil)
(setq en nil)
(setq a nil)
(setq v1 nil)
(setvar "cmdecho" 1)
(setvar "dimzin" olddimzin)
(princ)
); END a2l DEFUN
(defun c:A2LM ()
(setq v2 (getreal "\nEnter ht adjustment "))
(setq ss (ssget (list (cons 0 "Text"))))
(setq len (sslength ss))
(setq x 0)
(repeat len
(setq en1 (ssname ss x))
       (setq el1 (entget en1))
       (setq v1 (atof (cdr (assoc 1 el1))))
       (setq a (+ v1 v2))
       (setq b (rtos a 2 3))
       (setq el (subst (cons 1 b) (assoc 1 el1) el1))
       (entmod el)
(setq x (+ x 1))
); repeat
(setq el nil
     ss nil)
(setq en nil)
(setq a nil)
(setq v1 nil)

(setvar "dimzin" olddimzin)
(setvar "cmdecho" 1)
(princ)
); END a2lm DEFUN
 

 

@BIGAL

Edited by Ish
H
Link to comment
Share on other sites

Time to start learning some code, this is quite easy so a good start for you.. and google is also your friend.

 

So in BigAls example he has a couple of lines asking for ht adjustment, something like this "(setq v2 (getreal "\nEnter ht adjustment "))" and I reckon that they are the lines to look at changing.

 

An internet search might give you this to try: (setq v2 (vla-get-TextString (vlax-ename->vla-object (car (entsel)))))

 

Note from experience that this line doesn't have any text to tell the user what it is expecting, you might try something like (princ "zzzz") just before this line to tell the user what to do, and you might get an error that your new V2 is seen as a text string rather than a number, again you can look at Google to see what it says to fix that... it is all out there... (for string to integer maybe try (type v2) to show what it is and then a search if that result is STR what to do... (if (= 'STR (type v2))(princ "String")(princ "Number")).. and then just change the 2 princ commands to what you need it to do).

 

There I reckon that should be enough to give you some thinking but also a solution

 

Much nicer way of asking and you get better help if you can have a go and then ask "I have tried these changes but it isn't quite working"

  • Agree 1
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
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.

 Share

×
×
  • Create New...