I need a lisp for polyline labeling

I need a lisp for polyline labeling

Anonymous
Not applicable
5,496 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,497 Views
23 Replies
Replies (23)
Message 2 of 24

Kent1Cooper
Consultant
Consultant

Welcome to these Forums!

 

Have you Searched the Forums?  [Always worth doing before posting a question.]  I suspect this has come up before, and there are probably several routines for stationing markers around.

Kent Cooper, AIA
0 Likes
Message 3 of 24

john.uhden
Mentor
Mentor

I'm not used to metric stationing (chainage), but if you can't find a routine already written, then I can write it for you.

I presume that you may want the polyline start point to have a station other than 0+000.

John F. Uhden

0 Likes
Message 4 of 24

krzysztof.psujek
Advocate
Advocate

@john.uhden There is no need to create new routine.

As Kent has mentioned before, simply using google or community search will give a lot of results.

 

@Anonymous

check for example this one:

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/mark-chainage/m-p/5803418#M334816 

or

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-used-to-work-in-2002-chainage-labelling/m-p/3303675#M301853

or

http://forums.augi.com/showthread.php?52779-Stationing-Autolisp-routine

or another one you may find out with google.

 

Chris

 

  

0 Likes
Message 5 of 24

Anonymous
Not applicable

Thank you so much. But I have a different problem.
I have a drawing that already chainage labels written.
And I have to change this label due to some local aligment change.
So after the change location written chainages have to be increased or decreaset some value.
I  need a lisp that adds or subtracts defined value from selected chainages that had written in 1+234.56 format.
I'll be appreciated if you could help.

0 Likes
Message 6 of 24

krzysztof.psujek
Advocate
Advocate

Hi, please post example drawing. 

It will be easier.

 

Chris

0 Likes
Message 7 of 24

Anonymous
Not applicable

For example I have an alignment like below.
Due to change at the beginning part, alignment has shorten 200 meters.

A lisp for this quest?

2017-01-20_17-21-56.png

 

0 Likes
Message 8 of 24

krzysztof.psujek
Advocate
Advocate

Try this.

Dirty and briefly tested but should works.

 

Chris

 

(defun c:add2sta (/ delta e sta)
  (setq delta (getreal "\nValue to add to stations: "))
  (while (setq e (car (nentsel)))
    (if	(setq sta (UnFormatStation (LM:gettextstring e)))
      (progn
	(setq sta (FormatStation (+ sta delta)))
	(vla-put-TextString (vlax-ename->vla-object e) sta)
      )
      (alert "Wrong input format!")
    )
  )
)

; ================================================================================================= ;
; UnFormatStation (str / % DMZ km)                                                                  ;
; Arguments: "###+###.##"                                                                           ;
; (UnFormatStation "0+000,12") ;-> 0.0                                                                  ;
; (UnFormatStation "1+310,99") ;-> 1310.0                                                            ;
(defun UnFormatStation (sta)
  (atof (vl-string-subst "" "+" sta))
)

; ================================================================================================= ;
; FormatStation (num / % DMZ km)                                                                    ;
; Arguments: num                                                                                    ;
; (FormatStation 0.12) ;-> "0+000,12"                                                               ;
; (FormatStation 1310.99);-> "1+310,99"                                                             ;


(defun FormatStation (num / % DMZ km)
  (if (or (eq (type num) 'REAL) (eq (type num) 'INT))
    (progn 
      (setq DMZ (getvar "DIMZIN"))
      (setvar "DIMZIN" 0)
      (setq % (rtos num 2 2))
      (setvar "DIMZIN" DMZ)
      (cond
	((wcmatch % "#.##") (setq km (strcat "0+00" %)))
	((wcmatch % "##.##") (setq km (strcat "0+0" %)))
	((wcmatch % "###.##")
	 (setq km (strcat "0" "+" (substr % 1 6)))
	)
	((wcmatch % "####.##")
	 (setq km (strcat (substr % 1 1) "+" (substr % 2 6)))
	)
	((wcmatch % "#####.##")
	 (setq km (strcat (substr % 1 2) "+" (substr % 3 7)))
	)
	((wcmatch % "######.##")
	 (setq km (strcat (substr % 1 3) "+" (substr % 4 8)))
	)
	((wcmatch % "#######.##")
	 (setq km (strcat (substr % 1 4) "+" (substr % 5 9)))
	)
	(t %)
      )
      ;(vl-string-translate "." "," km)
    )				
    nil
  )
)
; ================================================================================================= ;
;; Get Textstring  -  Lee Mac                                                                       ;
;; Returns the text content of Text, MText, Multileaders, Dimensions & Attributes                   ;


