AutoCAD Civil 3D Customization

AutoCAD Civil 3D Customization

Reply
*Expert Elite*
neilyj
Posts: 3,781
Registered: ‎08-01-2008
Message 1 of 17 (345 Views)
Accepted Solution

Creating Pline along centreline of existing road

345 Views, 16 Replies
08-18-2011 08:14 AM

I have an exsiting road survey and I need to create the centreline. I am creating a PLINE by slecting two approx adjacent points and using the M2P transparent command to fin the mid point. This method means having to type M2P every time so is there a way I can create a new command to create a PLINE but which defaults to M2P??

 

thanks

neilyj
(No connection with Autodesk other than using the products in the real world)


IDSP Premium 2015 (mainly Civil 3D 2015 UKIE & Infraworks with some limited 3ds Max Design)
Win 7 Pro x64, 240Gb SSD, 1Tb HDD
32Gb Ram Intel Xeon CPU E5-2650 v2 @ 2.6GHz (32 CPUs), ~2.6GHz
NVIDIA Quadro K4000, Dual 27" Monitor, Dell T5610

Looks like you already have a different solution, but since I whipped this up perhaps someone may find a use for it. It's quick & dirty, not pretty, no frills, no arcs, but it works.. command name is plinemid. Stupid forum software STILL places smileys in code panes. that smiley should be "c : plinemid" without the spaces or quotes.

 

