Jump to content

Get block data coordinates without removing trailing zeros (fixed 4digit decimal numbers)


Recommended Posts

Posted

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

 

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

  • Like 1
Posted (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.

image.png.6ad61fd6274ff43de8cd5df89d1083a7.png

Edited by mhupp
  • Like 1

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