LISP edit Help Chainage

LISP edit Help Chainage

Anonymous
Not applicable
1,580 Views
7 Replies
Message 1 of 8

LISP edit Help Chainage

Anonymous
Not applicable

I'm looking for some help editing a lisp previously posted here; http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-can-i-change-the-justification-of...

 

Currently this LISP works perfectly except the chainage values are returned as meters. Ideally i'd like to change the code to display kilometers so 4100 becomes 4.100.

 

I have absolutely zero experience editing LISPs and would really appreciate any assistance to achieve this.

(defun c:CH1 (/)
(vl-load-com)
(defun _Line (p b o)
       (entmake
	 (append
	   '((0 . "line")
	     (100 . "AcDbEntity")
	     (67 . 0)
	     (410 . "Model")
	     (8 . "C-CTRL_TICK")
	     (100 . "AcDbLine")
	     )
	   (list (cons 10 (polar p b o)))
	   (list (cons 11 (polar p (+ b PI) o)))
	   '((210 0.0 0.0 1.0))
	   )
	 )
  )
(defun _text (p b o h c)
;;;  pBe -<-- dont forget to mention the original author dude
       (entmake
	 (append
	   '((0 . "MTEXT")
	     (100 . "AcDbEntity")
	     (67 . 0)
	     (410 . "Model")
	     (7 . "Standard Arial")
	     (8 . "C-CTRL_TXT")
	     (100 . "AcDbMText")
	     )
	   (list (cons 10 (polar p (+ b PI) o))
		 )
	   (list (cons 40 h))
	   (list (cons 1 (strcat "KP "
				 (if (setq ld (nth (strlen (rtos  c 2 0)) '(x   "")))
				   	ld "")
				 (rtos c 2 2))))
	   (list (cons 50 (+ b PI)))
	   
	   '((41 . 1.0)
	     (71 . 4)
	     (72 . 5)
	     (210 0.0 0.0 1.0)
	     (73 . 1)
	     )
	   )
	 )
  )
(defun _ang (p1 p2)(+ (angle p1 p2) (/ PI 2.0)))
  
(setq dist (getdist "increment: "))
  (setq offset (getdist "tick size: "))
  (setq height (getdist "text height: "))
  (setq to (getdist "text offset: "))
  (setq	ss (ssget)
	count 0
	dist dist
	offset offset
	height height
	)
  (repeat (sslength ss)
    (setq ent	   (ssname ss count)
	  obj	   (vlax-ename->vla-object ent)
	  chainage dist
	  )
    (_line (setq p (vlax-curve-getstartpoint obj))
	   (setq bearing (_ang p (vlax-curve-getPointAtDist obj (+ chainage 0.001))))
		   offset)
    (_text p bearing to height 0.0)
    (while
      (and
	(setq point1 (vlax-curve-getPointAtDist obj chainage))
	(setq point2 (vlax-curve-getPointAtDist obj (+ chainage 0.001)))
	)
       (setq bearing (+ (angle point1 point2) (/ PI 2.0)))
       (_line point1 bearing offset)
       (_text point1 bearing to height chainage)
       
       (setq chainage (+ chainage dist))
       )
    (setq count (1+ count))
    )
  )

 

Thanks 

0 Likes
Accepted solutions (1)
1,581 Views
7 Replies
Replies (7)
Message 2 of 8

hmsilva
Mentor
Mentor
Accepted solution

Hello 157898153 and welcome to the Autodesk Community!

 

Try to change

(list (cons 1 (strcat "KP "
				 (if (setq ld (nth (strlen (rtos c 2 0)) '(x   "")))
				   	ld "")
				 (rtos c 2 2))))

to

 

(list (cons 1 (strcat "KP "
				 (if (setq ld (nth (strlen (rtos (/ c 1000.) 2 0)) '(x   "")))
				   	ld "")
				 (rtos (/ c 1000.) 2 2))))

 

Hope this helps,
Henrique

EESignature

Message 3 of 8

Anonymous
Not applicable

Thanks, worked perfectly.

0 Likes
Message 4 of 8

hmsilva
Mentor
Mentor

@Anonymous wrote:

Thanks, worked perfectly.


You're welcome, 157898153
Glad I could help

Henrique

EESignature

0 Likes
Message 5 of 8

Automohan
Advocate
Advocate

Hi Sir;

 

Could you modify slightly the above lisp code......

 

I require Chainage text this way....

Sta: 0+000

Sta: 4+500

Sta: 12+800

Sta: 21+000

 

Thanks in advance for any help/advice

Mohan

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 6 of 8

hmsilva
Mentor
Mentor

@Automohan wrote:

Hi Sir;

 

Could you modify slightly the above lisp code......

 

I require Chainage text this way....

Sta: 0+000

Sta: 4+500

Sta: 12+800

Sta: 21+000

 

Thanks in advance for any help/advice

Mohan


Hello Mohan and welcome to the Autodesk Community!

 

Put stations in the 'Search This Board' window, and a bunch of threads will come up...

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 7 of 8

Automohan
Advocate
Advocate
Best way to use civil 3d for chainage
"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 8 of 8

john.uhden
Mentor
Mentor
(defun FormatSta (sta xp prec / n sign str)
  ;; where:
  ;;  sta = real or integer
  ;;  xp = exponent of 10 to specify how many numeric charcters between "+" and "."
  ;;  prec = decimal precision
  (setq n (expt 10.0 xp) dimzin (getvar "dimzin"))
  (setvar "dimzin" 0)
  (setq sign (if (minusp sta) "-" ""))
  (setq sta (abs sta))
  (setq str1 (strcat sign (itoa (fix (/ sta n))) "+"))
  (setq str2 (rtos (* n (rem (/ sta n) 1)) 2 prec))
  (repeat (max (- xp (strlen str2))(- xp (vl-string-position 46 str2)))
    (setq str2 (strcat "0" str2))
  )
  (setvar "dimzin" dimzin)
  (strcat str1 str2)
)

John F. Uhden

0 Likes