How can i create Multiple Section View Using Civil 3D Dynamo Python Script?

Hi,

There are some nodes in Camber, Arkance and C3DToolkit packages, but I don’t know their limitations.
Last year I tested section view group creation, but I did not get it to production, so use it with caution.
It should create section view group for every input sample line groups.
It is also made for specific template, so you have to modify style names in the code. As I said it is not complete, not well tested, so bugs may occur, i.e. source selection. (see video)
That said here is the script, you can start your own using this:

# 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

#sample line groups
SLGS = IN[0]
#insertion point
P = IN[1]
#station range, 0 if from start to end
SSin = IN[2]
ESin = IN[3]
#placement type 0 if draft, anything else if production
placement = IN[4]
templatepath = IN[5]
layoutname = IN[6]

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
civdoc = CivilApplication.ActiveDocument

with adoc.LockDocument():
   with adoc.Database as db:

       with db.TransactionManager.StartTransaction() as t:
           # Place your code below
           #Insertion point from input
           P1 = Point3d(P.X, P.Y, P.Z)
           #get sample line groups in for loop
           for SLG in SLGS:
               #open SLGs
   			SLGId = SLG.InternalObjectId
   			SLGOb = SLGId.GetObject(OpenMode.ForWrite)
   			#THIS SECTION ADDS EVERY SURFACE AND CORRIDOR AS SOURCE
   			SLGS = SLGOb.GetSectionSources()
   			for source in SLGS:
   				st = source.SourceType
   				if str(st) == "TinSurface":
   					source.IsSampled = False
   					source.IsSampled = True
   					source.StyleId = civdoc.Styles.SectionStyles["UNI_terep"]
   				if str(st) == "Corridor":
   					source.IsSampled = False
   					source.IsSampled = True
   					source.StyleId = civdoc.Styles.CodeSetStyles["UNI_Keresztszelvény_1:100"]
   				else:
   					pass
   				#get EG source idq
   				sn = source.SourceName
   				if str(sn) == "Meglévő terep":
   					EGId = source.SourceId
   			#open parentalignment
   			PA = SLGOb.ParentAlignmentId.GetObject(OpenMode.ForRead)
   			#get station range from alignment or from input
   			if SSin == 0:
   				SS = PA.StartingStation
   			else:
   				SS = SSin
   			if ESin == 0:
   				ES = PA.EndingStation
   			else:
   				ES = ESin
   			
   			rangeOptions = SectionViewGroupCreationRangeOptions(SLGId)
   			
   			placementOptions = SectionViewGroupCreationPlacementOptions()
   			
   			#set placement type
   			if placement == 0:
   				placementOptions.UseDraftPlacement()
   			else:
   				placementOptions.UseProductionPlacement(templatepath,layoutname)
   				
   			sectiondisplayOptions = SectionDisplayOptionCollection(SLGId)
   			for option in sectiondisplayOptions:
   				option.Draw = True
   			
   			#sectiondisplayOptions[0].UseOverrideStyle = True;
   			#sectiondisplayOptions[0].OverrideStyleId = civdoc.Styles.CodeSetStyles["UNI_Keresztszelvény_Kiviteli"];
   			
   			#set section view style
   			sectionViewStyleId = civdoc.Styles.SectionViewStyles["UNI_ksz rajz"]
   			#set band set
   			sectionViewBandSetStyleId = civdoc.Styles.SectionViewBandSetStyles["UNI_Lábléckészlet"]
   			#create
   			SVGC = SLGOb.SectionViewGroups
   			SVGS = SVGC.Add(P1,SS,ES,rangeOptions,placementOptions,sectiondisplayOptions,sectionViewStyleId,sectionViewBandSetStyleId)
   			SVGS.PlotStyleId = civdoc.Styles.GroupPlotStyles["UNI_ksz_csoportnyomtatás_420"]
   			SVIds = SVGS.GetSectionViewIds()
   			for SVId in SVIds:
   				SV = SVId.GetObject(OpenMode.ForWrite)
   				SL = SV.SampleLineId.GetObject(OpenMode.ForWrite)
   				EGsectionid = SL.GetSectionId(EGId)
   				bottombanditems = SV.Bands.GetBottomBandItems()
   				for bottombanditem in bottombanditems:
   					#if bottombanditem.BandStyleId == civdoc.Styles.BandStylesRoot.SectionViewSectionDataBandStyles["UNI_ksz_terep magasság"]:
   					bottombanditem.Section1Id = EGsectionid
   				SV.Bands.SetBottomBandItems(bottombanditems)
   					#else:
   						#pass
   			
   			P1 = Point3d(P1.X,P1.Y-70,P1.Z)
   			
   			sectiondisplayOptions.Dispose()

           # Commit before end transaction
           t.Commit()
           pass

# Assign your output to the OUT variable.
OUT = bottombanditems

1 Like