I need a lisp for polyline labeling

I need a lisp for polyline labeling

Anonymous
Not applicable
5,509 Views
23 Replies
Message 1 of 24

I need a lisp for polyline labeling

Anonymous
Not applicable

Hi 
I need a lips for polyline labeling like that:
I will select the polyline than mark a point on that polyline,
lisp will calculate the distance from beggining of polyline to market point on polyline aligment then it will write the calculated distance as P1=12+456.78 format. 
Is there any lisp like that?

 

0 Likes
Accepted solutions (1)
5,510 Views
23 Replies
Replies (23)
Message 21 of 24

john.uhden
Mentor
Mentor

In metric stationing one provides 3 characters after the + for 999 meters.  In imperial stationing one provides only 2 characters after the + for 99 feet.

IOW, whole stations in metric are for one thousand meters, but for imperial whole stations are for one hundred feet.

 

I added dimzin to my function but (formatsta 12 3 3) returned 0+12.000, not 0+012.000.  All the metric people should use your function.

John F. Uhden

0 Likes
Message 22 of 24

ВeekeeCZ
Consultant
Consultant

@ВeekeeCZ wrote:

I would go other way... 

 

(defun FormatSta (sta pre / a dmz)
  (setq dmz (getvar 'DIMZIN))
  (setvar 'DIMZIN 0)
  (setq a (vl-string-translate "." "+" (rtos (/ sta 1000.) 2 (+ pre 3))))
  (setvar 'DIMZIN dmz)
  (strcat (substr a 1 (- (strlen a) 2)) "." (substr a (1- (strlen a)))))

 


Thinking about this... yes, I makes what it supposed to, but I'm feeling like this function should be made of very basic functions, independent on DIMZIN or vl*..

 

(defun FormatSta (sta pre / i s x u v w) ; stationion as real, pre as integer
  
  (setq s (rtos (/ sta 1000.) 2 (+ pre 3))
	u "" v "" w ""
	i 0)

  (strcat
    (while (and (/= "." (setq x (substr s (setq i (1+ i)) 1))) (/= "" x))
      (setq u (strcat u x)))
    "+"
    (repeat 3
      (setq v (strcat v (if (/= "" (setq x (substr s (setq i (1+ i)) 1))) x "0"))))
    "."
    (repeat pre
      (setq w (strcat w (if (/= "" (setq x (substr s (setq i (1+ i)) 1))) x "0"))))
    ))

 

Message 23 of 24

john.uhden
Mentor
Mentor
Accepted solution

I'm not happy about the bloating, but I think I've got it.

 

(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)
)

Command: (formatsta 0.34 3 2) "0+000.34"

Command: (formatsta 0.34 2 2) "0+00.34"

Command: (formatsta 0 3 2) "0+000.00"

John F. Uhden

Message 24 of 24

john.uhden
Mentor
Mentor

Please note that I forgot to localize str1 and str2 and that str is no longer used.

For those who are not sure, by definition input arguments are local as well.

 

Anyway, the point is that the function accomodates both metric (12+345.67, where xp is supplied as 3) and imperial (123+45.67, where xp is supplied as 2) formatting, even if the input is an integer and/or negative.

John F. Uhden

0 Likes