Jump to content

exporting in a specular format


MajorTom

Recommended Posts

best would be to save the right format to begin with but assuming you're already stuck with one :


; (chop '(1 2 3 4 5 6 7 8 9) 4) -> '((1 2 3 4) (5 6 7 8) (9))
(defun chop (l n / tl fl) (cond ((or (null l) (null n) (not (vl-consp l)) (not (numberp n)))) ((< (length l) n) l)
  (t (while (vl-consp l) (setq tl (cons (car l) tl))(if (= n (length tl))(setq fl (cons tl fl) tl nil))
       (if (and (not (vl-consp (setq l (cdr l))))(vl-consp tl))(setq fl (cons tl fl)))))) (reverse (mapcar 'reverse fl)))


; convert
(defun convert_csv_file (fn-in / fp-in fnl fn-out fp-out dat item lst)
  (if (and fn-in (findfile fn-in) (setq fp-in (open fn-in "r")) (setq fnl (fnsplitl fn-in))
           (setq fn-out (strcat (car fnl) (cadr fnl) " MB" (last fnl))) (setq fp-out (open fn-out "w")))
    (progn
      ; first read entire file and put it in a list
      (while (setq dat (read-line fp-in))(setq lst (cons dat lst)))
      ; now chop-up list in pieces of 6 (based on posted example)
      (setq lst (chop (reverse lst) 6))
      ; org format posted :
      ;   MT-AR-FC-01-TW-GN-CD-0312 + 30.09.2019 + 1/2 + 0 + FT01 TYPICAL DETAIL 311 + ""
      ; desired format :
      ;   Drawing Number;Drawing Name;Date;Revision Number
      ;   MT-AR-FC-01-TW-GN-CD-0312;FT01 TYPICAL DETAIL 311;30.09.2019;0

      ; first save header
      (write-line "Drawing Number;Drawing Name;Date;Revision Number" fp-out)
      ; now write chopped up list
      ; we need item_0 + ";" + item_4 + ";" + item_1 + ";" + item_3
      (foreach item lst
        (write-line (strcat (nth 0 item) ";" (nth 4 item) ";" (nth 1 item) ";" (nth 3 item)) fp-out)
      )
      (close fp-in)(close fp-out)(gc)
      (startapp "notepad" fn-out)
    )
  )
  (princ)
)

(defun c:t1 ( / fn)
  (if (setq fn (getfiled "select source csv file" "" "csv" 0)) (convert_csv_file fn))
  (princ)
)


🐉

Link to comment
Share on other sites

haven't tested this one (since I have no drawing to test it on)


(defun c:t2 (/ *error* f o e ss i sn atl)
  (defun *error* (msg) (if o (close o)) (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")
    (princ msg) (princ (strcat "\n ** Error : " msg " **"))))
  (if (and (setq ss (ssget "X" '((0 . "INSERT") (66 . 1) (2 . "A1 ANTET"))))
           (setq f (getfiled "Specify Excel file name" (getvar 'dwgprefix) "csv" 1)) (setq o (open f "w")))
    (progn
      ; write header "Drawing Number;Drawing Name;Date;Revision Number"
      (write-line "Drawing Number;Drawing Name;Date;Revision Number" o)
      (repeat (setq i (sslength ss))
        (setq atl '() sn (ssname ss (setq i (1- i))))
        (while (and (setq sn (entnext sn)) (/= (cdr (assoc 0 (setq e (entget sn)))) "SEQEND"))
          (if (eq (cdr (assoc 0 e)) "ATTRIB")(setq atl (cons (cdr (assoc 1 e)) atl))))
        ; format posted   : (0) MT-AR-FC-01-TW-GN-CD-0312, (1) 30.09.2019, (2) 1/2, (3) 0, (4) FT01 TYPICAL DETAIL 311, (5)""
        ; format desired  : MT-AR-FC-01-TW-GN-CD-0312;FT01 TYPICAL DETAIL 311;30.09.2019;0
        (if (vl-consp atl) (write-line (strcat (nth 0 atl) ";" (nth 4 atl) ";" (nth 1 atl) ";" (nth 3 atl)) o))
      )
    )
  )
  (if o (close o))
  (gc)
  (princ)
)

🐉

Link to comment
Share on other sites

12 hours ago, rlx said:

best would be to save the right format to begin with but assuming you're already stuck with one :

 

This isn't worked :( 

 

Quote

 


; (chop '(1 2 3 4 5 6 7 8 9) 4) -> '((1 2 3 4) (5 6 7 8) (9))
(defun chop (l n / tl fl) (cond ((or (null l) (null n) (not (vl-consp l)) (not (numberp n)))) ((< (length l) n) l)
  (t (while (vl-consp l) (setq tl (cons (car l) tl))(if (= n (length tl))(setq fl (cons tl fl) tl nil))
       (if (and (not (vl-consp (setq l (cdr l))))(vl-consp tl))(setq fl (cons tl fl)))))) (reverse (mapcar 'reverse fl)))


; convert
(defun convert_csv_file (fn-in / fp-in fnl fn-out fp-out dat item lst)
  (if (and fn-in (findfile fn-in) (setq fp-in (open fn-in "r")) (setq fnl (fnsplitl fn-in))
           (setq fn-out (strcat (car fnl) (cadr fnl) " MB" (last fnl))) (setq fp-out (open fn-out "w")))
    (progn
      ; first read entire file and put it in a list
      (while (setq dat (read-line fp-in))(setq lst (cons dat lst)))
      ; now chop-up list in pieces of 6 (based on posted example)
      (setq lst (chop (reverse lst) 6))
      ; org format posted :
      ;   MT-AR-FC-01-TW-GN-CD-0312 + 30.09.2019 + 1/2 + 0 + FT01 TYPICAL DETAIL 311 + ""
      ; desired format :
      ;   Drawing Number;Drawing Name;Date;Revision Number
      ;   MT-AR-FC-01-TW-GN-CD-0312;FT01 TYPICAL DETAIL 311;30.09.2019;0

      ; first save header
      (write-line "Drawing Number;Drawing Name;Date;Revision Number" fp-out)
      ; now write chopped up list
      ; we need item_0 + ";" + item_4 + ";" + item_1 + ";" + item_3
      (foreach item lst
        (write-line (strcat (nth 0 item) ";" (nth 4 item) ";" (nth 1 item) ";" (nth 3 item)) fp-out)
      )
      (close fp-in)(close fp-out)(gc)
      (startapp "notepad" fn-out)
    )
  )
  (princ)
)

(defun c:t1 ( / fn)
  (if (setq fn (getfiled "select source csv file" "" "csv" 0)) (convert_csv_file fn))
  (princ)
)


🐉

On 10/1/2019 at 6:56 PM, Lee Mac said:

Have you tried using the standard AutoCAD DATAEXTRACTION command?

 

On 10/2/2019 at 5:01 AM, BIGAL said:

Another simple is a lisp extract attributes to csv file. Just search.

 

12 hours ago, rlx said:

best would be to save the right format to begin with but assuming you're already stuck with one :

 


; (chop '(1 2 3 4 5 6 7 8 9) 4) -> '((1 2 3 4) (5 6 7 8) (9))
(defun chop (l n / tl fl) (cond ((or (null l) (null n) (not (vl-consp l)) (not (numberp n)))) ((< (length l) n) l)
  (t (while (vl-consp l) (setq tl (cons (car l) tl))(if (= n (length tl))(setq fl (cons tl fl) tl nil))
       (if (and (not (vl-consp (setq l (cdr l))))(vl-consp tl))(setq fl (cons tl fl)))))) (reverse (mapcar 'reverse fl)))


; convert
(defun convert_csv_file (fn-in / fp-in fnl fn-out fp-out dat item lst)
  (if (and fn-in (findfile fn-in) (setq fp-in (open fn-in "r")) (setq fnl (fnsplitl fn-in))
           (setq fn-out (strcat (car fnl) (cadr fnl) " MB" (last fnl))) (setq fp-out (open fn-out "w")))
    (progn
      ; first read entire file and put it in a list
      (while (setq dat (read-line fp-in))(setq lst (cons dat lst)))
      ; now chop-up list in pieces of 6 (based on posted example)
      (setq lst (chop (reverse lst) 6))
      ; org format posted :
      ;   MT-AR-FC-01-TW-GN-CD-0312 + 30.09.2019 + 1/2 + 0 + FT01 TYPICAL DETAIL 311 + ""
      ; desired format :
      ;   Drawing Number;Drawing Name;Date;Revision Number
      ;   MT-AR-FC-01-TW-GN-CD-0312;FT01 TYPICAL DETAIL 311;30.09.2019;0

      ; first save header
      (write-line "Drawing Number;Drawing Name;Date;Revision Number" fp-out)
      ; now write chopped up list
      ; we need item_0 + ";" + item_4 + ";" + item_1 + ";" + item_3
      (foreach item lst
        (write-line (strcat (nth 0 item) ";" (nth 4 item) ";" (nth 1 item) ";" (nth 3 item)) fp-out)
      )
      (close fp-in)(close fp-out)(gc)
      (startapp "notepad" fn-out)
    )
  )
  (princ)
)

(defun c:t1 ( / fn)
  (if (setq fn (getfiled "select source csv file" "" "csv" 0)) (convert_csv_file fn))
  (princ)
)


🐉

 

11 hours ago, rlx said:

haven't tested this one (since I have no drawing to test it on)

This can be helpful but onlly running in current layout I wanna same thng to all layouts


(defun c:t2 (/ *error* f o e ss i sn atl)
  (defun *error* (msg) (if o (close o)) (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")
    (princ msg) (princ (strcat "\n ** Error : " msg " **"))))
  (if (and (setq ss (ssget "X" '((0 . "INSERT") (66 . 1) (2 . "A1 ANTET"))))
           (setq f (getfiled "Specify Excel file name" (getvar 'dwgprefix) "csv" 1)) (setq o (open f "w")))
    (progn
      ; write header "Drawing Number;Drawing Name;Date;Revision Number"
      (write-line "Drawing Number;Drawing Name;Date;Revision Number" o)
      (repeat (setq i (sslength ss))
        (setq atl '() sn (ssname ss (setq i (1- i))))
        (while (and (setq sn (entnext sn)) (/= (cdr (assoc 0 (setq e (entget sn)))) "SEQEND"))
          (if (eq (cdr (assoc 0 e)) "ATTRIB")(setq atl (cons (cdr (assoc 1 e)) atl))))
        ; format posted   : (0) MT-AR-FC-01-TW-GN-CD-0312, (1) 30.09.2019, (2) 1/2, (3) 0, (4) FT01 TYPICAL DETAIL 311, (5)""
        ; format desired  : MT-AR-FC-01-TW-GN-CD-0312;FT01 TYPICAL DETAIL 311;30.09.2019;0
        (if (vl-consp atl) (write-line (strcat (nth 0 atl) ";" (nth 4 atl) ";" (nth 1 atl) ";" (nth 3 atl)) o))
      )
    )
  )
  (if o (close o))
  (gc)
  (princ)
)

 

🐉

 

Edited by MajorTom
Link to comment
Share on other sites

couldn't have said it better Bigal :danger:  hahaha 😄

 

so SSDD (same s..t , different day) : untested (and also have other work to do)

 

(defun c:t3 (/ *error* f o e ss i sn atl)
  (defun *error* (msg) (if o (close o)) (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")
    (princ msg) (princ (strcat "\n ** Error : " msg " **"))))
  (cond
    ((not (setq f (getfiled "Specify Excel file name" (getvar 'dwgprefix) "csv" 1)))
     (alert "No csv file was specified"))
    ((not (setq o (open f "w")))
     (alert "Unable to write to csv file"))
    (t
     (write-line "Drawing Number;Drawing Name;Date;Revision Number" o)
     (foreach lay (cons "Model" (layoutlist))
       (setvar "CTAB" lay)
       (if (setq ss (ssget "X" (list '(0 . "INSERT") '(66 . 1) '(2 . "A1 ANTET") (cons 410 (getvar "CTAB")))))
         (repeat (setq i (sslength ss))
           (setq atl '() sn (ssname ss (setq i (1- i))))
           (while (and (setq sn (entnext sn)) (/= (cdr (assoc 0 (setq e (entget sn)))) "SEQEND"))
             (if (eq (cdr (assoc 0 e)) "ATTRIB")(setq atl (cons (cdr (assoc 1 e)) atl))))
           (if (vl-consp atl) (write-line (strcat (nth 0 atl) ";" (nth 4 atl) ";" (nth 1 atl) ";" (nth 3 atl)) o))
         )
       )
       (setq ss nil)
     )
    )
  )
  (if o (close o))(gc)(startapp "notepad" f)
  (princ)
)

 

🀄

Edited by rlx
Updated code after testing on test block from me , myself and I
  • Like 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...