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

# Load the Python Standard and DesignScript Libraries
import sys
import clr
import DSCore

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')

# 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 from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# Import references from Dynamo
from Autodesk.DesignScript.Geometry import Point
from DSCore import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

def getSideName(val):
    if val == 0:
        side = "Left"
    elif val == 1:
        side = "Right"
    elif val == 2:
        side = "Center"
    return side

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

def get_sample_line_info(sampleLines):
    global adoc, t
    
    keys = ["Name","Number","Station","Group Name","Vertices"]
    output = []
    
    if not sampleLines:
        return
    
    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)}
            
            output.append(d)

    return output

with adoc.LockDocument():
    with adoc.Database as db:
        with db.TransactionManager.StartTransaction() as t:
                     
            try:
                
                # Use flatten list
                flst = List.Flatten(IN[0])
                
                OUT = get_sample_line_info(flst)
                
            except:
            
                OUT = "Error"
            
            t.Commit()
            
            pass

Camber package Useful Packages - Dynamo can extract SampleLine information.

1 Like

Is there a way to set the left/right offsets of a sampleline created via the Camber package?

No, not at present.