Jump to content

mText converting/calculating


Beginner2015

Recommended Posts

Hello @ all,

 

i am new in this forum, and i hope that anybody can help me with my task:)

 

i often become dwg-files from our customers. In this files there are many components. All components have an mtext with a length.

 

here are some examples of which can be in the mtext.

-F 450

-N 380

-1120

-D+B 1120

 

the problem is that we need other lengths for our production. So i have to change each mtext manually.

 

for example:

if an mtext contains "F 450" than calculate "450-4" --> F 446

 

if an mtext contains "N 380" than calculate "380+23" --> N 403

 

if an mtext contains "1120" than calculate "1120-4" --> 1116

 

if an mtext contains "D+B 1120" than calculate "1120-4" --> D+B 1116

 

the letter before the number decides how much is subtracted.

if there is no letter before the number than subtract "-4"

 

is it possible to create a lisp that can change all selected mtext`s and calculate it to our lengths?

 

Thanks for your help

Link to comment
Share on other sites

Welcome to CADTutor .

 

have a play with this program and let me know .

 

(defun c:Test (/ ss)
;;;    Tharwat 17.01.2015    ;;;
 (if (setq ss (ssget "_:L" '((0 . "MTEXT,TEXT") (1 . "F*#,N*#,*#*,D+B*#"))))
   ((lambda (i / sn e st)
      (while (setq sn (ssname ss (setq i (1+ i))))
        (cond
          (    (wcmatch (setq st (cdr (assoc 1 (setq e (entget sn))))) "F*#")
               (setq st (strcat "F " (itoa (- (read (substr st 2)) 4))))
           )
          (    (wcmatch st "N*#") (setq st (strcat "N " (itoa (+ (read (substr st 2)) 23))))
          )
          (    (wcmatch st "D+B*#") (setq st (strcat "D+B " (itoa (- (read (substr st 4)) 4))))
          )
          (    (numberp (read st)) (setq st (itoa (- (read st) 4))))
        )
        (entmod (subst (cons 1 st) (assoc 1 e) e)
        )  )  )
     -1
   )
 )
 (princ)
)

Edited by Tharwat
replaced - with + and thanks to Henrique
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...