Community
Civil 3D Forum
Welcome to Autodesk’s Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to generate multiple alignments from multiple polylines.

40 REPLIES 40
SOLVED
Reply
Message 1 of 41
Anonymous
6035 Views, 40 Replies

How to generate multiple alignments from multiple polylines.

Hi All,

 

I have a question that is related to automation of a simple task. My background is hydraulic modelling of water networks. A water network for a city can be an elaborate system. Civil3d has well devised import mechanism to import model data in shapefile format.

 

For interference analysis, profile plotting and other allied tasks, the network pipes must have associated surface and alignments. Civil3d has multiple alignment generation options. However, it seems, all require significant man-hours (when it is a city scale branched network). I can dissolve the pipe network into polylines that can be used as objects for alignment generation. For each object, I left a unique integer ID in DF field (of the shapefile).Mapimport Shape with unique ID for each polylineMapimport Shape with unique ID for each polyline

Create alignment from objectsCreate alignment from objects

 

Alignment generation definition to be replicated for each polyline object.Alignment generation definition to be replicated for each polyline object.

My question is, is there any application or script that can take the polylines and generate alignment for each polyline without requiring any user intervention? Attaching a sample file that contains the polyline objects that need to be converted into alignments. For the seven polyline objects in the file, I want to generate seven corresponding alignments; preferably named 'Alignment - DF'. The process should be automated.

 

Much appreciate a quick response. Thanks in advance.

40 REPLIES 40
Message 2 of 41
rl_jackson
in reply to: Anonymous

@Anonymous  First let me say Welcome to the Forum. 

 

First you can't have multiple alignments with the same name that I'm aware of as you show in your example xxxx-DF so there in lies some intervention to the automation that will require some form of input from the user. Now you can place a counter after the DF that would automate creating the alignment. But to create multiple without any user input would mean that the user doesn't know where they are or how they are created. 


Rick Jackson
Survey CAD Technician VI

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 3 of 41
cwr-pae
in reply to: Anonymous

You would need a *.lsp routine for this. I recommend posting on the C3D customization forum (here)  for help with creating said lsp. While you can not have multiple alignments with the same name, you can have multiple alignments with the same description and use the description in place of the name for mast things.

Message 4 of 41
tcorey
in reply to: Anonymous

