Jump to content

MIssing .000


bijoyvm

Recommended Posts

hi

im trying to create a station elevation lisp

 

but im facing a problem 0 digits are missing

for example

 

if (setq elev 125.125)

(setq text (rtos elev 2 3))

 

!text = "125.125"

 

but (setq elev 125.000)

(setq text (rtos elev 2 3))

 

!text = "125" ( I need "125.000" like this)

 

how can I solve this problem....

Link to comment
Share on other sites

Or you could make sure the system variable DIMZIN is set to the correct value

 

 

 

DIMZIN System Variable 
Type: Integer
Saved in: Drawing
Initial value: 0
Controls the suppression of zeros in the primary unit value. DIMZIN stores this 
value when you enter it on the command line or set it under Primary Units in 
the Annotation dialog box. DIMZIN values 0-3 affect feet-and-inch dimensions only.

0  Suppresses zero feet and precisely zero inches
1  Includes zero feet and precisely zero inches
2  Includes zero feet and suppresses zero inches
3  Includes zero inches and suppresses zero feet
4  Suppresses leading zeros in decimal dimensions (for example, 0.5000 becomes .5000)
8  Suppresses trailing zeros in decimal dimensions (for example, 12.5000 becomes 12.5)
12  Suppresses both leading and trailing zeros (for ex-ample, 0.5000 becomes 0.5)

DIMZIN also affects real-to-string conversions performed by the AutoLISP rtos and angtos functions.

 

Link to comment
Share on other sites

Or you could make sure the system variable DIMZIN is set to the correct value

 

 

 

DIMZIN System Variable 
Type: Integer
Saved in: Drawing
Initial value: 0
Controls the suppression of zeros in the primary unit value. DIMZIN stores this 
value when you enter it on the command line or set it under Primary Units in 
the Annotation dialog box. DIMZIN values 0-3 affect feet-and-inch dimensions only.

0 Suppresses zero feet and precisely zero inches
1 Includes zero feet and precisely zero inches
2 Includes zero feet and suppresses zero inches
3 Includes zero inches and suppresses zero feet
4 Suppresses leading zeros in decimal dimensions (for example, 0.5000 becomes .5000)
8 Suppresses trailing zeros in decimal dimensions (for example, 12.5000 becomes 12.5)
12 Suppresses both leading and trailing zeros (for ex-ample, 0.5000 becomes 0.5)

DIMZIN also affects real-to-string conversions performed by the AutoLISP rtos and angtos functions.

 

Thats true eldon, It would change the current dimstyle you set it to. That also would need to be taken into consideration when changing it especially through a program. Probably would need to save the original dimzin at the beginning of the program and set it later in the program, Then restore it when exiting.

 

It would all depend on if using the dimstyle later for dimensioning. But if done correctly through the program, not a big deal.

Link to comment
Share on other sites

eldon,

 

Actually after testing alanjt"s routine and adjusting dimzin, It had an effect on the output or the function by alan would not work in this case. It seems likely that dimzin would override this, So if getting correct output from the program and avoiding permenant setting changes, You would in fact need to consider saving, changing and restoring this variable. If using this to place text in the drawing and once placed, DIMZIN does not effect the placed text.

 

Good Call, I learned something today.

Link to comment
Share on other sites

I suppose this could constitute a solution which avoids changing DIMZIN:

 

(defun LM:rtos ( real prec / _padright ) (vl-load-com)
 ;; © Lee Mac 2010

 (defun _padright ( str char len )
   (if (< (strlen str) len) (_padright (strcat str char) char len) str)
 )
 
 (strcat (itoa (fix real))
   (_padright
     (vl-string-left-trim "0" (rtos (abs (rem real 1)) 2 prec)) "0" (1+ prec)
   )
 )
)

Link to comment
Share on other sites

I suppose this could constitute a solution which avoids changing DIMZIN:

 

(defun LM:rtos ( real prec / _padright ) (vl-load-com)
;; © Lee Mac 2010

(defun _padright ( str char len )
(if (< (strlen str) len) (_padright (strcat str char) char len) str)
)

(strcat (itoa (fix real))
(_padright
(vl-string-left-trim "0" (rtos (abs (rem real 1)) 2 prec)) "0" (1+ prec)
)
)
)

 

Works great Lee!

Link to comment
Share on other sites

Thanks Buzzard :)

 

EDIT: Found a small glitch:

 

(LM:rtos 3.400 0)
"30"

 

Fixed:

 

(defun LM:rtos ( real prec / _padright ) (vl-load-com)
 ;; © Lee Mac 2010

 (defun _padright ( str char len )
   (if (< (strlen str) len) (_padright (strcat str char) char len) str)
 )
 (
   (lambda ( dec )
     (strcat (itoa (fix real)) (if (eq "" dec) "" ".") dec)
   )
   (_padright (vl-string-left-trim ".0" (rtos (abs (rem real 1)) 2 prec)) "0" prec)
 )
)

Link to comment
Share on other sites

Actually this is most probably quicker:

 

(defun LM:rtos ( real prec ) (vl-load-com)
 (
   (lambda ( l )
     (repeat (- prec (cond ( (vl-position 46 l) ) ( 0 )))
       (setq l (cons 48 l))
     )      
     (vl-list->string (if (= 46 (car (setq l (reverse l)))) (cons 48 l) l))
   )
   (reverse (vl-string->list (rtos real 2 prec)))
 )
)

Link to comment
Share on other sites

Still has to reset dimzin variable, but doesn't disrupt architectural units.

(defun foo (num prec / dim)
 (and (setq dim (getvar 'dimzin)) (setvar 'dimzin 0))
 (setq num (cond ((numberp num)
                  (rtos num
                        (getvar 'lunits)
                        (cond ((numberp prec) prec)
                              ((getvar 'luprec))
                        )
                  )
                 )
           )
 )
 (and dim (setvar 'dimzin dim))
 num
)

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