Change MText elevation

Hi everyone. I’m tryign to change the elevation of multiple MText. The use of that is to assign the elevation in a profile at a specific station to the MText thant contains the station.
I currently have the list of MText and the list of elevations but I can’t find a node to change the elevation. I hope you can help me. Thanks.

Can you attached example drawing

Sure.
PRUEBA_ALINEAMIENTO_INICIO.dwg (1.4 MB)
In that dwg there is an alignment (that contains a profile) and multiple MTexts. Each MText contains an elevation.
labelsConElevacion.dyn (27.8 KB)
That dyn does this:

  1. Gets all the MTexts, reads the contents and converts those string to numbers.
  2. Selects a profile from an alignment and get the elevation in the profile at the stations in the MTexts.
    What I need now is to assign those elevation to the MTexts. Thanks for your response. I will be eager to respond to anything else. Thanks again.

The Z position of a MText object is set with a Point3d as the Location property.
Between Dynamo and AutoCAD the Point3d object is not handled well so a bit of python helps.

import clr
clr.AddReference('AcDbMgd')
from Autodesk.AutoCAD.Geometry import Point3d
OUT = [Point3d(p.X, p.Y, IN[1][i]) for i, p in enumerate(IN[0])]

(I’ve also cleaned up the text to number parsing) EDIT Splitting on the semi-colon is going to be more consistent


image

3 Likes

1 Like

I didn’t know that you control the position of a MText with Location. Thank you so much.
The Python code works. Can I ask you to explain this part:
OUT = [Point3d(p.X, p.Y, IN[1][i]) for i, p in enumerate(IN[0])]
Thanks again for your response.

Hi Raul,
What the code is doing is taking two lists, IN[0] list of Point3ds, and IN[1] list of elevations and building a list of new points. As standard code it might look like this

points = []
for i, p in enumerate(IN[0]):
    point = Point3d(p.X, p.Y, IN[1][i])
    points.append(point)

enumerate(IN[0]) gets each item in a list and prepends the index number as a tuple i.e. (i, Point3d). We can unpack this to variables with i, p so we can match the item in the second list IN[1][i] using the index and at the same time get the X and Y values of the point.

2 Likes

Thank you so much for the explanation. I really need to get to learn C3D API and use it in Python. It helps so much with so many things. Thanks again.

1 Like