layout name to excel or csv

layout name to excel or csv

chan230984
Advocate Advocate
2,047 Views
12 Replies
Message 1 of 13

layout name to excel or csv

chan230984
Advocate
Advocate

hi all I have many layout but I want to send to Excel or csv

who can help me write some lisp

thanks

 

Untitled.png

0 Likes
Accepted solutions (1)
2,048 Views
12 Replies
Replies (12)
Message 2 of 13

Moshe-A
Mentor
Mentor
Accepted solution

@chan230984  hi,

 

check this on

 

enjoy

moshe

 

; Layout To Excel CSV

(defun c:lay2Csv (/ fname f)
 (setq fname (strcat (getvar "dwgprefix") (vl-filename-base (getvar "dwgname")) ".csv"))
 (if (setq f (open fname "w"))
  (progn
   (foreach lay (layoutlist)
    (write-line lay f)
   ); foreach

   (setq f (close f))
   (prompt (strcat "\nCreating " fname " file."))
  ); progn
 ); if

 (princ)	
)  
0 Likes
Message 3 of 13

lavarias.jayson.v
Participant
Participant

This works great, Is there a way to include dwg name on first column of excel?. Thank you in advance.

0 Likes
Message 4 of 13

kpblc2000
Advisor
Advisor
(vl-load-com)

(defun c:lay2csv (/ file handle layouts dwgname)
  (setq dwgname (strcat (getvar "dwgprefix") (getvar "dwgname"))
        file    (strcat (getvar "dwgprefix") (vl-filename-base (getvar "dwgname")) ".csv")
  ) ;_ end of setq
  (if (setq handle (open file "w"))
    (progn
      (setq layouts (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))))
      (write-line "File\tLayout name\tCount" handle)
      (foreach item (layoutlist)
        (write-line
          (strcat dwgname "\t" item "\t" (itoa (vla-get-count (vla-get-block (vla-item layouts item)))))
          handle
        ) ;_ end of write-line
      ) ;_ end of foreach
      (close handle)
      (princ (strcat "\nAll data saved to " file))
    ) ;_ end of progn
  ) ;_ end of if
  (princ)
) ;_ end of defun

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.


Алексей Кулик aka kpblc | Aleksei Kulik aka kpblc Facebook | LinkedIn
autolisp.ru
Техническая поддержка программистов Autodesk в СНГ
Библиотека пользовательских lisp-функций | Custom Lisp-function library

0 Likes
Message 5 of 13

lavarias.jayson.v
Participant
Participant

Thank you @kpblc2000  for your urgent response.

What I need is to reflect the dwg names on the first column and the layout names on the second column.

Will this be possible? Thank you.

lavariasjaysonv_0-1653986482538.png

 

0 Likes
Message 6 of 13

kpblc2000
Advisor
Advisor

You see I tried to add "entities range at layout" because empty layouts will contain 0 entities. And you can filter empty layouts. If you don't need it, try this one:

 

(vl-load-com)

(defun c:lay2csv (/ file handle layouts dwgname)
  (setq file (strcat (getvar "dwgprefix") (setq dwgname (vl-filename-base (getvar "dwgname"))) ".csv")
  ) ;_ end of setq
  (if (setq handle (open file "w"))
    (progn
      (write-line "File\tLayout name" handle) ; comment (place semicolon at the start of line) this line if you don't need table header
      (foreach item (layoutlist)
        (write-line (strcat dwgname "\t" item) handle)
      ) ;_ end of foreach
      (close handle)
      (princ (strcat "\nAll data saved to " file))
    ) ;_ end of progn
  ) ;_ end of if
  (princ)
) ;_ end of defun

P.S. I didn't check it

P.P.S. Sorry for my English

 

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.


Алексей Кулик aka kpblc | Aleksei Kulik aka kpblc Facebook | LinkedIn
autolisp.ru
Техническая поддержка программистов Autodesk в СНГ
Библиотека пользовательских lisp-функций | Custom Lisp-function library

0 Likes
Message 7 of 13

lavarias.jayson.v
Participant
Participant

Thanks @kpblc2000 

Here's the result of the program.

lavariasjaysonv_0-1653990443815.png

Filename and layout name shared the same column. It is possible to have the Filename on Column A and layout name on column B?

 

0 Likes
Message 8 of 13

kpblc2000
Advisor
Advisor

During import data to Excel try to select "Tab symbol" as a delimiter.

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.


Алексей Кулик aka kpblc | Aleksei Kulik aka kpblc Facebook | LinkedIn
autolisp.ru
Техническая поддержка программистов Autodesk в СНГ
Библиотека пользовательских lisp-функций | Custom Lisp-function library

Message 9 of 13

lavarias.jayson.v
Participant
Participant

@kpblc2000  Thanks.

where should I place the tab symbol on the program? pardon, I totally new with lisp program. Thanks.

0 Likes
Message 10 of 13

kpblc2000
Advisor
Advisor

Not at program. During importing.

You can replace

 

\t

symbol to any you want 🙂

 

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.


Алексей Кулик aka kpblc | Aleksei Kulik aka kpblc Facebook | LinkedIn
autolisp.ru
Техническая поддержка программистов Autodesk в СНГ
Библиотека пользовательских lisp-функций | Custom Lisp-function library

0 Likes
Message 11 of 13

lavarias.jayson.v
Participant
Participant

@kpblc2000 

 

Thanks a lot. Got It now 😊

0 Likes
Message 12 of 13

Sea-Haven
Mentor
Mentor

CSV Comma Seperated Values is not a csv file where a Tab is used as seperator in the true sense, understand why you did it that way.

SeaHaven_0-1654050013765.png

 

Its easy to do (write-line (strcat dwgname "," layoutname) handle) then no confusion. Also "," = (chr 44)

 

Just me "handle" is a valid Autocad reserved name so would not use it as a variable name. 

0 Likes
Message 13 of 13

kpblc2000
Advisor
Advisor

File name can contain commas so using comma as delimiter (i think) can't guarantee result.

About ""handle" is a valid Autocad reserved name" - never heard about it. Up to ACAD20221 this code work correctly.

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.


Алексей Кулик aka kpblc | Aleksei Kulik aka kpblc Facebook | LinkedIn
autolisp.ru
Техническая поддержка программистов Autodesk в СНГ
Библиотека пользовательских lisp-функций | Custom Lisp-function library

0 Likes