bijoyvm Posted October 18, 2010 Share Posted October 18, 2010 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.... Quote Link to comment Share on other sites More sharing options...
eldon Posted October 18, 2010 Share Posted October 18, 2010 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. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted October 18, 2010 Share Posted October 18, 2010 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. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted October 18, 2010 Share Posted October 18, 2010 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. Quote Link to comment Share on other sites More sharing options...
bijoyvm Posted October 18, 2010 Author Share Posted October 18, 2010 Thanks eldon and Buzzard now its working Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 18, 2010 Share Posted October 18, 2010 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) ) ) ) Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted October 18, 2010 Share Posted October 18, 2010 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! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 18, 2010 Share Posted October 18, 2010 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) ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 18, 2010 Share Posted October 18, 2010 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))) ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 18, 2010 Share Posted October 18, 2010 By the way, I meant to ask, how is your learning of VL going? Quote Link to comment Share on other sites More sharing options...
alanjt Posted October 18, 2010 Share Posted October 18, 2010 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 ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.