Get the properties of the sample line

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])
7 Likes