Jump to content

Recommended Posts

Posted

I found this lisp on another site from a user with the handle jmcshane. Thanks for that! It works well with adding a specified integer to a selected number with multiple copies.

 

(defun c:copyinc (/ IncVal TextObj NewPos TextVal 
NewTextObj)
(vl-load-com)
 (setq IncVal (fix (getreal "\nEnter 
Incremant Value :")))
 (setq    TextObj
    (vlax-ename->vla-object 
(car (entsel "\nSelect Mtext Object :")))
 )

(while
   (setq NewPos (getpoint "\nSelect new position : 
"))
    (setq TextVal (atoi (vla-get-textstring 
TextObj)))
    (setq NewTextObj (vla-copy 
TextObj))
    (vla-move 
NewTextObj
          (vla-get-InsertionPoint 
NewTextObj)
          (vlax-3D-Point 
NewPos)
    )

(vla-put-textstring NewTextObj (+ IncVal TextVal))

(setq TextObj NewTextObj)
 )
 (princ)
)

 

I would like it to function the same way but have the selected number "10410-13" for example get copied and change to this example "10414-17". any help would be appreciated.

Posted

Give this a try:

 

(vl-load-com)

(defun c:CopyInc (/ n ss otext insertionPoint textString pt oNewText i
             newString
            )
 (if (and (setq n (getint "\nEnter increment value (integer): "))
          (setq ss (ssget ":S:E:L" '((0 . "MTEXT,TEXT") (1 . "*#-#*"))))
          (setq oText (vlax-ename->vla-object (ssname ss 0)))
     )
   (while (setq pt (getpoint "\nSpecify new insertion point(s): "))
     (vla-move (setq oNewText (vla-copy oText))
               (vla-get-insertionpoint oText)
               (vlax-3d-point pt)
     )
     (vla-put-textstring
       oNewText
       (strcat
         (substr
           (setq newString
                  (itoa
                    (+ n
                       (atoi (strcat
                               (substr
                                 (setq textString (vla-get-textstring oText))
                                 1
                                 (setq i (vl-string-search "-" textString))
                               )
                               (substr textString (+ 2 i))
                             )
                       )
                    )
                  )
           )
           1
           i
         )
         "-"
         (substr newString (1+ i))
       )
     )
     (setq oText oNewText)
   )
   (cond (n (prompt "\n** Nothing selected ** "))
         ((prompt "\n** Must enter an increment value ** "))
   )
 )
 (princ)
)

Posted

Getting closer. I need to add to the first number before the dash and the numbers after the dash. Like this

10410-13

copies too

10414-17

Posted
Getting closer. I need to add to the first number before the dash and the numbers after the dash. Like this

10410-13

copies too

10414-17

 

I don't know what results you're getting on your end, but a text entity with a TextString = "10410-13" _does_ copy as "10414-17"... Here's a screen shot using 404 (the difference between 1041013 and 1041417) as my increment:

ct.copyinc.png

Posted

Seems to work on my end. Well done, Mat.

Posted

I am sorry was using the number "4" works awesome. I am feeling a bit sheepish

Posted
I am sorry was using the number "4" works awesome. I am feeling a bit sheepish

 

No worries; I'm happy to help. :beer:

Posted

Why not

(vla-put-textstring
 oNewText (strcat
   (substr (setq newString
            (itoa  (+ n
                 (atoi (strcat
                     [b][color="blue"](itoa (+ (atoi (substr
                                  (setq textString (vla-get-textstring oText))
                                  1
                                  (setq i (vl-string-search "-" textString))
                                )
                              ) n )[/color][/b] )
                     (substr textString (+ 2 i))
                   )))))
     1 i )
   "-"
   (substr newString (1+ i))
 )
)

 

and type 4 instead of 404? or 1 than 101?

 

Here's another

(defun c:CopyInc2 (/  n  ss otext
                 insertionPoint textString
                 pt oNewText
                )
 (if (and (setq n (getint "\nEnter increment value (integer): "))
          (setq ss (ssget ":S:E:L" '((0 . "MTEXT,TEXT") (1 . "*#-#*"))))
          (setq oText (vlax-ename->vla-object (ssname ss 0)))
     )
   (while (setq pt (getpoint "\nSpecify new insertion point(s): "))
     (vla-move (setq oNewText (vla-copy oText))
               (vla-get-insertionpoint oText)
               (vlax-3d-point pt)
     )
    [b][color="blue"][color="#8b0000"] (setq NewStr (mapcar '+ (read (Strcat  "(" (vl-string-subst " " "-" (vla-get-textstring Otext)) ")")) (list n n)))
(vla-put-textstring
         	oNewText
               	(strcat (itoa (Car NewStr)) "-" (itoa (Cadr NewStr))))[/color][/color][/b]
               	
     (setq oText oNewText)
   )
   (cond (n (prompt "\n** Nothing selected ** "))
         ((prompt "\n** Must enter an increment value ** "))
   )
 )
 (princ)
)

 

command: CopyInc2

 

HTH

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