Edit Baseline StartStation value

Hello, I’m currently trying it like this:

corr = t.GetObject(corrid, OpenMode.ForWrite)
base = corr.Baselines[0]
base.StartStation = 5

I get the error “AttributeError: can’t assign to read-only property StartStation of type ‘Baseline’”
I think the C3D API wont let me to Edit Baseline StartStation value, does anyone know any workaround?
I’m thinking creating a new corridor with a new baseline, but that seems a lot of work given that the station value should change several times (is an iterative task)
Regards,

1 Like

Ok, I found this:
https://adndevblog.typepad.com/infrastructure/2014/01/updating-civil-3d-corridor-baselineregion-start-and-end-stations-using-api.html

It have a C# .NET code that goes like this:

Corridor corridor = trans.GetObject(corridorId, OpenMode.ForWrite) asCorridor;           

 

// Get the BaselineRegionCollection

BaselineRegionCollection baselineRegionColl = corridor.Baselines[0].BaselineRegions;

 

// Get the BaselineRegion to update the Start and End Station

BaselineRegion baselineregion = baselineRegionColl["Corridor Region (1)"];

 

if (baselineregion != null)

{

  ed.WriteMessage("\n BaseLineRegion Start Station Before Update : " + baselineregion.StartStation.ToString());

  ed.WriteMessage("\n BaseLineRegion End   Station Before Update : " + baselineregion.EndStation.ToString());

 

  // update the stations Value

 

  baselineregion.StartStation = 50.00;

  baselineregion.EndStation = 568.00;

 

  //rebuild the corridor

  corridor.Rebuild();

 

  ed.WriteMessage("\n BaseLineRegion Start Station After Update : " + baselineregion.StartStation.ToString());

  ed.WriteMessage("\n BaseLineRegion End   Station After Update : " + baselineregion.EndStation.ToString());

 

}   

I have to pythonize it, I’ll post the update when I do it :wink:

Hello, here is the pythonized code:

#Edit Corridor Baseline Stations

__author__ = 'Jesus A Duran - jduran@moffattnichol.com'
__version__ = '0.0.0'

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

# 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 PropertySets
from Autodesk.Aec.PropertyData import *
from Autodesk.Aec.PropertyData.DatabaseServices 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

adoc = acapp.DocumentManager.MdiActiveDocument
ed = adoc.Editor
   
def edit_station(co_name, re_name, new_station_val):
	global adoc
	
	corrid = None
	
	output = {}
	
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
				bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
				btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
				
				for oid in btr:
					obj = t.GetObject(oid, OpenMode.ForWrite)
					if isinstance(obj, Corridor):
						if obj.Name == co_name:
							corrid = oid
							break
				
				if corrid is None:
					return "Corridor not found"
				corr = t.GetObject(corrid, OpenMode.ForWrite)
				baseReColl = corr.Baselines[0].BaselineRegions
				baseRegion = baseReColl[re_name]
				baseRegion.StartStation = new_station_val
				for a in dir(baseRegion):
					try:
						output[a] = getattr(baseRegion, a)
					except:
						pass
				t.Commit()
	return baseRegion.StartStation

OUT = edit_station(IN[0],IN[1],IN[2])

So the dynamo code will be like this:


Where “Edit Corridor baseline stations” has the phyton code.

Hope this is helpfull to someone

2 Likes

This is exactly what I have been trying to. I really appreciate you giving us tips!
I tried to figure out why “StartStation” is editable by directly designating the corridor and corridor regions, instead of using existing nodes picking up specific corridor regions. It turned out types are different.

corr.Baselines[0].BaselineRegions : Autodesk.Civil.DatabaseServices.BaselineRegion
Baseline.Regions (existing Dynamo node) : Autodesk.Civil.DynamoNodes.BaselineRegion

I hope Autodesk.Civil.DynamoNodes.BaselineRegion will allow us to set stations in the future.

Thanks for sharing this!
I am looking for a way to add specify additional stations to my frequencies (i would like a specified increment value along my offset target spirals…), have you any idea? I have to build a python script?