Error in python code for Station and DesignSpeed

To generate Station and DesignSpeed

import clr

# Add Assemblies for AutoCAD and Civil 3D APIs
clr.AddReference('acmgd')
clr.AddReference('acdbmgd')
clr.AddReference('accoremgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('System.Windows.Forms')

# Add standard Python references
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import os
import math

# Add references to manage arrays, collections and interact with the user
from System import *
from System.IO import *
from System.Collections.Specialized import *
from System.Windows.Forms import MessageBox

# Create an alias to the Autodesk.AutoCAD.ApplicationServices.Application class
import Autodesk.AutoCAD.ApplicationServices.Application as acapp

# 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 for Civil 3D
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.
dyn_align = IN[0]

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

output = []

with adoc.LockDocument():
	with adoc.Database as db:
		with db.TransactionManager.StartTransaction() as t:
			align = dyn_align.InternalDBObject
			dSpeedCol = align.DesignSpeeds
			for i in dSpeedCol:
				output.append({"Station": i.Station, "DesignSpeed": i.Value})

			t.Commit()

OUT = output

Hi @Christhian

Try this:

or by using list comprehension in one line:

4 Likes

great @Kulkul
one last consultation to learn more about python in civil 3d using dynamo, any course or book that you can recommend

I haven’t seen any course but I would recommend you start withit and let us know if you hit the wall. Here are few links that might help you:

Great @Kulkul

Hello, the explanation has been very good but I do not understand why it does not work when I do it for a single alignment . I appreciate your answer because I am learning.

This I am testing but has a error:

Could you expand exception.

Yes, this is
image

@carpeso1 It works for me:

1 Like

Yes, thank’s for your help. But i do not understand, why the code that i am using is not useful. Thank you so much. :+1: :+1: :+1: