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

Hi! I recently started to learn and use Dynamo in my workflows and I’m impressed with it. One of my current task is to add a couple of surfaces as sample sources to some Section Groups and I thought Dynamo could help me.

I found the popular and helpful Civil3DToolkit but also I couldn’t find some node to do the job. I searched in Sections, Corridors, Basselines, SectionViews but… nothing. So, as this topic says, is there someway to add sample sources using Dynamo? Maybe I’m looking for nothing mplemented yet (⌒_⌒;)

Note: I’m asking mainly for nodes but I know basic Python so a custom code solution would be welcome too.

Thanks.

Hi @MichaelMX,

Welcome to the Forum. You can do it using the .net API and the python script node.
You can use this code as a starting point:

# 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[2]
				#Add the source item above
				#source.IsSampled = True
				#Add all sources
				for source in slgs:
					source.IsSampled = True
				# Commit before end transaction
				t.Commit()

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



Add SLsource.dyn (5.5 KB)

2 Likes

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)

3 Likes

Thanks, I’ll try it and study that API you mention above. Sorry for taking too long to mark your answer as correct.

Hi. I’m trying to add sources (surfaces and corridor) to sample lines. It seems that your Python code can do that but I don’t have so much Python knowledge to understand it. Can you give reference to how to use that? Or do you know a better way to add sources? I hope you can help me. Thanks you so much.