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.
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)
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)
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.
Hi @kovacsv,
I have problems to use your example Python code. I have Civil 3D 2023. There is error and Civil 3D shuts down. Have you tested this on 2023 version with Python3?
I made this almost 2 years ago, I’m sure it was made in IronPyton 2.7. Try running it with 2.7 maybe it drops an error message. We used another version of this with corridors a few months ago, we did not experience crashes.