Jump to content

Ammend output of chainage


chizifreshi

Recommended Posts

1+

 

These may help in that respect.

Lee, that's a great set of tutorials!

 

Could I presume to give a suggestion? :wink:

 

In your Introduction to VLIDE: the "Loading a Program" section doesn't make note that you don't need to save the LSP before loading it in ACad. In my experience this is quite a useful thing, as you cannot undo (Ctrl+Z) after you've saved. So if you make a quick change, you can load it without saving, test the code, and if something doesn't work you can undo.

Link to comment
Share on other sites

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • irneb

    11

  • chizifreshi

    9

  • Lee Mac

    3

  • BlackBox

    3

Top Posters In This Topic

OK, a bit more complex :lol:

(defun _AddSta (num /)
 (if (>= num 1000.0)
   (strcat ((lambda (s)
              (substr s 1 (- (strlen s) 3))
             )
             (vl-string-left-trim "+0" (_AddSta (fix (/ num 1000.0))))
           )
           (vl-string-left-trim "0" (_AddSta (rem num 1000.0)))
   )
   (strcat ((lambda (s)
              (while (< (strlen s) 5) (setq s (strcat s "0")))
              s
            )
             (vl-string-translate ",." "++" (rtos (/ num 1000.0) 2 3))
           )
           ((lambda (s)
              (if (eq s "")
                (setq s ".00")
                (while (< (strlen s) 3) (setq s (strcat s "0")))
              )
              s
            )
             (vl-string-left-trim "0" (rtos (rem num 1.0) 2 2))
           )
   )
 )
)

Probably going overboard, but what the hell! :shock:

Link to comment
Share on other sites

Blind b... just realized that function goes and mixes all sorts of programming concepts! It's imperative, it's functional, it uses both iteration and recursion, and then just to mix it all up there's some anonymous functions as well! If I didn't lisp, I'd think it was a mess! :P

Link to comment
Share on other sites

Lee, that's a great set of tutorials!

 

Could I presume to give a suggestion? :wink:

 

In your Introduction to VLIDE: the "Loading a Program" section doesn't make note that you don't need to save the LSP before loading it in ACad. In my experience this is quite a useful thing, as you cannot undo (Ctrl+Z) after you've saved. So if you make a quick change, you can load it without saving, test the code, and if something doesn't work you can undo.

 

Thanks Irne, I'm glad you like them :)

 

I would like to add a lot more, but to be honest, I found writing tutorials more of a challenge than I had anticipated. Its rather difficult to get the right balance of the amount of information, the level of programming involved, and still keep the interest of the reader throughout. Also, things that seem obvious to a more experienced LISPer might confuse a novice, so I find myself trying to include every little bit of information, which isn't always possible.

 

But I certainly welcome any and all suggestions to help me improve the tutorials - there are bound to be items I have overlooked.

 

Thanks for looking over them!

 

Lee

Link to comment
Share on other sites

OK, a bit more complex :lol:
(defun _AddSta (num /) ... <snip> ... 

 

Great code Irne!

 

I think you may have trouble with numbers less than one when DIMZIN is non-zero, for example:

 

_$ (_Addsta 0.02)
"00000.02"

But excellent code all the same.

 

I thought I'd have a stab at it too:

 

(defun _num->sta ( n / num->sta d )

 (defun num->sta ( n )
   (cond
     ( (<= 1000 n)
       (strcat
         ( (lambda ( s ) (substr s 1 (- (strlen s) 3)))
           (vl-string-left-trim "0+" (num->sta (fix (/ n 1000.0))))
         )
         (substr (num->sta (rem n 1000.0)) 2)
       )
     )
     ( t
       (strcat "0+"
         ( (lambda ( s ) (while (< (strlen s) 6) (setq s (strcat "0" s))) s)
           (rtos n 2 2)
         )
       )
     )
   )
 )
 (setq d (getvar 'DIMZIN))
 (setvar 'DIMZIN 0)
 (setq n (num->sta n))
 (setvar 'DIMZIN d)
 n
)

Its annoying that rtos is affected by DIMZIN, in the past I have written a workaround rtos function:

 

;;------------------------=={ rtos }==------------------------;;
;;                                                            ;;
;;  Subfunction designed to produce a consistent rtos return, ;;
;;  independent of the DIMZIN System Variable.                ;;
;;                                                            ;;
;;  [ Currently restricted to Decimal Format only ]           ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  real - real number to convert to a string                 ;;
;;  prec - precision to which the real should be displayed    ;;
;;------------------------------------------------------------;;
;;  Returns:  String representing the supplied real           ;;
;;------------------------------------------------------------;;

(defun LM:rtos ( real prec )
 (
   (lambda ( l )
     (repeat (- prec (cond ( (vl-position 46 l) ) ( (setq l (cons 46 l)) 0 )))
       (setq l (cons 48 l))
     )
     (vl-string-right-trim "."
       (vl-list->string
         (cond
           ( (= 46 (car (setq l (reverse l))))
             (cons 48 l)
           )
           ( (and (= 45 (car l)) (= 46 (cadr l)))
             (cons 45 (cons 48 (cdr l)))
           )
           ( l )
         )
       )
     )
   )
   (reverse (vl-string->list (rtos real 2 prec)))
 )
)

But it seemed easier to change the System Variable for this task.

 

Lee

Link to comment
Share on other sites

Hi irneb

 

Glad you went overboard cause its working well.

 

When i look at all the help coming through i see i have alot to learn in autolisp.

 

Cheers to all who helped out

Link to comment
Share on other sites

You're welcome! Great to get something working!

 

Lee, yep I suppose the DimZin would be a much simpler solution. I was actually looking for something in ActiveX - like you get in C++'s format function. This code would have been extremely simple if the rtos had an option to format with thousand separators. But I can't seem to find any such???

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...