(defun LM:gettextstring ( ent / enx itm str typ )
    (setq enx (entget ent)
          typ (cdr (assoc 0 enx))
    )
    (cond
        (   (wcmatch typ "TEXT,*DIMENSION")
            (cdr (assoc 1 (reverse enx)))
        )
        (   (and (= "MULTILEADER" typ)
                 (= acmtextcontent (cdr (assoc 172 (reverse enx))))
            )
            (cdr (assoc 304 enx))
        )
        (   (wcmatch typ "ATTRIB,MTEXT")
            (setq str (cdr (assoc 1 (reverse enx))))
            (while (setq itm (assoc 3 enx))
                (setq str (strcat (cdr itm) str)
                      enx (cdr (member itm enx))
                )
            )
            str
        )
    )
)

 

Chris

Message 9 of 24

john.uhden
Mentor
Mentor

How about just...

 

 

(defun FormatSta (sta)
(strcat (itoa (fix (/ sta 1000)))"+"(rtos (* 1000.0 (rem (/ sta 1000.0) 1)) 2 2))
)

John F. Uhden

Message 10 of 24

krzysztof.psujek
Advocate
Advocate

Nice, haven't test it yet but I am quite sure it works.

I took format-sta function from my old routine so...  now I can update it ;).

 

Thanks John. 

0 Likes
Message 11 of 24

Anonymous
Not applicable

Thanks a lot.
But It works for changing objects selecting one by one.
Is it possible to make it work for multi selection?

0 Likes
Message 12 of 24

krzysztof.psujek
Advocate
Advocate

It is possible, this one above generally should works with several types of objects (if you only pick it): texts/mtexts/attribs/mleaders

Because you didn't post drawing as I asked before and I didn't know what exact objects those stations are.

 

If you want to make it work on a selection set - first post example drawing. I need right data for some tests.

 

Chris

 

0 Likes
Message 13 of 24

john.uhden
Mentor
Mentor

This one is better as it allows you to specify format and precision:

 

(defun FormatSta (sta xp prec / n)
  ;; 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))
  (strcat (itoa (fix (/ sta n)))"+"(rtos (* n (rem (/ sta n) 1)) 2 prec))
)

For example...

Command: (formatsta 123456.789 3 3)
"12+345.679"

 

Command: (formatsta 123456.789 2 2)
"123+45.68"

 

It also works with negative numbers.

John F. Uhden

0 Likes
Message 14 of 24

john.uhden
Mentor
Mentor
It strikes me that maybe you ought to just erase the old ones and relable
with something we invent for you (if you don't already have something).

John F. Uhden

0 Likes
Message 15 of 24

john.uhden
Mentor
Mentor

I was wrong.  It did not handle low negative numbers correctly.

This one does...

 

(defun FormatSta (sta xp prec / n sign)
  ;; 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))
  (setq sign (if (minusp sta) "-" ""))
  (setq sta (abs sta))
  (strcat sign (itoa (fix (/ sta n)))"+"(rtos (* n (rem (/ sta n) 1)) 2 prec))
)

John F. Uhden

0 Likes
Message 16 of 24

krzysztof.psujek
Advocate
Advocate

 

Hi John,

I've just did some quick tests of your last function and it's not working properly.

Take a look here:

 

 

(FormatSta 10125.32 3 2);-> "10+125.32"
(FormatSta 10125.00 3 2);-> "10+125" should be "10+125.00"
(FormatSta 1 3 2);-> "0+1" should be "0+001.00"
(FormatSta 11.212 3 2) ;-> "0+11.21" should be "0+011.21"

 

 

 

Chris

0 Likes
Message 17 of 24

ВeekeeCZ
Consultant
Consultant

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

 

Message 18 of 24

krzysztof.psujek
Advocate
Advocate

Yup,

after quick tests - your variation gives right results.

 

Thanks @ВeekeeCZ.

 

Chris

0 Likes
Message 19 of 24

john.uhden
Mentor
Mentor

Nice work.  I had forgotten all about DIMZIN.  But you did leave out the xp argument to account for feet vs. meters.

John F. Uhden

0 Likes
Message 20 of 24

ВeekeeCZ
Consultant
Consultant

@john.uhden wrote:

Nice work.  ... But you did leave out the xp argument to account for feet vs. meters.


Thanks!

 

I did not understand why is that -- I'm using metric system -- so it's up to you to fix it and make an over all solution! 🙂

 

 

;----

 

You're welcome, Chris!

0 Likes