Query the Direction (Bearing) of an Alignment

I have the Civil 3D Toolkit package installed, and I cannot seem to find anything that will give me the bearing (direction) of an alignment drawn? I’m trying to pull certain information from alignment data in order to create a table of specific items. I see a bunch of nodes to create lines by direction, but nothing that allows me to query unless I’m just not looking in the right place. Any suggestions?

Hi @SMorykin,

To my knowledge, a node with that functionality doesn’t exist yet. Here’s couple options for you:

  1. You could use AlignmentExtensions.GetGeometry to get the Dynamo geometry for the alignment, and then do a little gymnastics to measure the angle between the elements and the Y axis (or north). However, that doesn’t really work for getting the bearing for a non-tangent entity like an arc or spiral.

  2. Here’s some quick Python code to get the northing, easting, and bearing of any point along the alignment given station and offset.

import clr

clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')

from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *

from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

from System.Collections.Generic import Dictionary

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

def get_alignment_info(alignment, station, offset):

	global adoc
	global civdoc
	
	keys = ["Easting", "Northing", "Bearing"]

	with adoc.LockDocument():
	    with adoc.Database as db:
	        with db.TransactionManager.StartTransaction() as t:
				oid = alignment.InternalObjectId
				obj = t.GetObject(oid, OpenMode.ForRead)
				vals = obj.PointLocation(station, offset, 0.001, 0, 0, 0)
				d = {k:v for k,v in zip(keys,vals)}
				dict = Dictionary[str,object](d)
				t.Commit()
	return dict

OUT = get_alignment_info(IN[0],IN[1],IN[2])
3 Likes

Thanks for quick reply. I figured some gymnastics was involved but was having problems with the Line.Direction node and it’s still giving me an error (see below). I did download todays version of the Toolkit, I was hoping additional nodes for the Direction were available. Seems like everything else about an alignment and sub-entities are, thought maybe I was just missing something since there is SO much in that toolkit.

1 Like

It’s giving the warning because Line.Direction doesn’t work with arcs. You’d need to instead use Curve.TangentAtParameter to get the tangent vector at the desired location.

1 Like

Brilliant! Thank you!

I heard you …

6 Likes

LOL! You rock, Paolo!

1 Like