Add QTOMaterialListCollection to SampleLineGroup

If anyone interested, I figured it out. The QTOMaterialListCollection of a sample line group can be accessed through the SampleLineGroup.MaterialLists property.
Tha hard part in this is the incomplete reference guide as the QTOMaterialListCollection.ImportCriteria Method only containing 1 parameter there while in reality it asks for 2 arguments. So with trial and error I found out that the first one is the QTOMaterialListCollection and the second is the QTOCriteriaNameMapping.
https://help.autodesk.com/view/CIV3D/2023/ENU/?guid=ae4b8042-5163-ad30-d4f4-088a211d14b4

Here’s the test code, note that there is no error handling, and it is for testing rn, so cannot handle multiple corridors yet. Also the inputs are created with camber and ArkanceSystems nodes

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

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

def createmateriallist(QTOC,SLGl,CORR,shapes):

#QTOC - QTOCriteria created from all the shapes from one corridor (Camber, ArkanceSystems Corridorshapes)
#SLGl - sample line group list
#CORR - selected corridor
#shapes - list of shapes in that corridor, QTOCriteria made from that

	global adoc
	
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
				#get input QTOCriteria object id
				QTOCid = QTOC.InternalObjectId;
				#QTOCo = t.GetObject(id, OpenMode.ForWrite, True);
				for slg in SLGl:
					#get sample line group object id
					slgid = slg.InternalObjectId;
					#open sample line group object
					slgo = t.GetObject(slgid, OpenMode.ForWrite, True);
					#create criteria name mapping for sample line group from QTOCriteria 
					QTOM = QTOCriteriaNameMapping(QTOCid,slgid);
					#sampled input corridor id
					CORRid = CORR.InternalObjectId
					for shape in shapes:
						#map every shape from input to every shape in criteria (error if not all the same, not solved in code yet)
						shapemapping = QTOM.MapCorridorShape(shape,shape,CORRid,shape)
						#TRUE if all shape code mapped
						completed = QTOM.isMappingCompleted
				#add created mapping to sample line group aka compute materials
				importcriteriatoslg = QTOMaterialListCollection.ImportCriteria(slgid.MaterialLists,QTOM)
				t.Commit()
				return completed

# Assign your output to the OUT variable.
OUT = createmateriallist(IN[0],IN[1],IN[2],IN[3])

I hope someone find this helpful.

5 Likes