Jump to content

Export a table quantities from specific layer


mihaibantas

Recommended Posts

Hi all,
Someone can help me with a code (lsp, vba, etc.) .

 

I want to export a excel table to contain  (in acad or file xls or csv) Total Lengths of specific Linetype, Cumulative Areas of specific Hatch (by color or pattern)  and Total Number of blocks (by name)...all objects are in a single layer (My Layer).

 

I attach a autocad file for example

 

Thank you for your time

test.dwg

Link to comment
Share on other sites

Did you do any searching ? All the answers are here or available at other sites. 

 

You can pay me to do the searching if you want.

Edited by BIGAL
Link to comment
Share on other sites

Hi BIGAL,

Generally I do not talk until I do a thorough research in google, forums, etc ... and honestly I'm a little confused right now

I found on various forums two codes that I can not convert into one ... so I want to get the information I want from a single selection.

 

 

Thanks for your time. 

test.lsp

HATCHAREA.lsp

Link to comment
Share on other sites

 


;; total length by linetype
(defun total_length ( ss linetype / i enttype ltp ent total)
  (setq
    i 0
    total 0.0
  )
  (repeat (sslength ss)
    (setq ent (ssname ss i))
    ;; make sure it's a line or polyline
    (setq enttype (cdr (assoc 0  (entget ent))))
    (if (or (= enttype "LWPOLYLINE") (= enttype "POLYLINE") (= enttype "LINE")) (progn
        ;; see if the line type corresponds
        (setq ltp (cdr (assoc 6  (entget ent))))
        (if (= linetype ltp) (progn
          (setq total (+ total (vla-get-length (vlax-ename->vla-object ent))))
        ))
    ))
    (setq i (+ i 1))
  )
  total
)

(defun hatch_surface ( ss color ptrn / i total)
  (setq
    i 0
    total 0.0
  )
  (repeat (sslength ss)
    (setq ent (ssname ss i))
    ;; make sure it's a hatch
    (setq enttype (cdr (assoc 0  (entget ent))))
    (if (= enttype "HATCH") (progn
      ;; by color
      (if (/= color nil) (progn
        (if (= color  (cdr (assoc 62  (entget ent))) )
          (setq total (+ total (vla-get-area (vlax-ename->vla-object ent))))
        )
      ))
      ;; by pattern
      (if ptrn (progn
        (if (= ptrn  (cdr (assoc 2  (entget ent))) )
          (setq total (+ total (vla-get-area (vlax-ename->vla-object ent))))
        )
      ))
      
    ))
    (setq i (+ i 1))
  )
  total
)

(defun blocks_by_name (ss blkname / total i ent)
  (setq
    i 0
    total 0
  )
  (repeat (sslength ss)
    (setq ent (ssname ss i))
    (if (and
        (= "INSERT" (cdr (assoc 0  (entget ent))))
        (= blkname (cdr (assoc 2  (entget ent))))
      )
      (setq total (+ total 1))
    )  
    (setq i (+ i 1))
  )
  total
)

(defun c:TL ( / ss)
   (vl-load-com)
  ;; all entities
  (setq ss (ssget "_X") )
 
  (princ "\nFENCELINE1: ")
  (princ (total_length ss "FENCELINE1"))
 
  (princ "\nFENCELINE2: ")
  (princ (total_length ss "FENCELINE2"))
 
  (princ "\nGAS_LINE: ")
  (princ (total_length ss "GAS_LINE"))
 
  (princ "\nHOT_WATER_SUPPLY: ")
  (princ (total_length ss "HOT_WATER_SUPPLY"))
 
  (princ "\nHatch color 152: ")
  (princ (hatch_surface ss 152 nil))
 
  (princ "\nHatch color 30: ")
  (princ (hatch_surface ss 30 nil))
 
  (princ "\nHatch pattern HEX: ")
  (princ (hatch_surface ss nil "HEX"))
 
  (princ "\nHatch pattern ANSI31: ")
  (princ (hatch_surface ss nil "ANSI31"))
 
  (princ "\nHatch pattern SOLID: ")
  (princ (hatch_surface ss nil "SOLID"))
 
  (princ "\nBlocks oooo: ")
  (princ (blocks_by_name ss "oooo"))
 
  (princ "\nBlocks bbbb: ")
  (princ (blocks_by_name ss "bbbb"))
 
  (princ)
 
)

  • Thanks 1
Link to comment
Share on other sites

  • 3 weeks later...

You need to take a different approach in the code and make say a list of each hatch as two items ("pat name" area) ("pat name" area) ("pat name" area)  you then sort the list so end up with a sequence in the list of pattern names and its area, next step is to add the areas up you look at next item and if different then its a new pattern so set total to 0 and add new area. The same applies with hatch, plines, lines etc that you can have a list of multiple two item lists. You make a new list that is (pat name1 totarea)(patname2 total area)

 

I have played with a sort up to 3 levels deep so could have (lines color length)(plines color length)

 

The other suggestion is rather than repeating each (total_length ss "name") just make a list of all the names and use a repeat for each name in list. Same with the hatches.

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