A Tabasi Posted July 29, 2021 Posted July 29, 2021 hi All I want to extract data of dimensions in file to csv. Specifically ''txt override'' and ''measure'' per dimension To be placed on a row please help me to create a lisp program or Another solution Quote
Tharwat Posted July 29, 2021 Posted July 29, 2021 Hi, Something like this? (defun c:Test (/ *error* int sel ent get ovr csv opn ) ;; Tharwat - 29.Jul.2021 ;; (defun *error* (msg) (and opn (close opn)) (and msg (not (wcmatch (strcase msg) "*CANCEL*,*EXIT*,*BREAK*")) (princ (strcat "\nError =>: " msg))) (princ "\nThis AutoLISP program was written by Tharwat Al Choufi") ) (and (setq int -1 sel (ssget '((0 . "*DIMENSION")))) (setq csv (getfiled "Save as ..." (getvar 'DWGPREFIX) "csv" 1)) (setq opn (open csv "w")) (write-line (strcat "Text Override" "," "Measurement") opn) (while (setq int (1+ int) ent (ssname sel int)) (setq get (entget ent)) (write-line (strcat (if (= (setq ovr (cdr (assoc 1 get))) "") "Null" ovr) "," (vl-princ-to-string (cdr (assoc 42 get)))) opn ) ) ) (*error* nil) (princ) ) (vl-load-com) 2 Quote
A Tabasi Posted July 29, 2021 Author Posted July 29, 2021 hi Cad guru that's great, You helped me the most I thank you with all my being Quote
icalara1921 Posted September 20, 2022 Posted September 20, 2022 Hi! This lisp works amazing, I came up with a similar problem though. We override several dimensions for productivity purposes. The fact is that all of those dimensions shares a format. The format is: FAB: Y=nn'-mm" (xx EA) The nn'-mm" & xx varies per each overridden dimension. Is it possible to extract only the information between the parenthesis? I have attached a snip. Thanks in advance! Quote
Steven P Posted September 21, 2022 Posted September 21, 2022 Try this one, (defun c:testthis ( / MySel MyFile CSVFile acount MyEnt Ent1 MyValue MySuffix) (vl-load-com) (if CSVFile (close CSVFile)) ;; Close 'CSVfile' in case it is open, prevents some errors (setq MyFile (getfiled "Save file as: " (getvar 'DWGPREFIX) "csv" 1)) ;; Select CSV file / make new CSV File (setq MySel (ssget '((0 . "*DIMENSION")))) ;; Select only dimensions (setq CSVFile (open MyFile "w")) ;; Open CSV File to write to (write-line (strcat "Test Override, Pieces, Measurement") CSVFile) ;; Write header row to file (setq acount 0) ;; Counter for while loop (while (< acount (sslength MySel)) ;; Loop for number of selected dimensions (setq MyEnt (entget (ssname MySel acount))) ;; get nth dimension entity data (setq Ent1 (cdr (assoc 1 MyEnt)) ) ;; assoc 1: text in dimension (setq MySuffix (substr Ent1 ( + (vl-string-search "(" Ent1) 1))) ;; get sub-string after '(' in Ent1 value (setq MyValue (vl-string-trim MySuffix Ent1)) (setq MyValue (vl-string-subst (vl-princ-to-string (cdr (assoc 42 MyEnt))) (strcat (chr 60) (chr 62)) MyValue)) ;; MyValue dimension text without '(...)', '42' is measured value (write-line (strcat MyValue ", " MySuffix ", " (vl-princ-to-string (cdr (assoc 42 MyEnt))) ) CSVFile) ;; write values to CSV file (setq acount (+ acount 1)) ;; Increase loop counter ) ; end while ;; end loop (close CSVFile) ;; close CSV file (princ) ) 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.