Add QTOMaterialListCollection to SampleLineGroup

Hi,

is there any way to create the QTOMaterialListCollection of a SampleLineGroup via .NET API? Or it has to be done through dialog box manually?

I’d like to create material lists for all corridors/slg’s in a drawing. I managed to get all the used shapecodes, create QTOCriteria from them with Camber, and in the API reference guide I see that the Mapping also can be done.
I only miss the step to associate a MaterialListCollection to a SampleLineGroup.

Thanks.

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

Thanks
can you share with us picture
showing inputs and outputs

Sure. Also question for @mzjensen
If I run the script from Dynamo the QTOCriteria.Clear node only works on the first run thus the script is a bit messy. I added passtrough, but it didn’t help, I have to exit and reopen the script or freeze that part. Is it a binding issue or something with the node? I haven’t tried it in Player yet.

2 Likes

After searching this for months, after figuring this out, I just found this on the customization forum…:
image
It can also be called this way… so the reference guide is correct, it is just not that self-explanatory for noobs like me :smiley:

1 Like

It’s probably just because the node has already run and Dynamo has cached a result, so the node isn’t marked as “dirty” anymore. I think it would work to just disconnect/reconnect one of the upstream nodes to force a rerun. Running in Player should work too.

2 Likes

In which package can i find the node “corridor.shapecodes”. Ive downloaded camber package