Create a 3d Section in Civil 3d

Hello everyone,
I am trying to create a Section in the 3D Modeling module with python and AutoCAD API, but when I instance the section, the script throws the following error:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 44, in
TypeError: Cannot create instances of Section because it has no public constructorst

I share the script below and the information of the AutoCAD API that I am using, if anyone can help me, I will appreciate it.
Thank you
API information:

C#
public Section(Point3dCollection pts, Vector3d verticalDir);

https://help.autodesk.com/view/OARX/2021/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_DatabaseServices_Section_Section_Point3dCollection_Vector3d

# 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.

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


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

        with db.TransactionManager.StartTransaction() as t:
			#Open BlockTable for read
			block_table = t.GetObject(db.BlockTableId,OpenMode.ForRead)
			
			
			#Open BlockTable for write
			block_table_recod = t.GetObject(block_table[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
			
			
			#Create a section Object
			with Section(Point3d(5, 5, 0), Point3d(12, 3, 0), Vector3d(0, 0, 1)) as section_object:
				block_table_recod.AppendEntity(section_object)
				t.AddNewlyCreatedDBObject(section_object, True)
			t.Commit()
			pass
OUT = 0

Section.dyn (3.7 KB)

Hi @luis.colina5BTB8,

I think the warning message is a little bit misleading because the section class does indeed have public constructors. What it should say is that there is no public constructor that matches the inputs you are providing. You need to create a Point3dCollection object that contains the points that you want, which is not the same as supplying multiple individual Point3d objects.

I think I’ve had this issue as well. I assumed a “Point3dCollection object” is just a list of “Point3d objects”. So this is not the case? How do we create a “Point3dCollection object” if we cannot declare a type in python?

1 Like
points = Point3dCollection()
points.Add(Point3d(0,0,0))
points.Add(Point3d(1,1,1))

Not sure what you mean by this, can you explain?

2 Likes

Sorry I’m probably just confusing us both. You answered my question perfectly. We can create an empty Point3dCollection object and then use the “.Add” method on it to add points. Now I know why when I tried to use “surfaceObject”.AddVerticies(“listOfPoint3ds”) it crashed. :slight_smile:

Thank you very much @mzjensen, I’ll keep it in mind for future queries to API
:sunglasses:

1 Like