AutoCAD - Text to multiple Mline's

AutoCAD - Text to multiple Mline's

g.dauksaite8AZKZ
Explorer Explorer
930 Views
12 Replies
Message 1 of 13

AutoCAD - Text to multiple Mline's

g.dauksaite8AZKZ
Explorer
Explorer

Hallo,

 

Please help! 

 I have to add MText "HDPE32" as in expalmpe to other multiple green Mlines and to align that text. I could copy/paste and align one by one but there are more then 300 of them. Is there an easier way to add the same text to all of them?

Knipsel.PNG

 

[ The subject line of this post has been edited to include the product name by @handjonathan ]

0 Likes
Accepted solutions (1)
931 Views
12 Replies
Replies (12)
Message 2 of 13

imadHabash
Mentor
Mentor

Hi,

You need here an outsource help .. I suggest to check the following link that may help . >> Click1 <<   

Imad Habash

EESignature

Message 3 of 13

g.dauksaite8AZKZ
Explorer
Explorer

Thank you for your fast answer, but first two options its still manually rotate every single object from 300 of them. Third opsion roatate all of them but to one direction, so not exacly what im looking for. Fourth is a blocks that atoumaticly aligns but still every single peace separately. 6th one is for Civil 3D. Last one, im not sure how to writte a LISP:/

0 Likes
Message 4 of 13

Kent1Cooper
Consultant
Consultant

