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

Help with LISP for Labeling

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
timothy.mckinney
782 Views, 4 Replies

Help with LISP for Labeling

I am extremely new to LISPS and am would love some help automating some labeling. Typically we will get field shots from our surveyors and want to dimension from the points to the building gridline. Usually there is an established "building north" which is not geodetic north. The goal of the LISP routine is to first define building north and then dimension from the point perpendicularly to the building grid. The label can them be placed and text will automatically be added to the end of the dimension stating if the shot is northerly, southerly, easterly, or westerly of the gridline.

 

Two things I need help with:

1) I have the basic structure but cannot get my conditional that automatically adds text to the label to function. One thing I am thinking is the conditional might need some room for the angles being slightly off (although building grids should be perfectly square)?

 

2) I would love to and a while loop to repeat the p3 and p4 picks to continue adding dimensions relative to the initial grid north established by p1 and p2.

 

(defun c:tmck (/ dtr rtd p1 p2 ang1 p3 p4 ang2 suf ang3)

;dtr converts degrees to radians
;rtd converts radians to degrees
	(defun dtr (a)
		(* pi (/ a 180.0))
	)
	(defun rtd (a)
		(/ (* a 180.0) pi)
	)

(setq p1 (getpoint "\nDefine grid north (south point): "))
(setq p2 (getpoint p1 "\nDefine grid north (north point): "))
(setq ang1 (rtd(angle p1 p2)))

(setq p3 (getpoint "\nSelect as-built shot: "))
(setq p4 (getpoint p3 "\nSelect perpendicular to grid: "))
(setq ang2 (rtd(angle p3 p4)))

(command "dimaligned" p3 p4 "\\")

(cond
	((= 180 abs(- ang1 ang2))(setq suf "' N'LY"))
	((= ang1 ang2)(setq suf "' S'LY"))
	((= 90 abs(- ang1 ang2))(setq suf "' E'LY"))
	((= 270 abs(- ang1 ang2))(setq suf "' W'LY"))
	(1 (setq suf " ERROR")))

(command "_.dimoverride" "DIMPOST" suf "" (entlast) "")


(princ)
)

 

 

Any help would be appreciated. Also, I will take any general pointers as well! Would love to keep learning more ways to improve at this.

Tags (3)
Labels (1)
4 REPLIES 4
Message 2 of 5

I'm no Lisp pro by any means, but your routine sounds interesting, could you show a pic of the end product, just curious what your trying to accomplish. I'm sure @tcorey or @Jeff_M  may be able to help with your problem.


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 5
Jeff_M
in reply to: timothy.mckinney


@timothy.mckinney wrote:

Two things I need help with:

1) I have the basic structure but cannot get my conditional that automatically adds text to the label to function. One thing I am thinking is the conditional might need some room for the angles being slightly off (although building grids should be perfectly square)?

 

2) I would love to and a while loop to repeat the p3 and p4 picks to continue adding dimensions relative to the initial grid north established by p1 and p2.

 

Any help would be appreciated. Also, I will take any general pointers as well! Would love to keep learning more ways to improve at this.


@timothy.mckinney your lisp was close. I've added some code for the Osnaps and to make sure your angles are exact for comparison. Also added the While loop. The only thing I didn't do was add an error handler to make sure the original osnap setting is restored in case the user cancels out of the routine.

 

(defun c:tmck (/ dtr rtd p1 p2 ang1 p3 p4 ang2 suf ang)

					;dtr converts degrees to radians
					;rtd converts radians to degrees
  (defun dtr (a)
    (* pi (/ a 180.0))
  )
  (defun rtd (a)
    (/ (* a 180.0) pi)
  )
  (setq snap (getvar 'osmode));save current Osnap mode
  (setvar 'osmode 1);set Osnap to endpoint

  (setq p1 (getpoint "\nDefine grid north (south point): "))
  (setq p2 (getpoint p1 "\nDefine grid north (north point): "))
  (setq ang1 (rtd (angle p1 p2)))
  (while
    (and (setvar 'osmode 8);set Osnap to Node for selecting a Cogopoint
	 (setq p3 (getpoint "\nSelect as-built shot: "))
	 (setvar 'osmode 128);set Osnap to Perp
	 (setq p4 (getpoint p3 "\nSelect perpendicular to grid: "))
    )
     (setq ang2 (rtd (angle p3 p4)))
    (setvar 'osmode 0);set Osnap to None
     (setq ang (atof (rtos (abs (- ang1 ang2)) 2 0)))

     (command "dimaligned" p3 p4 "\\")

     (cond
       ((= 180.0 ang) (setq suf "' N'LY"))
       ((= 0.0 ang) (setq suf "' S'LY"))
       ((= 90.0 ang) (setq suf "' E'LY"))
       ((= 270.0 ang) (setq suf "' W'LY"))
       (1 (setq suf " ERROR"))
     )

     (command "_.dimoverride" "DIMPOST" suf "" (entlast) "")
  )
  (setvar 'osmode snap);reset Osnap
  (princ)
)

 

 

Jeff_M, also a frequent Swamper
EESignature
Message 4 of 5

@rl_jacksonSee below for a rough example. Building north would be different from geodetic or control north but the lisp would allow for automatic labeling in reference to building north. I just placed four example shots around grid A1 to illustrate.

 

Capture.JPG

Message 5 of 5
timothy.mckinney
in reply to: Jeff_M

@Jeff_MThank you very much. I was playing with it this morning and got it to work with using a range (< 179 ang 181) within the condition but this is much more elegant. One question, Using rtos decimal 0 would allow for .99 degree tolerance? I assume there is no rounding with this function so i.e. a delta of 180.79 would turn to 180.0 and satisfy the condition.

 

After studying your solution some more I think I will be able to add a few more tools to my tool belt. Thanks for the help and for taking to time to provide some comments. Having the osnaps be dynamic within the routine is a very nice touch.

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report