Jump to content

Extract Text override and Measure of Dimension to CSV file


A Tabasi

Recommended Posts

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 

Link to comment
Share on other sites

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)





 

  • Thanks 2
Link to comment
Share on other sites

  • 1 year later...

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! 
  

image.thumb.png.f114e4d6fd19a186a16d524203bde88d.png

    

 

Link to comment
Share on other sites

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

 

 

  • Thanks 1
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...