<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Export to excel table all objects from specific layer in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-to-excel-table-all-objects-from-specific-layer/m-p/8337483#M98125</link>
    <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;Someone can help me with a code (lsp, vba, etc.) .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I want to export into excel table (in acad or file xls or csv) Total Lengths of specific Line Types, Cumulative Areas from specific hatch (by color or pattern)&amp;nbsp; and Total Number of blocks (by name)...all objects are in a single layer (My Layer).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class="short_text"&gt;I attach a autocad file for example&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class="short_text"&gt;Thank you for your time&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Oct 2018 12:47:25 GMT</pubDate>
    <dc:creator>mihai_bantas</dc:creator>
    <dc:date>2018-10-16T12:47:25Z</dc:date>
    <item>
      <title>Export to excel table all objects from specific layer</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-to-excel-table-all-objects-from-specific-layer/m-p/8337483#M98125</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;Someone can help me with a code (lsp, vba, etc.) .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I want to export into excel table (in acad or file xls or csv) Total Lengths of specific Line Types, Cumulative Areas from specific hatch (by color or pattern)&amp;nbsp; and Total Number of blocks (by name)...all objects are in a single layer (My Layer).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class="short_text"&gt;I attach a autocad file for example&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class="short_text"&gt;Thank you for your time&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 12:47:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-to-excel-table-all-objects-from-specific-layer/m-p/8337483#M98125</guid>
      <dc:creator>mihai_bantas</dc:creator>
      <dc:date>2018-10-16T12:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: Export to excel table all objects from specific layer</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-to-excel-table-all-objects-from-specific-layer/m-p/8421273#M98126</link>
      <description>&lt;P&gt;I hope it helps.&lt;BR /&gt;Let us know if it worked.&lt;/P&gt;
