Get the properties of the sample line

Hi Everyone!
I can’t find the node for the sample line properties
I need to get the properties of the sample line: name, station, coordinates …e.t.c
Thanks in advance…
image

There is no node for this. There is only a create sample line under the alignment extensions. You can make the request on the civil 3D toolkit github : Issues · paoloemilioserra/Civil3dToolkit · GitHub

In the meantime try looking at the Sample Line Class : Help

2 Likes

Thanks for your answer!

Hi @lebinhx3c2012,

I wrote this up for you to try. This has not be thoroughly tested, so use with caution.

import sys
import clr

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

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

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

from System.Collections.Generic import Dictionary

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

from Autodesk.DesignScript.Geometry import *

def get_sample_line_vertex_info(vertex):
	
	keys = ["Location","Side"]
	vals = []
	output = []
	
	# Get Point3d of vertex location
	acPoint = vertex.Location
	# Create DesignScript point
	vals.append(Point.ByCoordinates(acPoint.X, acPoint.Y, acPoint.Z))
	vals.append(vertex.Side)
	
	# Create dictionary
	d = {k:v for k,v in zip(keys,vals)}
	dict = Dictionary[str,object](d)
	
	return dict

def get_sample_line_info(sampleLines):
	
	global adoc
	global cdoc
	
	keys = ["Name","Number","Station","Group Name","Vertices"]
	output = []
	
	if not sampleLines:
		return
	
	if not isinstance(sampleLines, list):
		sampleLines = [sampleLines]

	with adoc.LockDocument():
	    with adoc.Database as db:
	        with db.TransactionManager.StartTransaction() as t:
				for sampleLine in sampleLines:
					vals = []
					
					sampleLineId = sampleLine.InternalObjectId
					obj = t.GetObject(sampleLineId, OpenMode.ForRead)
					
					if isinstance(obj, SampleLine):
						vals.append(obj.Name)
						vals.append(obj.Number)
						vals.append(obj.Station)
						
						# Get parent sample line group
						groupId = obj.GroupId
						group = t.GetObject(groupId, OpenMode.ForRead)
						vals.append(group.Name)
						
						# Get vertices
						vertices = obj.Vertices
						verticesDict = []
						for vertex in vertices:
							if isinstance(vertex, SampleLineVertex):
								verticesDict.append(get_sample_line_vertex_info(vertex))
						vals.append(verticesDict)
						
						# Create dictionary
						d = {k:v for k,v in zip(keys,vals)}
						dict = Dictionary[str,object](d)
						output.append(dict)
				t.Commit()
	return output		

OUT = get_sample_line_info(IN[0])
5 Likes

Thank you very much!
I have a problem @mzjensen, I cannot get information in the Vertices List.

1 Like

Nice ! Thanks for sharing this !

1 Like

Use a Dictionary.ValueAtKey node with a key of “Vertices”.

2 Likes

Great! Thank you very much!