[New Feature Preview] Python 3 Support Issue Thread

Here is what I came up with, but I would think there is a better way. Since I was unable to get the object id by name directly like I could with IronPython or C#, I needed to loop through the collection and query each objects name. Unfortunately, there is still a lot from the Civil 3D COM API that is not yet in the .NET API. Getting style names is one of those. Thank you to @c.poupin for the tip on using reflection.
This is definitely more difficult than IronPython.

import clr

# Add Assemblies for AutoCAD and Civil 3D APIs
clr.AddReference('acdbmgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('System.Reflection')

from System.Reflection import BindingFlags

# Import references from AutoCAD
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *

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

adoc = Application.DocumentManager.MdiActiveDocument
civdoc = CivilApplication.ActiveDocument

styleId = None

with adoc.LockDocument():
	with adoc.Database as db:
		with db.TransactionManager.StartTransaction() as t:
			styleCol = civdoc.Styles.AlignmentStyles

			for i in styleCol:
				styleObj = t.GetObject(i, OpenMode.ForRead)
				comObj = styleObj.AcadObject
				if comObj.GetType().InvokeMember("Name", BindingFlags.GetProperty, None, comObj, None) == "Basic":
				    styleId = i
				    break

OUT = styleId
1 Like