;this routine converts polylines into Civil 3D Alignments
;significant thanks to Jeff Mishler for his help
(defun c:DES_CnvrtPlineToAlign ( / plss len ctr pl algns lblsets lblset 
									algnstys algnsty algn c3dnumber c3dproduct c3drelease c3ddoc appno
									acadapp acaddoc c3dapp)
(getdoc)
(prompt "\nSelect Polylines: ")
(setq plss (ssget)
	  len (sslength plss)
	  ctr 0)
	  
	  (while (< ctr len)
			  (setq pl (vlax-ename->vla-object (ssname plss ctr)))
			  
				(if (= (vlax-get pl 'ObjectName) "AcDbPolyline")
					(progn
						(setq algns (vlax-get c3ddoc 'AlignmentsSiteless))
						(setq lblsets (vlax-get c3ddoc 'alignmentlabelstylesets)
							  lblset (vlax-get-property lblsets 'item "Major and Minor only")
							  algnstys (vlax-get c3ddoc 'AlignmentStyles)
							  algnsty (vlax-get-property algnstys 'Item "Proposed")
							  )
							  
						(setq algn (vlax-invoke-method algns 'addfrompolyline 
										"fromPolyline" ;new alignment name
										"C-ROAD" ;layer
										(vla-get-objectid pl) ;pline object id
										algnsty ;alignment style
										lblset  ;alignment label set
										:vlax-false ;add curves between tangents
										:vlax-false)  ;delete existing entites
						)
						
						
						))(setq ctr (1+ ctr)))(princ))
						
						
						
						
						
						
						

						
(defun getAecAppNumber (/ )
  (setq	C3Dproduct (strcat "HKEY_LOCAL_MACHINE\\"
			   (if vlax-user-product-key
			     (vlax-user-product-key)
			     (vlax-product-key)
			   )
		   )
	C3Drelease (vl-registry-read C3Dproduct "Release")
	C3Dnumber  (substr
		     C3Drelease
		     1
		     (vl-string-search
		       "."
		       C3Drelease
		       (+ (vl-string-search "." C3Drelease) 1)
		     )
		   )
  )
)

(defun getdoc ( / )

  (setq appno (getaecappnumber))

  (setq	acadapp	(vlax-get-acad-object)
	c3dapp	(vla-getinterfaceobject acadapp (strcat "AeccXUiLand.AeccApplication." appno))
	C3Ddoc	(vla-get-activedocument C3Dapp)
  )

)					;end function


Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 5 of 41
Anonymous
in reply to: rl_jackson

Thanks for your feedbacks.

 

Sorry for the confusion. My earlier question lacked details. The polylines are created from pipes dissolved into desired profile scopes.

 

Actually, the intention is 'not' to create alignments with same name. That's why, I have imported 'DF' variable (a field in the shape file with integer values 1,2,3...,7) as an object data associated with each polyline. So, if one polyline will have associated 'DF' object data as, say, '1' then, it's alignment will have name, 'Alignment -1' while the polyline with  'DF' 5 will have Alignment named as 'Alignment-5'. That is the expectation.

 

Much appreciate your insight.

Message 6 of 41
Anonymous
in reply to: tcorey

Thanks a lot for the lisp code! It 'almost' did what was requested. My earnest thanks to Mr. Mishlar for the lisp code.

 

There is a 'DF' variable (a field in the shape file with integer values 1,2,3...,7) imported as object data associated with each polyline. So, if one polyline will have associated 'DF' object data as, say, '1' then, it's alignment will have name, 'Alignment -1' while the polyline with  'DF' 5 will have Alignment named as 'Alignment-5' as so on. So, getting the naming part done will be a big help.

 

It seems, the code skips polylines with only two vertices (lines with start and end vertex only). Is there a way to modify the code so that all polylines will be considered?

 

Thanks a lot for your assistance.

 

Regards,

 

Imtiaz

 

Message 7 of 41
tcorey
in reply to: Anonymous

@Anonymous , If you post a drawing that includes the object data, I can quickly make the naming change. Or tell me the name of the Object Data Table and the Field name from which to capture the number.

 

If you can't post, send to me directly:  tcorey at shasta dot com

 

As far as skipping polylines with two vertices, I don't find that to be true. Maybe the entities are Lines, not Polylines. Use PEDIT command, Multiple, to turn them into Polylines, before running this LISP.

 

Best regards,

 

Tim

 

 



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 8 of 41
neilyj666
in reply to: tcorey

Code works fine for me although I had to amend the lblset and algnsty to ones I have in my template rather than the ones in the code

neilyj (No connection with Autodesk other than using the products in the real world)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


AEC Collection 2025 UKIE (mainly Civil 3D UKIE and IW)
Win 11 Pro x64, 1Tb Primary SSD, 1Tb Secondary SSD
64Gb RAM Intel(R) Xeon(R) W-11855M CPU @ 3.2GHz
NVIDIA RTX A5000 16Gb, Dual 27" Monitor, Dell Inspiron 7760
Message 9 of 41
Anonymous
in reply to: tcorey

Dear Mr. Corey,

 

Many thanks for your tip! Indeed, after pedit, multiple fix, all alignments were generated from the polyline file. I am attaching the polyline file. This is just a test case file. With each polyline, an object data variable 'DF' contains an integer value. Is there any way the Lisp code can be enhanced to collect the DF integer value and name the alignment created with it as a suffix? For example, if DF = 1, Alignment-1 or if If DF = 5, Alignment-5 and so on.

 

Many thanks for your help.

 

Regards,

 

Imtiaz

Message 10 of 41
tcorey
in reply to: Anonymous

I should be able to do this by Monday...

 

 



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 11 of 41
tcorey
in reply to: Anonymous

Try this. 

;this routine converts polylines into Civil 3D Alignments
;significant thanks to Jeff Mishler for his help
;Rev B converts lines into polylines, with object data intact.No help from Jeff.
(defun c:DES_CnvrtPlineToAlign ( / plss len ctr pl algns lblsets lblset algnstys algnsty algn c3dnumber c3dproduct
									c3drelease c3ddoc appno acadapp acaddoc c3dapp)  
								   
									
(getdoc)
(prompt "\nSelect Polylines: ")
(setq plss (ssget)
	  len (sslength plss)
	  ctr 0)
	  
	  (setq algns (vlax-get c3ddoc 'AlignmentsSiteless))
						(setq lblsets (vlax-get c3ddoc 'alignmentlabelstylesets)
							  lblset (vlax-get-property lblsets 'item "Major and Minor only")
							  algnstys (vlax-get c3ddoc 'AlignmentStyles)
							  algnsty (vlax-get-property algnstys 'Item "Proposed")
							  )
	  
	  (while (< ctr len)
		      (setq ple (ssname plss ctr))
			  (setq pl (vlax-ename->vla-object ple))
			  
				(cond ((= (vlax-get pl 'ObjectName) "AcDbPolyline")
					
						(getade)
						
							  
						(setq algn (vlax-invoke-method algns 'addfrompolyline 
										algnname ;new alignment name
										"C-ROAD" ;layer
										(vla-get-objectid pl) ;pline object id
										algnsty ;alignment style
										lblset  ;alignment label set
										:vlax-false ;add curves between tangents
										:vlax-false)  ;delete existing entites
						)
					   )
						
						
						((= (vlax-get pl 'ObjectName) "AcDbLine")
						 (getade)
						 (vl-cmdf "pedit" ple "y" "")
						 (setq newrecid (ade_odNewRecord "Alignment2"))
						 (setq ple (entlast))
						 (setq pl (vlax-ename->vla-object ple))
						 (ade_odattachrecord ple newrecid)
						 (ade_odsetfield ple "alignment2" "DF"	0 namesfx)
						 (setq algn (vlax-invoke-method algns 'addfrompolyline 
										algnname ;new alignment name
										"C-ROAD" ;layer
										(vla-get-objectid pl) ;pline object id
										algnsty ;alignment style
										lblset  ;alignment label set
										:vlax-false ;add curves between tangents
										:vlax-false)  ;delete existing entites
						)
						 )
						 (t nil)
						 )
						 
						 
						 (setq ctr (1+ ctr))
       )
	(princ)
	)
						
						
	(defun getade ()
  (setq recno (ade_odgetrecord ple "Alignment2" 0))
  (setq namesfx (ade_odgetrecfield recno "DF"))
  (setq algnname (strcat "Alignment-" (itoa namesfx)))
  )					
						
						
						
						

						
(defun getAecAppNumber (/ )
  (setq	C3Dproduct (strcat "HKEY_LOCAL_MACHINE\\"
			   (if vlax-user-product-key
			     (vlax-user-product-key)
			     (vlax-product-key)
			   )
		   )
	C3Drelease (vl-registry-read C3Dproduct "Release")
	C3Dnumber  (substr
		     C3Drelease
		     1
		     (vl-string-search
		       "."
		       C3Drelease
		       (+ (vl-string-search "." C3Drelease) 1)
		     )
		   )
  )
)

(defun getdoc ( / )

  (setq appno (getaecappnumber))

  (setq	acadapp	(vlax-get-acad-object)
	c3dapp	(vla-getinterfaceobject acadapp (strcat "AeccXUiLand.AeccApplication." appno))
	C3Ddoc	(vla-get-activedocument C3Dapp)
  )

)					;end function


Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 12 of 41
Anonymous
in reply to: tcorey

Dear Mr. Corey,

 

Many thanks for your solution! The code works flawlessly.

 

Kind regards,

 

Imtiaz

Message 13 of 41
txheed
in reply to: tcorey

This is not working for me in version 2020. Is there a code change that needs to be made?

Message 14 of 41
tcorey
in reply to: txheed

I would need to get a sample drawing from you. The code should work the same in 2020 as previous versions.



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 15 of 41
txheed
in reply to: tcorey

Attached is an example of the Road Centerlines

 

Command: DES_CNVRTPLINETOALIGN
Select Polylines:
Select objects: 1 found
Select objects:
; error: no function definition: VLAX-ENAME->VLA-OBJECT

Message 16 of 41
Ntuthuko.
in reply to: tcorey

Hi.

 

How do I run this code? Do I paste it into the command line?

Message 17 of 41
neilyj666
in reply to: Ntuthuko.

Open Notepad, paste the code and save as a new file e.g. "newfile.lsp" - make sure you put it in quotation marks

 

On the Civil command line, APPLOAD and browse to the file just saved and load it - be aware it failed when I just tried

 

On the command line type  DES_CNVRTPLINETOALIGN


Select Polylines:
Select objects: Specify opposite corner: 8 found
Select objects:
; error: Automation Error. The parameter is incorrect.
Command:

 

 

neilyj (No connection with Autodesk other than using the products in the real world)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


AEC Collection 2025 UKIE (mainly Civil 3D UKIE and IW)
Win 11 Pro x64, 1Tb Primary SSD, 1Tb Secondary SSD
64Gb RAM Intel(R) Xeon(R) W-11855M CPU @ 3.2GHz
NVIDIA RTX A5000 16Gb, Dual 27" Monitor, Dell Inspiron 7760
Message 18 of 41
Ntuthuko.
in reply to: tcorey

Hi There

 

I've loaded the lisp. When I run it, it says "error, no function definition GETDOC."

 

Please help.

 

Thanks

Ntuthuko

Message 19 of 41
Ntuthuko.
in reply to: neilyj666

Thank you, much appreciated!

 

I have loaded the LISP successfully but when I run it, it says, "error, no function definition: GETDOC." Any idea how I can resolve this?

 

Thanks

Ntuthuko

Message 20 of 41
neilyj666
in reply to: Anonymous

No idea prhaps @tcorey can assist..?

neilyj (No connection with Autodesk other than using the products in the real world)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


AEC Collection 2025 UKIE (mainly Civil 3D UKIE and IW)
Win 11 Pro x64, 1Tb Primary SSD, 1Tb Secondary SSD
64Gb RAM Intel(R) Xeon(R) W-11855M CPU @ 3.2GHz
NVIDIA RTX A5000 16Gb, Dual 27" Monitor, Dell Inspiron 7760

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report