Hi, It’s a nice day
I’m making a dynamo logic about creating multiple section view
There are some Input material that i can use
(Civil 3D Object) sampleline = IN[0]
(String) section_view_name = IN[1]
(Point) location = IN[2]
(Civil 3D Object) alignment = IN[3]
I try to make a dynamo python script using civil 3d api(SectionViewGroup class, SectionViewGroupCollection class … etc)
But I don’t know what i using civil 3d api…
How can i make a dynamo python script to create Multiple Section View ?
Like this Image
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
Thank you for assisting me.
Your help has been invaluable.
However, I encountered some errors while attempting to utilize this script.
Input datas and python script are like this image.
# 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["Basic"]
if str(st) == "Corridor":
source.IsSampled = False
source.IsSampled = True
source.StyleId = civdoc.Styles.CodeSetStyles["Basic"]
else:
pass
#get EG source idq
sn = source.SourceName
if str(sn) == "existingsurface":
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["Basic"]
#set band set
sectionViewBandSetStyleId = civdoc.Styles.SectionViewBandSetStyles["Basic"]
#create
SVGC = SLGOb.SectionViewGroups
SVGS = SVGC.Add(P1,SS,ES,rangeOptions,placementOptions,sectiondisplayOptions,sectionViewStyleId,sectionViewBandSetStyleId)
SVGS.PlotStyleId = civdoc.Styles.GroupPlotStyles["Basic"]
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
Error Message
- TypeError : NO method matches given arguments for onexit: (<class’autodesk.autocad.applicationservices.documentlock’>,<class’type’>,<class’typeerror’>,<class’traceback’>)[‘file"",line129,in\n’]
I’m trying to check this script, but it’s a big problem to me.
How can i solve this error?
It must be some Cpython3 syntax error I made, try to run it with Ironpython 2.7. This code was tested in that.
1 Like
I’m really grateful for your kindness in helping me understand something I didn’t know. Thank you so much for your understanding and assistance.
1 Like