Some way to add sample sources with Dynamo in Civil 3D?

Sorry, I missed the part that you wanted to add surfaces.

# 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.
dataEnteringNode = IN

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

sampleline = IN[0]

def addsource(sampleline):

	with adoc.LockDocument():
	    with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
	        	#Get sample line ID
				slId = sampleline.InternalObjectId
				#Get sample line group ID
				slgroupId = slId.GroupId
				#Open SLGroup
				slg = t.GetObject(slgroupId, OpenMode.ForWrite)
				#Get sources
				slgs = slg.GetSectionSources()
				#Get source item
				source = slgs.Item[0]
				#Add the source item above
				#source.IsSampled = True
				#Add all sources
				for source in slgs:
					st = source.SourceType
					if str(st) == "TinSurface":
						source.IsSampled = True
					else:
						pass
				# Commit before end transaction
				t.Commit()

	return st
# Assign your output to the OUT variable.
OUT = addsource(sampleline)

Add SLsource.dyn (5.6 KB)

4 Likes