carmelo Posted May 4, 2020 Posted May 4, 2020 Hi all, how is it possible to set a variable by selecting a text? I explain: a and b are 2 variables; a is a text who i select; b=a/8. At the end, i print b. Thank you Quote
Tharwat Posted May 4, 2020 Posted May 4, 2020 Welcome to the forum. Can you post your codes ( if you already wrote any ) regarding what you are trying to achieve? Quote
carmelo Posted May 4, 2020 Author Posted May 4, 2020 3 hours ago, Tharwat said: Welcome to the forum. Can you post your codes ( if you already wrote any ) regarding what you are trying to achieve? Thanks i'm sorry but i not have any code (i'm not able..) Anyway, have I been clear with the explanation in the first post? Quote
Tharwat Posted May 4, 2020 Posted May 4, 2020 Alright then, something like this? (defun c:foo (/ a e) (if (and (setq a (car (entsel "\nSelect text : "))) (or (= (cdr (assoc 0 (setq e (entget a)))) "TEXT") (alert "Invlaid object. Try again") ) (or (numberp (setq a (distof (cdr (assoc 1 e))))) (alert "Invalid contents of text <!>") ) ) (princ (/ a 8.0)) ) (princ) ) 1 Quote
BIGAL Posted May 5, 2020 Posted May 5, 2020 Just expanding a bit more in case any more than / 8. Can just type on command line (foo number). (defun foo ( div / a e) (if (and (setq a (car (entsel "\nSelect text : "))) (or (= (cdr (assoc 0 (setq e (entget a)))) "TEXT") (alert "Invlaid object. Try again") ) (or (numberp (setq a (distof (cdr (assoc 1 e))))) (alert "Invalid contents of text <!>") ) ) (princ (/ a div)) ) (princ) ) (defun c:foo8 () (foo 8.0) (princ) ) (defun c:foo4 () (foo 4.0) (princ) ) 1 Quote
Tharwat Posted May 5, 2020 Posted May 5, 2020 8 hours ago, BIGAL said: Just expanding a bit more in case any more than / 8. Can just type on command line (foo number). That expansion is redundant and not required but having one expression to get the value from the user with getreal , getint , getdist would be more than enough I believe. Quote
carmelo Posted May 5, 2020 Author Posted May 5, 2020 Thank you very much! It work only with "text" and no with "mtext". Is it possible to have both? Thanks Quote
Tharwat Posted May 5, 2020 Posted May 5, 2020 You're welcome anytime. Yes it is possible unless you have your Mtext contents formatted then you would be in need of unformatting the contents in prior of retrieving the value. But anyway, just replace the following expression: (= (cdr (assoc 0 (setq e (entget a)))) "TEXT") With this expression. (wcmatch (cdr (assoc 0 (setq e (entget a)))) "TEXT,MTEXT") 1 Quote
carmelo Posted May 5, 2020 Author Posted May 5, 2020 No, does not work with mtext. ps: i use Nanocad but i think not is a problem with simple code Quote
Tharwat Posted May 5, 2020 Posted May 5, 2020 5 minutes ago, carmelo said: No, does not work with mtext. Run the following codes on the Mtext that you tried the previous routine with and post a snapshot of the return message if you can. (and (setq s (ssget "_+.:S:E" '((0 . "MTEXT")))) (alert (vl-princ-to-string (cdr (assoc 1 (entget (ssname s 0)))))) ) Quote
carmelo Posted May 5, 2020 Author Posted May 5, 2020 this is the code and below the message (defun c:divvv (/ a e) (if (and (setq a (car (entsel "\nSelect text : "))) (or (wcmatch (cdr (assoc 0 (setq e (entget a)))) "TEXT,MTEXT") (and (setq s (ssget "_+.:S:E" '((0 . "MTEXT")))) (alert (vl-princ-to-string (cdr (assoc 1 (entget (ssname s 0)))))) ) (alert "Invalid object. Try again") ) (or (numberp (setq a (distof (cdr (assoc 1 e))))) (alert "Invalid contents of text <!>") ) ) (princ (/ a 8.0)) ) (princ) ) Quote
Tharwat Posted May 5, 2020 Posted May 5, 2020 6 minutes ago, Tharwat said: Run the following codes on the Mtext that you tried the previous routine with and post a snapshot of the return message if you can. (and (setq s (ssget "_+.:S:E" '((0 . "MTEXT")))) (alert (vl-princ-to-string (cdr (assoc 1 (entget (ssname s 0)))))) ) Run the above codes separately without adding them to the previous routine. Quote
carmelo Posted May 5, 2020 Author Posted May 5, 2020 Sorry Tharwat, it work, and without your second code! But, if i use an existing mtext, it does not work, and, if i use a new mtext, it work... Quote
Tharwat Posted May 5, 2020 Posted May 5, 2020 The second codes are just for testing and to get sure of the return value of that Mtext. Do you know what does formatted Mtext mean ? Quote
carmelo Posted May 5, 2020 Author Posted May 5, 2020 2 minutes ago, Tharwat said: Do you know what does formatted Mtext mean ? the same of text formatting in Word? i.e., bold, justify...?!? Quote
Tharwat Posted May 5, 2020 Posted May 5, 2020 Can you upload a sample of that drawing that you tested the routine on including the same Mtext that the codes failed with as you previously demonstrated? Please save the drawing to AutoCAD 2016 or earlier for me to be able to open the drawing. 1 Quote
ronjonp Posted May 5, 2020 Posted May 5, 2020 As Tharwat eluded ... (1 . "\\pxqc;{\\fArial|b0|i0|c0|p34;1}") 1 Quote
Tharwat Posted May 5, 2020 Posted May 5, 2020 Thanks Ron. @carmelo Please try the following expanded codes to get the job done the way it should be. (defun c:foo (/ a e) (if (and (setq a (car (entsel "\nSelect text : "))) (or (wcmatch (cdr (assoc 0 (setq e (entget a)))) "TEXT,MTEXT") (alert "Invlaid object. Try again") ) (or (numberp (setq a (distof (Clear_Mtext_String (cdr (assoc 1 e))))) ) (alert "Invalid contents of text <!>") ) ) (princ (/ a 8.0)) ) (princ) ) ;; ;; (defun Clear_Mtext_String (String / Text Str) (setq Text "") (while (/= String "") (cond ((wcmatch (strcase (substr String 1 6)) "\\PXQC;") (setq String (substr String 7)) ) ((wcmatch (strcase (setq Str (substr String 1 2))) "\\[\\{}`~]" ) (setq String (substr String 3) Text (strcat Text Str) ) ) ((wcmatch (substr String 1 1) "[{}]") (setq String (substr String 2)) ) ((and (wcmatch (strcase (substr String 1 2)) "\\P") (/= (substr String 3 1) " ") ) (setq String (substr String 3) Text (strcat Text " ") ) ) ((wcmatch (strcase (substr String 1 2)) "\\[LOP]") (setq String (substr String 3)) ) ((wcmatch (strcase (substr String 1 2)) "\\[ACFHQTW]") (setq String (substr String (+ 2 (vl-string-search ";" String)))) ) ((wcmatch (strcase (substr String 1 2)) "\\S") (setq Str (substr String 3 (- (vl-string-search ";" String) 2)) Text (strcat Text (vl-string-translate "#^\\" " " Str)) String (substr String (+ 4 (strlen Str))) ) (print Str) ) (T (setq Text (strcat Text (substr String 1 1)) String (substr String 2) ) ) ) ) Text ) (vl-load-com) 1 Quote
carmelo Posted May 5, 2020 Author Posted May 5, 2020 3 minutes ago, Tharwat said: Thanks Ron. @carmelo Please try the following expanded codes to get the job done the way it should be. (defun c:foo (/ a e) (if (and (setq a (car (entsel "\nSelect text : "))) (or (wcmatch (cdr (assoc 0 (setq e (entget a)))) "TEXT,MTEXT") (alert "Invlaid object. Try again") ) (or (numberp (setq a (distof (Clear_Mtext_String (cdr (assoc 1 e))))) ) (alert "Invalid contents of text <!>") ) ) (princ (/ a 8.0)) ) (princ) ) ;; ;; (defun Clear_Mtext_String (String / Text Str) (setq Text "") (while (/= String "") (cond ((wcmatch (strcase (substr String 1 6)) "\\PXQC;") (setq String (substr String 7)) ) ((wcmatch (strcase (setq Str (substr String 1 2))) "\\[\\{}`~]" ) (setq String (substr String 3) Text (strcat Text Str) ) ) ((wcmatch (substr String 1 1) "[{}]") (setq String (substr String 2)) ) ((and (wcmatch (strcase (substr String 1 2)) "\\P") (/= (substr String 3 1) " ") ) (setq String (substr String 3) Text (strcat Text " ") ) ) ((wcmatch (strcase (substr String 1 2)) "\\[LOP]") (setq String (substr String 3)) ) ((wcmatch (strcase (substr String 1 2)) "\\[ACFHQTW]") (setq String (substr String (+ 2 (vl-string-search ";" String)))) ) ((wcmatch (strcase (substr String 1 2)) "\\S") (setq Str (substr String 3 (- (vl-string-search ";" String) 2)) Text (strcat Text (vl-string-translate "#^\\" " " Str)) String (substr String (+ 4 (strlen Str))) ) (print Str) ) (T (setq Text (strcat Text (substr String 1 1)) String (substr String 2) ) ) ) ) Text ) (vl-load-com) Now is perfect! wow...you didn't stop until you totally solved the problem! You are a great men Thank you very much 1 Quote
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.