How to rotate Mtext based on alignment of MLine ?

How to rotate Mtext based on alignment of MLine ?

pramodrajpandit123
Contributor Contributor
728 Views
2 Replies
Message 1 of 3

How to rotate Mtext based on alignment of MLine ?

pramodrajpandit123
Contributor
Contributor

I wanted to rotate MText ( which is at the middle of MLine drawn ) according to the alignment of MLine drawn on Modelspace.

Cases:

i)If Mline is Horizontal the MText should be horizontal.

ii)If Mline is Vertical the MText should be vertical.

iii)If Mline is Diagonal the MText should be diagonal ie according to alignment of MLine.

 

I have used Tan(θ)=Perpendicular/Base to get the angle at which the MLine is drawn on Modelspace but the alignment of MText does not match the alignment of MLine.

P.S: I have solved for Case I and Case II using If-Else but for Case III: Diagonal, I could not figure out a way to solve it.

Capture.JPG

 

 

 

        Start = acadDoc.Utility.GetPoint(, "Start point :")
        Finish = acadDoc.Utility.GetPoint(Start, "End point :")
        
        point(0) = Start(0)
        point(1) = Start(1)
        point(2) = Start(2)
        point(3) = Finish(0)
        point(4) = Finish(1)
        point(5) = Finish(2)
        Set MLine = acadDoc.ModelSpace.AddMLine(point)

            Inspoint(0) = (point(0) + point(3)) / 2
            Inspoint(1) = (point(1) + point(4)) / 2
            TextString = "I am at Mid-Point"
            Set MTextObj = acadDoc.ModelSpace.AddMText(Inspoint, 0, TextString)
            MTextObj.Rotation = Atn((point(4) - point(1)) / (point(0) - point(3)))-90 * 0.0174532925

 

 

0 Likes
Accepted solutions (1)
729 Views
2 Replies
Replies (2)
Message 2 of 3

Ray-Sync
Advocate
Advocate
Accepted solution

@pramodrajpandit123 , this is the solution.

RaySync_0-1684450425282.pngRaySync_1-1684450442592.png

 

jefferson
Message 3 of 3

pramodrajpandit123
Contributor
Contributor

Almost gave up on the solution ! Thank you CAD-Sensei 🙂

 One more thing: If i have to shift the MText above the Mline then how to achieve it using the same code above ?Capture.JPG