&lt;P&gt;Best Regards, Luís Augusto&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun C:TEST ()

  ;; Write CSV  -  Lee Mac
  ;; Writes a matrix list of cell values to a CSV file.
  ;; lst - [lst] list of lists, sublist is row of cell values
  ;; csv - [str] filename of CSV file to write
  ;; Returns T if successful, else nil

  (defun LM:writecsv (lst csv / des sep)
    (if	(setq des (open csv "w"))
      (progn
	(setq sep
	       (cond ((vl-registry-read
			"HKEY_CURRENT_USER\\Control Panel\\International"
			"sList"
		      )
		     )
		     (",")
	       )
	)
	(foreach row lst (write-line (LM:lst-&amp;gt;csv row sep) des))
	(close des)
	t
      )
    )
  )

  ;; List -&amp;gt; CSV  -  Lee Mac
  ;; Concatenates a row of cell values to be written to a CSV file.
  ;; lst - [lst] list containing row of CSV cell values
  ;; sep - [str] CSV separator token

  (defun LM:lst-&amp;gt;csv (lst sep)
    (if	(cdr lst)
      (strcat (LM:csv-addquotes (car lst) sep)
	      sep
	      (LM:lst-&amp;gt;csv (cdr lst) sep)
      )
      (LM:csv-addquotes (car lst) sep)
    )
  )

  (defun LM:csv-addquotes (str sep / pos)
    (cond
      ((wcmatch str (strcat "*[`" sep "\"]*"))
       (setq pos 0)
       (while (setq pos (vl-string-position 34 str pos))
	 (setq str (vl-string-subst "\"\"" "\"" str pos)
	       pos (+ pos 2)
	 )
       )
       (strcat "\"" str "\"")
      )
      (str)
    )
  )

  ;; Insert Nth  -  Lee Mac
  ;; Inserts an item at the nth position in a list.
  ;; x - [any] Item to be inserted
  ;; n - [int] Zero-based index at which to insert item
  ;; l - [lst] List in which item is to be inserted

  (defun LM:insertnth (x n l)
    (cond
      ((null l) nil)
      ((&amp;lt; 0 n) (cons (car l) (LM:insertnth x (1- n) (cdr l))))
      ((cons x l))
    )
  )

  	(defun openfile (file / sh)
    (setq sh (vla-getinterfaceobject
	       (vlax-get-acad-object)
	       "Shell.Application"
	     )
    )
    (vlax-invoke-method sh 'open (findfile file))
    (vlax-release-object sh)
  )


  (defun GetCurveLength	(ent /)
    (setq ent (vlax-ename-&amp;gt;vla-object ent))
    (vlax-curve-getDistAtParam
      ent
      (vlax-curve-getEndParam ent)
    )
  )

  (setq	lineList '(
		   "FENCELINE1"
		   "FENCELINE2"
		   "GAS_LINE"
		   "HOT_WATER_SUPPLY"
		  )
  )

  (setq	lineList
	 (mapcar
	   '(lambda (lineStyle)
	      (if (setq
		    ss (ssget "_X"
			      (list '(0 . "*LINE") (cons 6 lineStyle))
		       )
		  )
		(progn
		  (setq	index 0
			totalObj 0
		  )
		  (repeat (sslength ss)
		    (setq totalObj
			   (+ totalObj (GetCurveLength (ssname ss index)))
		    )
		    (setq index (1+ index))
		  )
		  (list lineStyle (rtos totalObj 2))
		)
	      )
	    )
	   lineList
	 )
  )

  (setq	lineList (LM:insertnth
		   (list "Line List" "------------------")
		   0
		   lineList
		 )
  )

  (setq bom lineList)

  ;-----------------------------------------

  (setq	blockList '(
		    "oooo"
		    "bbbb"
		   )
  )

  (setq	blockList
	 (mapcar
	   '(lambda (blkName)
	      (if (setq
		    ss (ssget "_X"
			      (list '(0 . "INSERT") (cons 2 blkName))
		       )
		  )
		(progn
		  (setq	index	 0
			totalObj (sslength ss)
		  )
		  (list blkName (rtos totalObj 2))
		)
	      )
	    )
	   blockList
	 )
  )

  (setq	blockList (LM:insertnth
		    (list "Block List" "------------------")
		    0
		    blockList
		  )
  )

  (setq bom (append bom blockList))

  ;-----------------------------------------

  (setq	hatchColorList
	 '(
	   30
	   152
	  )
  )

  (setq	hatchColorList
	 (mapcar
	   '(lambda (color)
	      (if (setq
		    ss (ssget "_X"
			      (list '(0 . "HATCH") (cons 62 color))
		       )
		  )
		(progn
		  (setq	index 0
			totalObj 0
		  )
		  (repeat (sslength ss)
		    (setq ent (vlax-ename-&amp;gt;vla-object
				(cdr (assoc -1 (entget (ssname ss index))))
			      )
		    )
		    (setq totalObj
			   (+ totalObj (vla-get-area ent))
		    )
		    (setq index (1+ index))
		  )
		  (list	(strcat "HatchColor_" (rtos color 2 00))
			(strcat
			  "Area = "
			  (if (or (= (getvar "lunits") 3)
				  (= (getvar "lunits") 4)
			      )
			    (strcat
			      (rtos totalObj 2)
			      " sq. in. ("
			      (rtos (/ totalObj 144) 2)
			      " sq. ft.)"
			    )
			    (rtos totalObj)
			  )
			)
		  )
		)
	      )
	    )
	   hatchColorList
	 )
  )

  (setq	hatchColorList
	 (LM:insertnth
	   (list "Hatch List" "------------------")
	   0
	   hatchColorList
	 )
  )

  (setq bom (append bom hatchColorList))

  ;-----------------------------------------

  (LM:writecsv bom (strcat (getvar 'DWGPREFIX) "BOM.csv"))
  (openfile  (strcat (getvar 'DWGPREFIX) "BOM.csv"))

)
(vl-load-com) (princ "TEST")&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Nov 2018 20:42:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-to-excel-table-all-objects-from-specific-layer/m-p/8421273#M98126</guid>
      <dc:creator>Luís Augusto</dc:creator>
      <dc:date>2018-11-23T20:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Export to excel table all objects from specific layer</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-to-excel-table-all-objects-from-specific-layer/m-p/8423753#M98127</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;C&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1944557"&gt;@Luís&amp;nbsp;Augusto&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I hope it helps.&lt;BR /&gt;Let us know if it worked.&lt;/P&gt;
&lt;P&gt;Best Regards, Luís Augusto&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun C:TEST ()

  ;; Write CSV  -  Lee Mac
  ;; Writes a matrix list of cell values to a CSV file.
  ;; lst - [lst] list of lists, sublist is row of cell values
  ;; csv - [str] filename of CSV file to write
  ;; Returns T if successful, else nil

  (defun LM:writecsv (lst csv / des sep)
    (if	(setq des (open csv "w"))
      (progn
	(setq sep
	       (cond ((vl-registry-read
			"HKEY_CURRENT_USER\\Control Panel\\International"
			"sList"
		      )
		     )
		     (",")
	       )
	)
	(foreach row lst (write-line (LM:lst-&amp;gt;csv row sep) des))
	(close des)
	t
      )
    )
  )

  ;; List -&amp;gt; CSV  -  Lee Mac
  ;; Concatenates a row of cell values to be written to a CSV file.
  ;; lst - [lst] list containing row of CSV cell values
  ;; sep - [str] CSV separator token

  (defun LM:lst-&amp;gt;csv (lst sep)
    (if	(cdr lst)
      (strcat (LM:csv-addquotes (car lst) sep)
	      sep
	      (LM:lst-&amp;gt;csv (cdr lst) sep)
      )
      (LM:csv-addquotes (car lst) sep)
    )
  )

  (defun LM:csv-addquotes (str sep / pos)
    (cond
      ((wcmatch str (strcat "*[`" sep "\"]*"))
       (setq pos 0)
       (while (setq pos (vl-string-position 34 str pos))
	 (setq str (vl-string-subst "\"\"" "\"" str pos)
	       pos (+ pos 2)
	 )
       )
       (strcat "\"" str "\"")
      )
      (str)
    )
  )

  ;; Insert Nth  -  Lee Mac
  ;; Inserts an item at the nth position in a list.
  ;; x - [any] Item to be inserted
  ;; n - [int] Zero-based index at which to insert item
  ;; l - [lst] List in which item is to be inserted

  (defun LM:insertnth (x n l)
    (cond
      ((null l) nil)
      ((&amp;lt; 0 n) (cons (car l) (LM:insertnth x (1- n) (cdr l))))
      ((cons x l))
    )
  )

  	(defun openfile (file / sh)
    (setq sh (vla-getinterfaceobject
	       (vlax-get-acad-object)
	       "Shell.Application"
	     )
    )
    (vlax-invoke-method sh 'open (findfile file))
    (vlax-release-object sh)
  )


  (defun GetCurveLength	(ent /)
    (setq ent (vlax-ename-&amp;gt;vla-object ent))
    (vlax-curve-getDistAtParam
      ent
      (vlax-curve-getEndParam ent)
    )
  )

  (setq	lineList '(
		   "FENCELINE1"
		   "FENCELINE2"
		   "GAS_LINE"
		   "HOT_WATER_SUPPLY"
		  )
  )

  (setq	lineList
	 (mapcar
	   '(lambda (lineStyle)
	      (if (setq
		    ss (ssget "_X"
			      (list '(0 . "*LINE") (cons 6 lineStyle))
		       )
		  )
		(progn
		  (setq	index 0
			totalObj 0
		  )
		  (repeat (sslength ss)
		    (setq totalObj
			   (+ totalObj (GetCurveLength (ssname ss index)))
		    )
		    (setq index (1+ index))
		  )
		  (list lineStyle (rtos totalObj 2))
		)
	      )
	    )
	   lineList
	 )
  )

  (setq	lineList (LM:insertnth
		   (list "Line List" "------------------")
		   0
		   lineList
		 )
  )

  (setq bom lineList)

  ;-----------------------------------------

  (setq	blockList '(
		    "oooo"
		    "bbbb"
		   )
  )

  (setq	blockList
	 (mapcar
	   '(lambda (blkName)
	      (if (setq
		    ss (ssget "_X"
			      (list '(0 . "INSERT") (cons 2 blkName))
		       )
		  )
		(progn
		  (setq	index	 0
			totalObj (sslength ss)
		  )
		  (list blkName (rtos totalObj 2))
		)
	      )
	    )
	   blockList
	 )
  )

  (setq	blockList (LM:insertnth
		    (list "Block List" "------------------")
		    0
		    blockList
		  )
  )

  (setq bom (append bom blockList))

  ;-----------------------------------------

  (setq	hatchColorList
	 '(
	   30
	   152
	  )
  )

  (setq	hatchColorList
	 (mapcar
	   '(lambda (color)
	      (if (setq
		    ss (ssget "_X"
			      (list '(0 . "HATCH") (cons 62 color))
		       )
		  )
		(progn
		  (setq	index 0
			totalObj 0
		  )
		  (repeat (sslength ss)
		    (setq ent (vlax-ename-&amp;gt;vla-object
				(cdr (assoc -1 (entget (ssname ss index))))
			      )
		    )
		    (setq totalObj
			   (+ totalObj (vla-get-area ent))
		    )
		    (setq index (1+ index))
		  )
		  (list	(strcat "HatchColor_" (rtos color 2 00))
			(strcat
			  "Area = "
			  (if (or (= (getvar "lunits") 3)
				  (= (getvar "lunits") 4)
			      )
			    (strcat
			      (rtos totalObj 2)
			      " sq. in. ("
			      (rtos (/ totalObj 144) 2)
			      " sq. ft.)"
			    )
			    (rtos totalObj)
			  )
			)
		  )
		)
	      )
	    )
	   hatchColorList
	 )
  )

  (setq	hatchColorList
	 (LM:insertnth
	   (list "Hatch List" "------------------")
	   0
	   hatchColorList
	 )
  )

  (setq bom (append bom hatchColorList))

  ;-----------------------------------------

  (LM:writecsv bom (strcat (getvar 'DWGPREFIX) "BOM.csv"))
  (openfile  (strcat (getvar 'DWGPREFIX) "BOM.csv"))

)
(vl-load-com) (princ "TEST")&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;&lt;BR /&gt;ode goes perfect ... Luís Augusto thank you&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;I wish you a beautiful day&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 07:11:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-to-excel-table-all-objects-from-specific-layer/m-p/8423753#M98127</guid>
      <dc:creator>mihai_bantas</dc:creator>
      <dc:date>2018-11-26T07:11:24Z</dc:date>
    </item>
  </channel>
</rss>

