Jump to content

Assign DIMENSION values to MTEXT


Temy

Recommended Posts

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

  • Like 1
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

help1.JPG

Edited by Temy
Link to comment
Share on other sites

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

  • Thanks 1
Link to comment
Share on other sites

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!

Example-02.JPG

Example-01.JPG

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