(defun c:plinemid (/ DOC MSPACE P1 P2 PLINE VERTICES)
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object))
mspace (vla-get-modelspace doc)
)
(defun getmidpoint (start_next_msg / p1 p2)
(if (and (setq p1
(getpoint (strcat "\n" start_next_msg " point side 1: "))
)
(setq p2
(getpoint p1
(strcat "\n" start_next_msg " point side 2: ")
)
)
)
(mapcar '(lambda (x y) (/ (+ x y) 2)) p1 p2)
nil
)
)
(if (and (setq p1 (getmidpoint "Start"))
(setq p2 (getmidpoint "Next"))
(setq vertices (list (car p1) (cadr p1) (car p2) (cadr p2)))
)
(progn
(setq pline (vlax-invoke mspace 'addlightweightpolyline vertices))
(while (setq p1 (getmidpoint "Next"))
(setq vertices (append vertices (list (car p1) (cadr p1))))
(vlax-put pline 'coordinates vertices)
(vla-update pline)
)
)
)
(princ)
)

 

And lisp needs 2 "\"'s when used literally...

^C^C(netload "C:\\AutoLisp\\AutoCAD_Project_SurveyFix.dll") Surveyfix;



*Expert Elite*
Jeff_M
Posts: 4,365
Registered: ‎07-22-2003
Message 2 of 17 (330 Views)

Re: Creating Pline along centreline of existing road

08-19-2011 06:34 AM in reply to: neilyj

Do you need to account for arcs in the pline?

Jeff_M, also a frequent Swamper
*Expert Elite*
neilyj
Posts: 3,781
Registered: ‎08-01-2008
Message 3 of 17 (330 Views)

Re: Creating Pline along centreline of existing road

08-19-2011 06:43 AM in reply to: Jeff_M

Not specifically - I basically have both sides of a forest track surveyed (with shots at varying distances apart but shots on each side are generally opposite each other) and want to create the approx centreline for realignment purposes using the M2P command.

 

I will be concentrating on the straight(ish) sections and then using the alignment tool to do the fancy stuff with curves and offsets etc

neilyj
(No connection with Autodesk other than using the products in the real world)


IDSP Premium 2015 (mainly Civil 3D 2015 UKIE & Infraworks with some limited 3ds Max Design)
Win 7 Pro x64, 240Gb SSD, 1Tb HDD
32Gb Ram Intel Xeon CPU E5-2650 v2 @ 2.6GHz (32 CPUs), ~2.6GHz
NVIDIA Quadro K4000, Dual 27" Monitor, Dell T5610
*Expert Elite*
Jeff_M
Posts: 4,365
Registered: ‎07-22-2003
Message 4 of 17 (330 Views)

Re: Creating Pline along centreline of existing road

08-19-2011 07:41 AM in reply to: neilyj

Looks like you already have a different solution, but since I whipped this up perhaps someone may find a use for it. It's quick & dirty, not pretty, no frills, no arcs, but it works.. command name is plinemid. Stupid forum software STILL places smileys in code panes. that smiley should be "c : plinemid" without the spaces or quotes.

 

(defun c:plinemid (/ DOC MSPACE P1 P2 PLINE VERTICES)
  (vl-load-com)
  (setq	doc    (vla-get-activedocument (vlax-get-acad-object))
	mspace (vla-get-modelspace doc)
  )
  (defun getmidpoint (start_next_msg / p1 p2)
    (if	(and (setq p1
		    (getpoint (strcat "\n" start_next_msg " point side 1: "))
	     )
	     (setq p2
		    (getpoint p1
			      (strcat "\n" start_next_msg " point side 2: ")
		    )
	     )
	)
      (mapcar '(lambda (x y) (/ (+ x y) 2)) p1 p2)
      nil
    )
  )
  (if (and (setq p1 (getmidpoint "Start"))
	   (setq p2 (getmidpoint "Next"))
	   (setq vertices (list (car p1) (cadr p1) (car p2) (cadr p2)))
      )
    (progn
      (setq pline (vlax-invoke mspace 'addlightweightpolyline vertices))
      (while (setq p1 (getmidpoint "Next"))
	(setq vertices (append vertices (list (car p1) (cadr p1))))
	(vlax-put pline 'coordinates vertices)
	(vla-update pline)
      )
    )
  )
  (princ)
)

 

Jeff_M, also a frequent Swamper
*Expert Elite*
neilyj
Posts: 3,781
Registered: ‎08-01-2008
Message 5 of 17 (321 Views)

Re: Creating Pline along centreline of existing road

08-19-2011 07:48 AM in reply to: Jeff_M

This is a great solution - thanks for taking the time and trouble to do the lisp - I wouldn't have known where to start.

 

Is it possible to put Lisp routines on a tool palette??

neilyj
(No connection with Autodesk other than using the products in the real world)


IDSP Premium 2015 (mainly Civil 3D 2015 UKIE & Infraworks with some limited 3ds Max Design)
Win 7 Pro x64, 240Gb SSD, 1Tb HDD
32Gb Ram Intel Xeon CPU E5-2650 v2 @ 2.6GHz (32 CPUs), ~2.6GHz
NVIDIA Quadro K4000, Dual 27" Monitor, Dell T5610
*Expert Elite*
Jeff_M
Posts: 4,365
Registered: ‎07-22-2003
Message 6 of 17 (317 Views)

Re: Creating Pline along centreline of existing road

08-19-2011 08:05 AM in reply to: neilyj

neilyj wrote:

 

Is it possible to put Lisp routines on a tool palette??


Should be able to. Place the code in a new text file and save it in your support path or somewhere you will know where to find it named "plinemid.lsp". Then the macro would be (no space after the colon again):

 

^C^C(if (not c:smileytongue:linemid) (load "plinemid")) plinemid;

Jeff_M, also a frequent Swamper
*Expert Elite*
AllenJessup
Posts: 5,916
Registered: ‎05-21-2003
Message 7 of 17 (309 Views)

Re: Creating Pline along centreline of existing road

08-19-2011 08:30 AM in reply to: neilyj

Theoretically you could make the lisp one long line and put in on the Tool Palette. But Jeff's way is much better.

 

Macros have no length limit. But I think it's best to keep them small.

 

Allen

*Expert Elite*
neilyj
Posts: 3,781
Registered: ‎08-01-2008
Message 8 of 17 (309 Views)

Re: Creating Pline along centreline of existing road

08-19-2011 08:30 AM in reply to: Jeff_M

Many thanks again - that work's well

 

Another query - can a DLL (usually loaded via NETLOAD) be placed on a tool palette in a similar way??

neilyj
(No connection with Autodesk other than using the products in the real world)


IDSP Premium 2015 (mainly Civil 3D 2015 UKIE & Infraworks with some limited 3ds Max Design)
Win 7 Pro x64, 240Gb SSD, 1Tb HDD
32Gb Ram Intel Xeon CPU E5-2650 v2 @ 2.6GHz (32 CPUs), ~2.6GHz
NVIDIA Quadro K4000, Dual 27" Monitor, Dell T5610
*Expert Elite*
Jeff_M
Posts: 4,365
Registered: ‎07-22-2003
Message 9 of 17 (304 Views)

Re: Creating Pline along centreline of existing road

08-19-2011 08:35 AM in reply to: neilyj

neilyj wrote:

Many thanks again - that work's well

 

Another query - can a DLL (usually loaded via NETLOAD) be placed on a tool palette in a similar way??



Glad I could help.

Yes, although rather than checking if the command is available, just netload it. If it's already loaded it won't load again. 

^C^C(netload "path to dll) commandname;

Jeff_M, also a frequent Swamper
*Expert Elite*
neilyj
Posts: 3,781
Registered: ‎08-01-2008
Message 10 of 17 (300 Views)

Re: Creating Pline along centreline of existing road

08-19-2011 08:51 AM in reply to: Jeff_M

Can you confirm that this syntax is correct - not sure about the quote and brackets??

 

^C^C(netload "C:\AutoLisp\AutoCAD_Project_SurveyFix.dll) Surveyfix;

neilyj
(No connection with Autodesk other than using the products in the real world)


IDSP Premium 2015 (mainly Civil 3D 2015 UKIE & Infraworks with some limited 3ds Max Design)
Win 7 Pro x64, 240Gb SSD, 1Tb HDD
32Gb Ram Intel Xeon CPU E5-2650 v2 @ 2.6GHz (32 CPUs), ~2.6GHz
NVIDIA Quadro K4000, Dual 27" Monitor, Dell T5610
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.