# FindElevationAtXY method doesn't work

**URL:** <https://forum.dynamobim.com/t/findelevationatxy-method-doesnt-work/87437>\
**Category:** Civil 3D\
**Tags:** python, dynamo\
**Created:** [March 16, 2023, 1:43pm UTC](https://forum.dynamobim.com/t/findelevationatxy-method-doesnt-work/87437 "2023-03-16T13:43:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![denes.nagy](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@denes.nagy](https://forum.dynamobim.com/u/denes.nagy)\
**Post date:** [March 16, 2023, 1:43pm UTC](https://forum.dynamobim.com/t/findelevationatxy-method-doesnt-work/87437/1 "2023-03-16T13:43:58Z")

</div>

Hello,  
I’ve tried to write a python script, which inputs are an alignment, an offset value and a surface. I wanted to generate a nested list, that includes X, Y coordinates along the alignment (left side, center, right side), and the elevation from the surface in these spots. I don’t know why, but it doesn’t work. I checked the python syntax in an independent editor and it works well there.  
Please, give me a suggestion, what I should do to fix it.  
[test.dwg](https://forum.dynamobim.com/uploads/short-url/y7UUcfSlxDE389yp72i5g7NTQK1.dwg) (926.6 KB)  
[oldaleses\_v00.dyn](https://forum.dynamobim.com/uploads/short-url/1FsiG0cpz21f1aZcjoUNo4FpwZY.dyn) (11.5 KB)

---

<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:** [March 16, 2023, 2:04pm UTC](https://forum.dynamobim.com/t/findelevationatxy-method-doesnt-work/87437/2 "2023-03-16T14:04:11Z")

</div>

Hi  
Can you put your code here instead of Dyn file

---

<div class="post-metadata">

**Author:** ![denes.nagy](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@denes.nagy](https://forum.dynamobim.com/u/denes.nagy)\
**Post date:** [March 16, 2023, 7:45pm UTC](https://forum.dynamobim.com/t/findelevationatxy-method-doesnt-work/87437/3 "2023-03-16T19:45:52Z")

</div>

Sure!  
The three inputs are: A - alignment, O - offset value, S - surface

```auto
# Load the Python Standard and DesignScript Libraries
import sys
import clr

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# The inputs to this node will be stored as a list in the IN variables.
A = IN[0]
O = IN[1]
S = IN[2]

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

with adoc.LockDocument():
    with adoc.Database as db:

        with db.TransactionManager.StartTransaction() as t:
            
            # starting station
            SS = A.InternalDBObject.StartingStation
            # ending station
            ES = A.InternalDBObject.EndingStation
            
            # sequence from starting station to ending station, incrementing by 1
            r = range(int(SS),int(ES))
            
            # generating a nested list from X, Y coordinates along the alignment
            CenterXY = []
            for i in r:
                CenterXY.append(A.InternalDBObject.PointLocation(i,0,0,0))
            
            # generating a nested list from X, Y coordinates along the left side of the alignment
            LeftXY = []
            for i in r:
                LeftXY.append(A.InternalDBObject.PointLocation(i,-O,0,0))
            
            # generating a nested list from X, Y coordinates along the right side of the alignment
            RightXY = []
            for i in r:
                RightXY.append(A.InternalDBObject.PointLocation(i,O,0,0))
            
            # generating a new nested list from CenterXY, eliminating the 1st (None) element from each sublist
            CenterXYZ = []
            for i in CenterXY:
                CenterXYZ.append(i[1:])
            
            # adding the surface elevation of each X, Y spot to the actual sublist
            for i, j in enumerate(CenterXY):
                CenterXYZ[i].append(S.InternalDBObject.FindElevationAtXY(j[1],j[2])
            
            #Elevation = S.InternalDBObject.FindElevationAtXY(CenterXY[0][1],CenterXY[0][2])
            
            t.Commit()
            pass

# Assign your output to the OUT variable.
OUT = CenterXYZ

```

---

<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:** [March 16, 2023, 8:23pm UTC](https://forum.dynamobim.com/t/findelevationatxy-method-doesnt-work/87437/4 "2023-03-16T20:23:46Z")

</div>

I’m not sure because of Change the repeat pattern try

```
        for i in CenterXY:
            CenterXYZ.append(S.InternalDBObject.FindElevationAtXY(i[0],i[1])

```

Or

for i in CenterXY:  
CenterXYZ.append([i[0],i[1], S.InternalDBObject.FindElevationAtXY(i[0],i[1] ])

---

<div class="post-metadata">

**Author:** ![denes.nagy](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@denes.nagy](https://forum.dynamobim.com/u/denes.nagy)\
**Post date:** [March 17, 2023, 6:51am UTC](https://forum.dynamobim.com/t/findelevationatxy-method-doesnt-work/87437/5 "2023-03-17T06:51:58Z")

</div>

Thanks, but I think that these wouldn’t do what I want.

The first one should place the elevation at the end of the CenterXYZ list, but it has sublists and I need to put the actual elevation into the ent of each sublist.

I don’t understand the purpose of the second one, and there is something wrong with the brackets.

Anyway both of them gave back warning. The first one’s arning is the same as my original:

```auto
Warning: CPythonEvaluator.EvaluatePythonScript operation failed. 
SyntaxError : ('invalid syntax', ('<string>', 71, 13, ' t.Commit()\n'))

```

---

<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:** [March 17, 2023, 11:15am UTC](https://forum.dynamobim.com/t/findelevationatxy-method-doesnt-work/87437/6 "2023-03-17T11:15:44Z")

</div>

No problem, Friday is a day off

in your code there is a shortage )  
FindElevationAtXY(i[0],i[1]) )

Tomorrow I will try it  
I expect If you do a search within the forum Find an example

---

<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:** [March 18, 2023, 5:17am UTC](https://forum.dynamobim.com/t/findelevationatxy-method-doesnt-work/87437/7 "2023-03-18T05:17:33Z")

</div>

![3](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/1/c165f538e8bb8bc6b71ebbdbbff398a526974c8d.jpeg)

---

<div class="post-metadata">

**Author:** ![denes.nagy](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@denes.nagy](https://forum.dynamobim.com/u/denes.nagy)\
**Post date:** [March 21, 2023, 1:41pm UTC](https://forum.dynamobim.com/t/findelevationatxy-method-doesnt-work/87437/8 "2023-03-21T13:41:39Z")

</div>

Thanks for all efforts, I managed to move forward by an other way 🙂
