Civil 3D - Toolkit - Get subassembly .NET class and assembly name

@Brendan_Cassidy your answer about DLL Hell is spot-on, but it’s not quite applicable in this context. Civil 3D Assemblies and Subassemblies are essentially cross section elements that are the building blocks for creating corridor models.

Subassemblies are defined by a DLL, so the terminology gets confusing because a Subassembly has a corresponding .NET assembly that is used to generate it’s geometry and behavior.

Anyway, @JPS here’s a quick Python snip. The data you’re looking for is stored in the Subassembly’s GeometryGenerator class.

import clr

clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')

from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *

from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

def get_subassembly_info(subassembly):

	if not subassembly:
		return
	
	adoc = Application.DocumentManager.MdiActiveDocument
	output = []
	
	with adoc.LockDocument():
	    with adoc.Database as db:
	        with db.TransactionManager.StartTransaction() as t:
	            oid = subassembly.InternalObjectId
	            aeccSubassembly = t.GetObject(oid, OpenMode.ForRead)
	            aeccGenerator = aeccSubassembly.GeometryGenerator
	            output.append(aeccGenerator.MacroOrClassName)
	            output.append(aeccGenerator.ProjectOrAssemblyName)
	            t.Commit()
	            pass
	return output

OUT = get_subassembly_info(IN[0])
2 Likes