Jump to content

add subtract numbers selectable


clint0577

Recommended Posts

How can I make this allow me to select the text to be edited?

 

(defun c:AFF ( / ss)
 (vl-load-com)
 (if (and (setq ss (ssget "X" (list (cons 0 "*text"))))
      (setq amt (getreal "\nPlease type the amount you would like to add: ")))
   (progn
     (mapcar '(lambda (z) (vla-put-textstring z (rtos (+ (atof (vla-get-textstring z)) amt) 2 2)))
         (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
     )
   )
 (princ)
 )

Link to comment
Share on other sites

If you're going to work with the Vla-Object for each entity in the Selection Set, then simply iterate the ActiveSelectionSet Collection Object instead of applying Vlax-Ename->Vla-Object to an iterated Selection Set (using SSNAME)... Much faster :thumbsup:

 

(vl-load-com)

(defun c:FOO ( / ss amt)
 (if (and (setq ss (ssget "_:L" '((0 . "*TEXT"))))
          (setq amt
                 (getreal "\nPlease type the amount you would like to add: ")
          )
     )
   (progn
     (vlax-for x (setq ss (vla-get-activeselectionset
                            (vla-get-activedocument
                              (vlax-get-acad-object)
                            )
                          )
                 )
       (vla-put-textstring
         x
         (rtos (+ (atof (vla-get-textstring x)) amt) 2 2)
       )
     )
     (vla-delete ss)
   )
 )
 (princ)
)

** Note - Error handling not included.

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...