Is possible to automate Cross Slope values in alignment using Dynamo?

I’m new on learning Dynamo and C3D API. In the last C3D project i worked on i had a very repetitive task on assigning Cross slope values to a offset alignment through the offset parameters, high and low points for drainage, i had to pick manually every single station and assign value. I would like to know if you think to achieve an automate way to make it is possible

Welcome to the forum.
Do you have any screenshot or example that you can show us? Make it easier to help you.

Hi,
it is totally possible. This is pretty old, but we use this to add superelevation data to offset profiles.
Inputs: offset alignment, list of stations, list of cross slopes (input format 0.025; 0.05 etc.), description
You can modify it for your needs.

# 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')
clr.AddReference('System')

from System.Collections.Generic import List

# 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

align = IN[0]
station = IN[1]
slope = IN[2]
desc = IN[3]

result = []
oppsset = []

def offsetsuper(align,station,slope,desc):
	global adoc
	global editor
	global civdoc
	
	try:	
		with adoc.LockDocument():
			with adoc.Database as db:
				with db.TransactionManager.StartTransaction() as t:
					#Selected alignment ID and object			
					alignment = align
					alignmentId = alignment.InternalObjectId
					al = t.GetObject(alignmentId, OpenMode.ForRead)
					alname = al.Name
					#Profile ID and object
					profileId = al.GetProfileIds()[0]
					profile = t.GetObject(profileId, OpenMode.ForWrite)
					n = station.Count
					opp = profile.OffsetProfileParameters(profile)
					oppstations = opp.Stations
					for i in range(0,n):
						#slopepercent = slope[s]*0.01
						opps = profile.OffsetProfileParametersStation(station[i],slope[i],desc[i])
						oppsset.append(opps) 
					oppssetlist = List[Profile.OffsetProfileParametersStation](oppsset)
					opp.Stations = oppssetlist
					oppstations = opp.Stations
					#list results
					for st in oppstations:
						res = st.Station
						result.append(res)
					#a = opp.Stations
					t.Commit()

	except Exception() as ex:
		oppstations.append(ex.message)
	return result
# Assign your output to the OUT variable.
OUT = offsetsuper(align,station,slope,desc)

2 Likes

Thank you so much, that’s super helpful!