Dgoutz Posted May 25, 2021 Posted May 25, 2021 Good morning all. I have the following code to get specific block data/information from CAD drawings in an xls format. However, trailing zeros in the coordinates values are omitted and so I get data with different number of digits which subsequently give me trouble in editing these data. To give you an example, currently the lisp now provides me the following coordinates (values are random) x1= 500.05, y1=4543.991 x2= 513.3322, y2=4588 When I would like to have a fixed amount of digits (4 decimal digits) such as x1= 500.0500, y1=4543.9910 x2= 513.3322, y2=4588.0000 I tried the DIMZIN system variable but it seems to work only in inches/feet and all of my drawings are in millimeters (metric system). Does anyone have an idea on what can I do about it without editing the file in excel? (defun c:GiveMeYourData ( / _sort addtolist _concatenate opf ss csvFile e data atrb AllData) (defun _concatenate (lst) (apply 'strcat (mapcar '(lambda (st) (strcat st ",")) lst )) ) (Defun _sort (s l) (vl-sort l '(lambda (a b)(< (s a)(s b))))) (defun addtolist ( key val lst / old ) (if (setq old (assoc key lst)) (subst (append old (list val)) old lst) (cons (list key val) lst) ) ) (if (And (setq ss (ssget "_X" '((0 . "INSERT")))) (setq csvFile (getfiled "Output File" "" "csv" 1)) ) (progn (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (setq data (mapcar '(lambda (p)(vlax-get e p)) '("EffectiveName" "Handle" "InsertionPoint" "Rotation")) atrb (_sort car (mapcar '(lambda (at) (list (vla-get-tagstring at)(vla-get-textstring at))) (vlax-invoke e 'GetAttributes))) ) (setq AllData (addtolist (car data) (append (Cdr data) atrb) AllData)) ) (setq opf (open csvFile "w")) (setq AllData (_sort car AllData)) (while (setq a (car AllData)) (Foreach itm (cdr a) (write-line (_concatenate (apply 'append (list (list (car a)(car itm)) (mapcar 'rtos (Cadr itm)) (list (rtos (/ (* (Caddr itm) 180.0) pi) 2 0)) (apply 'append (cdddr itm)) ) ) ) opf ) ) (setq AllData (cdr AllData)) ) (Close opf) (startapp "explorer" csvFile) ) )(princ) ) Quote
eldon Posted May 25, 2021 Posted May 25, 2021 3 hours ago, Dgoutz said: ........... I tried the DIMZIN system variable but it seems to work only in inches/feet and all of my drawings are in millimeters (metric system). Does anyone have an idea on what can I do about it without editing the file in excel? What value did you use for the DIMZIN system variable? Try setting it to 0. 1 Quote
tombu Posted May 25, 2021 Posted May 25, 2021 Lee Mac's Consistent rtos function is what you're looking for: http://www.lee-mac.com/consistentrtos.html It doesn't require modifying any dimension system variables either. Command: (LM:rtos 500.05 2 4) "500.0500" Command: (LM:rtos 513.3322 2 4) "513.3322" 1 Quote
mhupp Posted May 25, 2021 Posted May 25, 2021 (edited) Like tombu said you need to change the precision of rtos to 4 (list (rtos (/ (* (Caddr itm) 180.0) pi) 2 4)) Also In Excel In the Format Cells dialog, under Number tab their is a place to select how many decimals you want to show. Edited May 25, 2021 by mhupp 1 Quote
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.