Beginner2015 Posted January 17, 2015 Share Posted January 17, 2015 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 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 17, 2015 Share Posted January 17, 2015 (edited) 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 January 18, 2015 by Tharwat replaced - with + and thanks to Henrique Quote Link to comment Share on other sites More sharing options...
Beginner2015 Posted January 18, 2015 Author Share Posted January 18, 2015 @Tharwat, WOW this is awesome! It works perfect! Thank you very much, i can`t belive that this works:D:D:D Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 18, 2015 Share Posted January 18, 2015 @Tharwat, WOW this is awesome! It works perfect! Thank you very much, i can`t belive that this works:D:D:D Ha ha ha ... , you are most welcome . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.