# Change MText elevation

**URL:** <https://forum.dynamobim.com/t/change-mtext-elevation/94696>\
**Category:** Civil 3D\
**Created:** [October 18, 2023, 7:44pm UTC](https://forum.dynamobim.com/t/change-mtext-elevation/94696 "2023-10-18T19:44:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![raul.07.11](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@raul.07.11](https://forum.dynamobim.com/u/raul.07.11)\
**Post date:** [October 18, 2023, 7:44pm UTC](https://forum.dynamobim.com/t/change-mtext-elevation/94696/1 "2023-10-18T19:44:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hosneyalaa](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/hosneyalaa/32/100865_2.png) [@hosneyalaa](https://forum.dynamobim.com/u/hosneyalaa)\
**Post date:** [October 18, 2023, 8:19pm UTC](https://forum.dynamobim.com/t/change-mtext-elevation/94696/2 "2023-10-18T20:19:58Z")

</div>

Can you attached example drawing

---

<div class="post-metadata">

**Author:** ![raul.07.11](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@raul.07.11](https://forum.dynamobim.com/u/raul.07.11)\
**Post date:** [October 18, 2023, 8:25pm UTC](https://forum.dynamobim.com/t/change-mtext-elevation/94696/3 "2023-10-18T20:25:14Z")

</div>

Sure.  
[PRUEBA\_ALINEAMIENTO\_INICIO.dwg](https://forum.dynamobim.com/uploads/short-url/6Wymdra9TgqGwAkLHxNh2zUYVVM.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](https://forum.dynamobim.com/uploads/short-url/kebz67Gw3mbepHu3fLu2rOOgQ9a.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.

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [October 19, 2023, 12:19am UTC](https://forum.dynamobim.com/t/change-mtext-elevation/94696/4 "2023-10-19T00:19:00Z")

</div>

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.

```python
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

 ![labelsConElevacion_2023-10-19_07-58-15](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/a/7a73bb5a27216933f35ca8671f2235997ebfa9d2.png)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/9/c9ec22e1d4812ab2329dfc137415ec8f5c6a68cb.png)

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [October 19, 2023, 5:54am UTC](https://forum.dynamobim.com/t/change-mtext-elevation/94696/5 "2023-10-19T05:54:18Z")

</div>

> [@Mike.Buttery](#):
>
> Splitting on the semi-colon is going to be more consistent

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/9/f991fa4821384d3e3889aa2ca16b20ea56b7f4bb.png)

---

<div class="post-metadata">

**Author:** ![raul.07.11](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@raul.07.11](https://forum.dynamobim.com/u/raul.07.11)\
**Post date:** [October 19, 2023, 4:35pm UTC](https://forum.dynamobim.com/t/change-mtext-elevation/94696/6 "2023-10-19T16:35:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [October 20, 2023, 2:38am UTC](https://forum.dynamobim.com/t/change-mtext-elevation/94696/7 "2023-10-20T02:38:53Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![raul.07.11](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@raul.07.11](https://forum.dynamobim.com/u/raul.07.11)\
**Post date:** [October 21, 2023, 9:07pm UTC](https://forum.dynamobim.com/t/change-mtext-elevation/94696/8 "2023-10-21T21:07:57Z")

</div>

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.
