Jump to content

Recommended Posts

Posted

Hi all

 

Could someone help me to create a lisp, that perform arithmetical operation - subtraction only on numerical data within Text/Mtext which may include Alphabetical Prefixes, please?

 

For example: The idea would be to click on the first text, than on  the second text and the second text replacing itself with the answer, So IL0.50 should become IL11.50 and IL1.00 should become IL-0.80

 

First Example:         

CL12.00

IL0.50

 

 

Second example:

CL0.20

IL1.00

 

 

Thank you

Posted (edited)

This one is what you want by Lee I use it various programs regarding to strings with numbers. Example code at end.

 

;;-------------------=={ Parse Numbers }==--------------------;;`
;;                                                            ;;
;;  Parses a list of numerical values from a supplied string. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  s - String to process                                     ;;
;;------------------------------------------------------------;;
;;  Returns:  List of numerical values found in string.       ;;
;;------------------------------------------------------------;;

(defun LM:ParseNumbers ( s )
  (
    (lambda ( l )
      (read
        (strcat "("
          (vl-list->string
            (mapcar
              (function
                (lambda ( a b c )
                  (if
                    (or
                      (< 47 b 58)
                      (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                      (and (= 46 b) (< 47 a 58) (< 47 c 58))
                    )
                    b 32
                  )
                )
              )
              (cons nil l) l (append (cdr l) (list nil))
            )
          )
          ")"
        )
      )
    )
    (vl-string->list s)
  )
)


(defun c:wow ( / num1ent num2ent num1str num2str diff tstr)
  (setq num1ent (entget (car (entsel "\npick 1st text "))))
  (setq num1str (cdr (assoc 1 num1ent)))
  (setq num1 (car (LM:ParseNumbers num1str )))
  (setq num2ent (entget (car (entsel "\npick 2nd text"))))
  (setq num2str (cdr (assoc 1 num2ent)))
  (setq num2 (car (LM:ParseNumbers num2str )))
  (setq diff (- num1 num2))
  (setq tstr (strcat "IL " (rtos diff 2 2)))
  (entmod (subst (cons 1 tstr) (assoc 1 num2ent) num2ent))
  (princ)
)
(c:wow)

 

Edited by BIGAL
  • Thanks 1
Posted
15 hours ago, BIGAL said:

This one is what you want by Lee I use it various programs regarding to strings with numbers. Example code at end.

 

;;-------------------=={ Parse Numbers }==--------------------;;`
;;                                                            ;;
;;  Parses a list of numerical values from a supplied string. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  s - String to process                                     ;;
;;------------------------------------------------------------;;
;;  Returns:  List of numerical values found in string.       ;;
;;------------------------------------------------------------;;

(defun LM:ParseNumbers ( s )
  (
    (lambda ( l )
      (read
        (strcat "("
          (vl-list->string
            (mapcar
              (function
                (lambda ( a b c )
                  (if
                    (or
                      (< 47 b 58)
                      (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                      (and (= 46 b) (< 47 a 58) (< 47 c 58))
                    )
                    b 32
                  )
                )
              )
              (cons nil l) l (append (cdr l) (list nil))
            )
          )
          ")"
        )
      )
    )
    (vl-string->list s)
  )
)


(defun c:wow ( / num1ent num2ent num1str num2str diff tstr)
  (setq num1ent (entget (car (entsel "\npick 1st text "))))
  (setq num1str (cdr (assoc 1 num1ent)))
  (setq num1 (car (LM:ParseNumbers num1str )))
  (setq num2ent (entget (car (entsel "\npick 2nd text"))))
  (setq num2str (cdr (assoc 1 num2ent)))
  (setq num2 (car (LM:ParseNumbers num2str )))
  (setq diff (- num1 num2))
  (setq tstr (strcat "IL " (rtos diff 2 2)))
  (entmod (subst (cons 1 tstr) (assoc 1 num2ent) num2ent))
  (princ)
)
(c:wow)

 

 

 

Thank you BIGAL, Just like I have imagined!  ;) wow

Posted (edited)

BIGAL, may I ask if we could tweak it slightly?

 

1) To Change the colour of the selected entities to the RGB colour (255, 0, 0)   -  basically so it could stand out.

2) It may be not only ''IL'' prefix, but also any other alphabets, for example WL or SL  - for some reason it replaces  WL1.00 to IL 1.00

 

 

🥺

Edited by pyou
Posted

I did not look at prefix so will need a code edit. will see what I can do. 

  • Thanks 1
Posted
On 27/10/2023 at 05:44, BIGAL said:

I did not look at prefix so will need a code edit. will see what I can do. 

Thank you BIGAL

Posted (edited)

I have found the solution.

Edited by pyou

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