Create Multiple Alignments From Polylines

lqqerqll

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_info(sampleLines):
	
	global adoc
	global cdoc
	
	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:
	            #bt = t.GetObject(db.BlockTableId, OpenMode.ForRead)
	            #btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
				for sampleLine in sampleLines:
					vals = []
					bt = t.GetObject(db.BlockTableId, OpenMode.ForRead)
					btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
					sampleLineId = sampleLine.InternalObjectId
					obj = t.GetObject(sampleLineId, OpenMode.ForWrite)
					obj.ReverseCurve()
					output.append('Success')
					
					#if isinstance(obj, SampleLine):

						#output.append(obj)
						
				t.Commit()
	return output 		

OUT = get_sample_line_info(IN[0])
1 Like

@mzjensen Is there an order the polylines need to be created? How does dynamo know that the bottom polyline will be C-Street and the top polyline will be A-Street and not the other way around?

In this particular example there isn’t a method of sorting the Polylines. The example was more intended to be illustrative of how to create multiple Alignments. You could certainly add some type of sorting routine (e.g. sort the curve start points by increasing X and/or Y values) to follow whatever naming convention you need.

If there is no sorting applied, then the objects will be selected in Dynamo in the order they were created. In other words, the most recently-created object will be at the bottom of the list.

Thanks @mzjensen

In order to re-use the multiple alignment script, it will be better to draw the polyline, then fill up blanks on the Excel spreadsheet, right? Otherwise, I can sort the curve start points by increasing X and/or Y values) to follow whatever naming convention I need, but the script will be only for a particular project


Pulling the information from an Excel spreadsheet may not be needed in your particular case. It depends on the workflow you’d like to have. Again, the purpose of this graph was to illustrate a general concept. Like you said, determining a naming convention for the alignments is likely a project-specific task. If you want to give the user control of the order, one idea would be to use the Select Objects node from the Civil 3D Toolkit and tell the user to select the polylines in the order that they want.

@mzjensen This is excellent thank you so much for your help. I was able to use your script and add a little bit of my own. I can generate alignments, existing ground profiles, and profile views in one run, with the idea of using the script in multiple projects. Thanks for sharing your knowledge.

1 Like

Hello people, Someone could help me with this node? In my case i am extracting a polyline from corridor feature line. After that a want to create an alignment for each polyline extracted. What I do not understand is that sometimes the node works and sometimes do not, even with the same inputs, in this last case the node only gives me null values without an error message. @mzjensen


Mod_Dre-SUP_Corredor_Polyline2.dyn (475.8 KB)

@KairoFilipe that node is from the Civil 3D Toolkit, so there might be information in the log file. Look in your user temp folder (the file name says “Civil 3D Toolkit” in it) and see if there is any relevant info.

@mzjensen Thanks for the tip, the log file show me the error.

1 Like

Hello everyone, i share my solution. I hope it can work for you too.

Create_alignment.dyn (18.6 KB)

Hi, CreaciĂłn de mĂșltiples alineamientos a partir de polilĂ­neas en Dynamo para Civil 3D - YouTube I hope it can work for you too.

could you help me when I use this script to make multiple alignments in civil 3d 2022.2 is ok
but in civil3d2021.3.2 some alignments don’t match with its polyline such in picture>>> Thanks in advance @mzjensen
Capture

Animation

Hi

Can you attached example drawing

1 Like

Drawing2.dwg (992.9 KB)
This problem in civil 3d 2021

@ENGRMA1234
use
Command: Flatten

3

1 Like

Thank you flatten is the right way but can I do it with dynamo

TRY

USE SendCommand

1 Like