I know ArkanceSystems (again thaks to @Anton_Huizinga) has a node for this but I want to tinker myself to prototype more functionality.
Its a pain and you have to be careful what python engine to run in, for me on C3D 2024 its IronPython 2.7 version 2.5 that works, I think:) although all it returns is no solution found invalid parameters??
Anyways here is graph and python code, if you get a chance to experiment, the problem is not the code i think its getting correct parameters to work with the geometry, and assistance from the community on getting a template for what works, what does not would be great, thenks.
cjm
Please note I did hard code some parameter values into this as just testing different ideas, so maybe they need changing??
# 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')
clr.AddReference('Civil3DNodes')
# 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 *
# Import references for Dynamo for Civil 3D
from Autodesk.Civil.DynamoNodes import Alignment as DynAlignment
# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
civdoc = CivilApplication.ActiveDocument
firstAlignmentId = IN[0] # First offset alignment
secondAlignmentId = IN[1] # Second offset alignment
connectedAlignmentName = IN[2] # Connected alignment name, str
connectedAlignmentStyle = IN[3] # Connected alignment style, str
connectedAlignmentLabelSetStyle = IN[4] # Connected alignment label set style, str
curveRadius = IN[5] # Curve radius, double
overlapStart = IN[6] # Overlap on incoming alignment, double
overlapEnd = IN[7] # Overlap on outgoing alignment, double
layerName = IN[8] # Layer name, str
siteId = ObjectId.Null # Site ID, assuming it to be null for this example
result = []
def getLayerIdByName(layerName):
global adoc
layerId = ObjectId.Null
try:
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
layerTable = t.GetObject(db.LayerTableId, OpenMode.ForRead)
if layerTable.Has(layerName):
layerId = layerTable[layerName]
t.Commit()
except System.Exception as ex:
result.append(str(ex))
return layerId
def createConnectedAlignment(firstAlignmentId, secondAlignmentId, connectedAlignmentName, connectedAlignmentStyle, connectedAlignmentLabelSetStyle, curveRadius, overlapStart, overlapEnd, layerName, siteId):
global adoc
global editor
global civdoc
try:
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
# Fetch the style and label set style objects by name
alignmentStyleId = civdoc.Styles.AlignmentStyles[connectedAlignmentStyle].ObjectId
labelSetStyleId = civdoc.Styles.LabelSetStyles.AlignmentLabelSetStyles[connectedAlignmentLabelSetStyle].ObjectId
layerId = getLayerIdByName(layerName)
# Create an instance of ConnectedAlignmentParams
connectedAlignmentParams = ConnectedAlignmentParams()
connectedAlignmentParams.IncomingParentAlignmentId = firstAlignmentId.InternalObjectId
connectedAlignmentParams.OutgoingParentAlignmentId = secondAlignmentId.InternalObjectId
#connectedAlignmentParams.ArcInRadius = 5
#connectedAlignmentParams.ArcOutRadius = 5
connectedAlignmentParams.CurveRadius = curveRadius
connectedAlignmentParams.ConnectionOverlapLengthIn = overlapStart
connectedAlignmentParams.ConnectionOverlapLengthOut = overlapEnd
connectedAlignmentParams.OffsetIn = 0
connectedAlignmentParams.OffsetOut = 0
connectedAlignmentParams.GreaterThan180=1
connectedAlignmentParams.IncomingParentAlignmentStation = 412.34
connectedAlignmentParams.IncomingParentAlignmentStation = 57.23
# Create the connected alignment
connectedAlignmentId = Alignment.CreateConnectedAlignment(
connectedAlignmentName,
siteId,
layerId,
alignmentStyleId,
labelSetStyleId,
connectedAlignmentParams
)
t.Commit()
result.append(connectedAlignmentId)
except Exception() as ex:
result.append(ex.message)
return result
# Assign your output to the OUT variable.
OUT = createConnectedAlignment(firstAlignmentId, secondAlignmentId, connectedAlignmentName, connectedAlignmentStyle, connectedAlignmentLabelSetStyle, curveRadius, overlapStart, overlapEnd, layerName, siteId)
offset_profiles_test.dwg (980.6 KB)
create_connected_alignments_python.dyn (27.1 KB)

