Temy Posted February 17, 2020 Share Posted February 17, 2020 HI FRIENDS. I HAVE AVAILABLE A SIZE VALUE, I WANT TO CREATE AN MTEXT THAT MEANS THAT VALUES (ACCORDING TO STANDARD). PLEASE HELP ME TO DO THAT. THANK YOU. help.pdf help.dwg Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted February 17, 2020 Share Posted February 17, 2020 I think this works (vl-load-com) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; draw Mtext (defun M-Text (pt str ht ang) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 pt) (cons 40 ht) (cons 50 ang) (cons 1 str))) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; correct - extend if needed (setq conversionData '( ("10A" 17.3) ("15A" 21.7) ("20A" 27.2) ("25A" 34) ("32A" 47.7) ("40A" 48.6) ("50A" 60.5) ("65A" 76.3) ("80A" 89.1) ("90A" 101.6) ("100A" 114.3) ("125A" 139.8) ("150A" 165.2) ("175A" 190.7) ("200A" 216.3) ("225A" 241.8) ("250A" 267.4) ("300A" 318.5) ("350A" 355.6) ("400A" 406.4) ) ) (defun isAppox (s d / tol) (setq tol 0.2) ;; I'll take a tolerance of 0.2, to be sure (< (abs (- s d)) tol ) ) (defun size2code (s / res) (setq i 0) (setq res nil) (foreach a conversionData (if (isAppox s (nth 1 a)) (setq res (nth 0 a)) ) ) res ) (defun c:maa ( / ht ov oh ent s code line ip e ang ip2 tmp) ;; settings (setq ht 75.0) ;; Text height of Mtext (setq ov 100.0) (setq oh 24.0) ;; Select DIM and find code (setq ent (car (entsel "\nSelect DIM: "))) (setq s (cdr (assoc 42 (entget ent)))) (setq code (size2code s)) ;; Select line (setq line (car (entsel "\nSelect line: "))) (setq ip (cdr (assoc 10 (entget line)))) (setq e (cdr (assoc 11 (entget line)))) ;; in case start and endpoint are drawn reversed, let's swap them (if (< (nth 0 e) (nth 0 ip)) (progn (setq tmp ip) (setq ip e) (setq e tmp) )) (setq ang (angle ip e)) ;; Insertpoint of the Mtext. We will put it slightly to the right of the i.P. of the line (setq ip2 (polar ip (+ ang (/ pi 2)) ov)) (setq ip2 (polar ip2 ang oh)) ;; draw Mtext (M-Text ip2 code ht ang) (princ) ) 1 Quote Link to comment Share on other sites More sharing options...
Temy Posted February 18, 2020 Author Share Posted February 18, 2020 12 hours ago, Emmanuel Delay said: I think this works (vl-load-com) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; draw Mtext (defun M-Text (pt str ht ang) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 pt) (cons 40 ht) (cons 50 ang) (cons 1 str))) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; correct - extend if needed (setq conversionData '( ("10A" 17.3) ("15A" 21.7) ("20A" 27.2) ("25A" 34) ("32A" 47.7) ("40A" 48.6) ("50A" 60.5) ("65A" 76.3) ("80A" 89.1) ("90A" 101.6) ("100A" 114.3) ("125A" 139.8) ("150A" 165.2) ("175A" 190.7) ("200A" 216.3) ("225A" 241.8) ("250A" 267.4) ("300A" 318.5) ("350A" 355.6) ("400A" 406.4) ) ) (defun isAppox (s d / tol) (setq tol 0.2) ;; I'll take a tolerance of 0.2, to be sure (< (abs (- s d)) tol ) ) (defun size2code (s / res) (setq i 0) (setq res nil) (foreach a conversionData (if (isAppox s (nth 1 a)) (setq res (nth 0 a)) ) ) res ) (defun c:maa ( / ht ov oh ent s code line ip e ang ip2 tmp) ;; settings (setq ht 75.0) ;; Text height of Mtext (setq ov 100.0) (setq oh 24.0) ;; Select DIM and find code (setq ent (car (entsel "\nSelect DIM: "))) (setq s (cdr (assoc 42 (entget ent)))) (setq code (size2code s)) ;; Select line (setq line (car (entsel "\nSelect line: "))) (setq ip (cdr (assoc 10 (entget line)))) (setq e (cdr (assoc 11 (entget line)))) ;; in case start and endpoint are drawn reversed, let's swap them (if (< (nth 0 e) (nth 0 ip)) (progn (setq tmp ip) (setq ip e) (setq e tmp) )) (setq ang (angle ip e)) ;; Insertpoint of the Mtext. We will put it slightly to the right of the i.P. of the line (setq ip2 (polar ip (+ ang (/ pi 2)) ov)) (setq ip2 (polar ip2 ang oh)) ;; draw Mtext (M-Text ip2 code ht ang) (princ) ) It was great, thank you very much! Quote Link to comment Share on other sites More sharing options...
Temy Posted February 18, 2020 Author Share Posted February 18, 2020 (edited) Sorry, I disturbed again! I want the height of the Mtext to be the same as the height of the dimensions, If the height of the dimension changes, the height of Mtext changes accordingly Because my drawings have different size dimstyles. Please help me fix it... Edited February 18, 2020 by Temy Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted February 18, 2020 Share Posted February 18, 2020 Okay, like this. (vl-load-com) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; draw Mtext (defun M-Text (pt str ht ang) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 pt) (cons 40 ht) (cons 50 ang) (cons 1 str))) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; correct - extend if needed (setq conversionData '( ("10A" 17.3) ("15A" 21.7) ("20A" 27.2) ("25A" 34) ("32A" 47.7) ("40A" 48.6) ("50A" 60.5) ("65A" 76.3) ("80A" 89.1) ("90A" 101.6) ("100A" 114.3) ("125A" 139.8) ("150A" 165.2) ("175A" 190.7) ("200A" 216.3) ("225A" 241.8) ("250A" 267.4) ("300A" 318.5) ("350A" 355.6) ("400A" 406.4) ) ) (defun isAppox (s d / tol) (setq tol 0.2) ;; I'll take a tolerance of 0.2, to be sure (< (abs (- s d)) tol ) ) (defun size2code (s / res) (setq i 0) (setq res nil) (foreach a conversionData (if (isAppox s (nth 1 a)) (setq res (nth 0 a)) ) ) res ) (defun c:maa ( / ht ov oh ent nent s code line ip e ang ip2 tmp) ;; settings (setq ht 75.0) ;; Text height of Mtext (setq ov 100.0) (setq oh 24.0) ;; Select DIM, and find code (setq ent (car (entsel "\nSelect DIM: "))) ;; read text height (setq ht (vla-get-TextHeight (vlax-ename->vla-object ent))) (setq ov (/ (* ht 4.0) 3.0)) (setq oh (/ ht 3.0)) (setq s (cdr (assoc 42 (entget ent)))) (setq code (size2code s)) ;; Select line (setq line (car (entsel "\nSelect line: "))) (setq ip (cdr (assoc 10 (entget line)))) (setq e (cdr (assoc 11 (entget line)))) ;; in case start and endpoint are drawn reversed, let's swap them (if (< (nth 0 e) (nth 0 ip)) (progn (setq tmp ip) (setq ip e) (setq e tmp) )) (setq ang (angle ip e)) ;; Insertpoint of the Mtext. We will put it slightly to the right of the i.P. of the line (setq ip2 (polar ip (+ ang (/ pi 2)) ov)) (setq ip2 (polar ip2 ang oh)) ;; draw Mtext (M-Text ip2 code ht ang) (princ) ) 1 Quote Link to comment Share on other sites More sharing options...
Temy Posted February 19, 2020 Author Share Posted February 19, 2020 15 hours ago, Emmanuel Delay said: Okay, like this. (vl-load-com) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; draw Mtext (defun M-Text (pt str ht ang) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 pt) (cons 40 ht) (cons 50 ang) (cons 1 str))) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; correct - extend if needed (setq conversionData '( ("10A" 17.3) ("15A" 21.7) ("20A" 27.2) ("25A" 34) ("32A" 47.7) ("40A" 48.6) ("50A" 60.5) ("65A" 76.3) ("80A" 89.1) ("90A" 101.6) ("100A" 114.3) ("125A" 139.8) ("150A" 165.2) ("175A" 190.7) ("200A" 216.3) ("225A" 241.8) ("250A" 267.4) ("300A" 318.5) ("350A" 355.6) ("400A" 406.4) ) ) (defun isAppox (s d / tol) (setq tol 0.2) ;; I'll take a tolerance of 0.2, to be sure (< (abs (- s d)) tol ) ) (defun size2code (s / res) (setq i 0) (setq res nil) (foreach a conversionData (if (isAppox s (nth 1 a)) (setq res (nth 0 a)) ) ) res ) (defun c:maa ( / ht ov oh ent nent s code line ip e ang ip2 tmp) ;; settings (setq ht 75.0) ;; Text height of Mtext (setq ov 100.0) (setq oh 24.0) ;; Select DIM, and find code (setq ent (car (entsel "\nSelect DIM: "))) ;; read text height (setq ht (vla-get-TextHeight (vlax-ename->vla-object ent))) (setq ov (/ (* ht 4.0) 3.0)) (setq oh (/ ht 3.0)) (setq s (cdr (assoc 42 (entget ent)))) (setq code (size2code s)) ;; Select line (setq line (car (entsel "\nSelect line: "))) (setq ip (cdr (assoc 10 (entget line)))) (setq e (cdr (assoc 11 (entget line)))) ;; in case start and endpoint are drawn reversed, let's swap them (if (< (nth 0 e) (nth 0 ip)) (progn (setq tmp ip) (setq ip e) (setq e tmp) )) (setq ang (angle ip e)) ;; Insertpoint of the Mtext. We will put it slightly to the right of the i.P. of the line (setq ip2 (polar ip (+ ang (/ pi 2)) ov)) (setq ip2 (polar ip2 ang oh)) ;; draw Mtext (M-Text ip2 code ht ang) (princ) ) Thank you for the feedback. I've used your edit, but in my case it didn't work. My Dimstyle is the Annotative object. Please research and fix me again, thank you! 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.