Are they always and only two-point MLINE objects -- nothing "fancier"?  Are they always all of the same Style and Scale and Justification [thinking about placement of the Text part -- length variations shouldn't matter]?  Are they always on the same Layer, with no other Mlines on that Layer that you don't want Text added to?  In that case the routine could find them all, or would the User select?  Would the User specify [type in] the Text content, or select an already-existing Text object, or would it be determined from some characteristic of each Mline, or ...?

Kent Cooper, AIA
Message 5 of 13

g.dauksaite8AZKZ
Explorer
Explorer

They are "street crossings", so lenght and rotations are different on eacht one, but all are in the same layer als o with text. At first they are just a polylines with labels:

Knipsel.PNG

So covert them to polylines. And then i add text, so at the end they look like this: 

Knipsel.PNG

 

Text is always the same, just rotation is different. Also the same Layer. Yes, green ones are always two point Mlines in the same style but different lenght and rotation. I can easy put text and Mline to separated layers if needed. 

Message 6 of 13

Kent1Cooper
Consultant
Consultant

Not all my questions have been answered yet, but as a quick starting approach:

 

(defun C:TAML ; = Text At MultiLines
  (/ ss txt n ends end1 end2 midpt ang)
  (if (setq ss (ssget "_X" '((0 . "MLINE") (8 . "YourMlineLayer"))))
    (progn
      (setq txt (getstring "\nText content: "))
      (repeat (setq n (sslength ss))
        (setq
          ends (vlax-get (vlax-ename->vla-object (ssname ss (setq n (1- n)))) 'Coordinates)
          end1 (list (car ends) (cadr ends) (caddr ends))
          end2 (cdddr ends)
          midpt (mapcar '/ (mapcar '+ end1 end2) '(2 2 2))
          ang (angle end1 end2)
        )
        (if (and (> ang (/ pi 2)) (<= ang (* pi 1.5))) (setq ang (+ ang pi))); plan-readable direction
        (command "_.text" "_c" ; ["_cen" or "_center" taken as Osnap call]
          (polar midpt (+ ang (/ pi 2)) (getvar 'textsize))
          "" (cvunit ang "radian" "degree") txt
        )
      )
    )
  )
  (princ)
)

 

It does the Text in the current Style, which it assumes is defined without a fixed height, and at the current Text Height, assuming that is an appropriate size, and on the current Layer.  Differences from those can be built in, as answers are provided.  Edit the Layer name to suit.  How well it places Text [center-justified, off the definition-point path of the Mline by the Text height] depends on the style and scale and justification of the Mlines -- if those are always the same, something can be built in.

Kent Cooper, AIA
Message 7 of 13

Sea-Haven
Mentor
Mentor

I remembered that getting info on the mline widths was not straight forward, and basically you have to open the mline dictionary and look at the properties there, so can get the offset values and Top Zero Bottom setting. If the mline is set to Zero ie centre then can just get total width from entget looking at the  dxf 49, (49 . 3.0) (49 . -3.0)

 

This is an example of labelling the width of a mline close to what is being asked for.

 

 

 

; dimension mline width 
; By Alanh Oct 2021

(defun c:mldima ( / olsnap dic obj xyz mlsty mlsc pt1 pt2 ang mp mp2 ent dic dict tot n)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)

(setq dic (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))

(setq dpss (ssget  '((0 . "MLINE"))))

(if (= dpss nil)
(alert "There are no mlines" )
(progn
(setvar 'blipmode 0)
(repeat (setq n (sslength dpss)) ; step through selection set
(setq obj (vlax-ename->vla-object (ssname dpss (setq n (1- n)))))
(setq xyz (vlax-get obj 'Coordinates))
(setq mlsty (vlax-get obj 'StyleName))
(setq mlsc (vlax-get obj 'MLineScale))

(setq pt1 (list (nth 0 xyz)(nth 1 xyz)))
(setq pt2 (list (nth 3 xyz)(nth 4 xyz)))
(setq ang (- (angle pt1 pt2)(/ pi 2.0)))
(setq mp (mapcar '* (mapcar '+ pt1 pt2) '(0.5 0.5)))

(setq dict (dictsearch (cdr (assoc -1 dic)) mlsty ))
(setq tot 0.0)
(foreach ent dict 
(if (= (car ent) 49)
(setq tot (+ tot (abs (cdr ent))))
)
)
(setq tot (* mlsc tot))

(setq mp2 (polar mp ang tot))

(command "dimaligned" mp mp2 mp)
)
)
)

(setvar 'osmode oldsnap)

(princ)
)
(c:mldima)

 

 

0 Likes
Message 8 of 13

g.dauksaite8AZKZ
Explorer
Explorer

Im sorry Im not very advanced in it. I try to answer rest of questions:

This is text Information:

Knipsel.PNG

 

Mlines are always the same width just length may vary. But length variations doesn''t matter for the text. Text stay always the same size as shown above. 

0 Likes
Message 9 of 13

g.dauksaite8AZKZ
Explorer
Explorer

And this is the information about Mlines. They are 1m width.

Knipsel.PNG

0 Likes
Message 10 of 13

g.dauksaite8AZKZ
Explorer
Explorer

Hey, I tried code:

Knipsel.PNG

it recognize Mlines beautifully and add text to all of it. But is it possible to add text height to 1.25m and distance 1m from Mlines?

0 Likes
Message 11 of 13

Kent1Cooper
Consultant
Consultant

And is your DRILLING MultiLine Style defined something like this in the MLSTYLE dialog box?

Kent1Cooper_0-1663760174812.png

Specifically, are the Offsets plus & minus 0.5, so that we can count on the scale assigned to a give Mline to be the actual spacing between its edges, and the edges centered around the virtual line between defined endpoints?

Kent Cooper, AIA
0 Likes
Message 12 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

If the answer to my previous question is yes, and if the current Text Style will always be without a fixed height, and if a meter is your drawing unit, then:

 

(defun C:TAML ; = Text At MultiLines
  (/ ss txt n ends end1 end2 midpt ang)
  (if (setq ss (ssget "_X" '((0 . "MLINE") (8 . "YourMlineLayer"))))
    (progn
      (setq txt (getstring "\nText content: "))
      (repeat (setq n (sslength ss))
        (setq
          mlobj (vlax-ename->vla-object (ssname ss (setq n (1- n))))
          ends (vlax-get mlobj 'Coordinates)
          end1 (list (car ends) (cadr ends) (caddr ends))
          end2 (cdddr ends)
          midpt (mapcar '/ (mapcar '+ end1 end2) '(2 2 2))
          ang (angle end1 end2)
        )
        (if (and (> ang (/ pi 2)) (<= ang (* pi 1.5))) (setq ang (+ ang pi))); plan-readable direction
        (command "_.text" "_c" ; ["_cen" or "_center" taken as Osnap call]
          (polar midpt (+ ang (/ pi 2)) (1+ (/ (vlax-get mlobj 'MlineScale) 2)))
          1.25 (cvunit ang "radian" "degree") txt
        )
      )
    )
  )
  (princ)
)

 

Kent1Cooper_0-1663760647310.png

 

Kent Cooper, AIA
Message 13 of 13

g.dauksaite8AZKZ
Explorer
Explorer

Stunning! You are magician! Thank you very much

0 Likes