Getting surface information from C3D using Python

Hello,

I’m trying to get surface information using a Python node,

I’m used to libraries information like this one that seems very different than this one

And I don’t manage to find any API reference guide for Autocad.

So far I manage to do this copying some code from @Paolo_Emilio_Serra1 and following this:
https://forum.dynamobim.com/t/new-to-dynamo-and-python-manipulating-general-properties/43220/2?u=jduran

import clr

# Add Assemblies for AutoCAD and Civil 3D APIs
clr.AddReference('acmgd')
clr.AddReference('acdbmgd')
clr.AddReference('accoremgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('System.Windows.Forms')
clr.AddReference('ProtoGeometry')

# Import references from AutoCAD

# Import references for Civil 3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
from Autodesk.Civil import FeatureLinePointType

# Create an alias to the Autodesk.AutoCAD.ApplicationServices.Application class
import Autodesk.AutoCAD.ApplicationServices.Application as acapp

doc = CivilApplication.ActiveDocument
Surfaces = []
for surfaceId  in doc.GetSurfaceIds:
	Surfaces.append(surface.Name)


OUT = Surfaces

But so far i have been just guessing without realizing which libraries should I import or assemblies to add and the results that I got is not a string,integer or any variable that I can use, all I get is IronPython.Runtime.Types.BuiltinFunction

Thanks,

image

the Assembly is what you add via clr.AddReference()
the Namespace is what you write at the import statement

They are already loaded in the Python template for your convenience.
If you want to know how a function works, call the name of function and use the _ _ doc_ _

property to get the Documentation String associated.
If you want to know which members are associated to an object call the dir() on the object.

here is a one line of code that looks at all the members of a Surface object

4 Likes

Thanks Paolo,
I finally did run the script without crashes or errors, felling like a total noob here

Changing the last line for:

OUT = [(m, getattr(VolumeSurfaceProperties, m).__doc__) for m in dir(VolumeSurfaceProperties)]

Manage to get the documentation of VolumeSurfaceProperties which have:
Namespace: Autodesk.Civil.DatabaseServices
Assembly: AeccDbMgd (in AeccDbMgd.dll) Version: 10.5.768.0

Moving foward I’m trying to get the Fill volume using this line:

OUT = VolumeSurfaceProperties.UnadjustedFillVolume()

I get an error

IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 42, in
TypeError: getset_descriptor is not callable

I guess I need to specify the the surface I want to get the volume from, but I’m stuck there now.

not callable means that you are dealing with a property, not a method, basically you need to remove the parenthesis.

1 Like

Thanks Again Paolo, I get rid of the error, but the result I get is “IronPytho.Runtime.Types.ReflectedProperty” I was expecting a float/double value accordint to this: http://docs.autodesk.com/CIV3D/2018/ENU/API_Reference_Guide/html/2194df7b-8d94-0be7-f2eb-9c5b7830dd78.htm

Because you are calling the property on the class VolumeSurfaceProperties (the definition of the object) and not on an actual instance of that object.

4 Likes

Thanks Paolo! That Code is just what I need to understand how surfaces and others C3D object work with python.

I tink the params are commented backwards first surface will be base surface (bottom) second will be comparison (top) ¿rigth?

I do have another question regarding to the volumes units on the output. The drawing ambient setting are set on Cubic Yards, but the API output is on Cubic foot. Is this the default units output? Even if the drawing is set on metric?

Thanks again!