FindElevationAtXY method doesn't work

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 (926.6 KB)
oldaleses_v00.dyn (11.5 KB)

Hi
Can you put your code here instead of Dyn file

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

# 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

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] ])

1 Like

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:

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

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

1 Like

1 Like

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