Export polyline data (area, layer and inner text) to excel

Export polyline data (area, layer and inner text) to excel

Anonymous
Not applicable
51,934 Views
179 Replies
Message 1 of 180

Export polyline data (area, layer and inner text) to excel

Anonymous
Not applicable

Hello, everyone!

I am searching for a lisp that can find all closed polylines in a drawing and export to excel their following information:

-Area of each closed polyline

-Layer in which the polyline resides

-Text inside each polyline

 

I have a building plan with polylines enclosing each room and the corresponding room text number also inside the polyline. I am looking for a lisp that can export to excel a table like this:

Text inside polylinePolyline Area (m2)Layer
"Room_1.1"10 m2Room_Layer
"Room_1.2"5 m2Room_Layer
"Room_1.3"5 m2Room_Layer
 -20 m2Floor_Layer

 

The polylines and room text numbers are located in different layers.

One of the polylines (last row in the table) encloses the whole building which means that there is more that one text inside it. For this single polyline, I only need its area and layer (text not needed).

 

I am fairly new to lisp creation so any help you can provide me would be highly appreciated!

Thanks in advance!

0 Likes
Accepted solutions (1)
51,935 Views
179 Replies
Replies (179)
Message 141 of 180

dlanorh
Advisor
Advisor

@OM805 wrote:

Working good on this end.

 

Thanks,

 

OM


That's great. 👍

 

Attached is the first iteration of the duplicate "Space Name" version. This is working on the attached (expanded) test drawing, and produces the attached csv file.

 

Points to note.

 

1. The lisp uses a global variable "dnlst". This is set to nil when exiting normally or via the error sub routine.

 

2. If there are duplicate space names, all spaces with that name are tagged as duplicate as it's impossible to know which is correct. This applies to spaces with or without polylines, or a mixture. This doesn't apply where there is no space name found. This is indicated with "-" in the space name column, as is any missing space class (in the space class column).

 

3. I have added the duplicate name column after the space name column as it was just too complicated to put it elsewhere.

 

Any problems let me know.

 

   

I am not one of the robots you're looking for

Message 142 of 180

OM805
Enthusiast
Enthusiast

dlanorh,

 

I've been testing the code and have not come across another issue.  Just wanted to give you some feedback and a big thanks.

 

 

Regards,

 

OM

0 Likes
Message 143 of 180

Hydro88
Explorer
Explorer

Hi

Thank you for all your work, your lisp is awesome !

 

I'm new to this and I achieve to edit it to my needs but I'm stuck for some features :

- is it possible to remove space class ?

- is it possible to order by layer name ?

- do you think it's possible to display somewhere sum of the layer's area ? Maybe on each line.

 

For example you have a layer "appartment n°1" with 4 spaces. 

You will have 4 lines for appartment N°1 and sum of the areas of these 4 spaces.

 

Thank for your help !

 

 

0 Likes
Message 144 of 180

ce_yassin
Contributor
Contributor

where can I find the output file?

0 Likes
Message 145 of 180

paliwal222
Advocate
Advocate

Dear Sir, 

I want the Area Table inserted in the drawing Directly.

please send the code to this function

Thanks.

0 Likes
Message 146 of 180

devitg
Advisor
Advisor

@paliwal222 , as it is the 145 post since the first one , please upload your sample dwg and the LSP you want to fit to your need 

0 Likes
Message 147 of 180

r.kostic
Explorer
Explorer

Hi,

 

Can you help me to modify this code to return total lenghts of polylines per layer?

 

Thank you in andvance.

0 Likes
Message 148 of 180

vporrash141089
Advocate
Advocate

Hello everyone, hope everyone is having an amazing Monday!

I've been struggling with some manual work at my office, and I was wondering if someone could help me out with a similar issue to this thread.

I have attached a drawing with  3 layers I need the SV-TXT-TYPE layer (Yellow) as column and also need column B as layer SV-TXT-SPACENAME (Blue) with that I'd like to have is the extracted information as image below, can some one please help? 

 

AVFx1410_0-1685382973792.png

 

Thank you so much!

 

0 Likes
Message 149 of 180

vporrash141089
Advocate
Advocate

To be clear that is all I need. I do not need any error checking or the option to Append, Overwirte etc.

 

Thanks again and every comment is appreciated!

0 Likes
Message 150 of 180

uros_markovicGJACK
Community Visitor
Community Visitor

Hi,

 

How do you execute/start this file?

I presume that you make a lisp out of it, but how to you envoke it? What's the command?

 

Best regards,

Uros

0 Likes
Message 151 of 180

uros_markovicGJACK
Community Visitor
Community Visitor

Hi @pbejse & @Anonymous ,

 

How do you execute this lisp?

 

Best regards,

Uros

0 Likes
Message 152 of 180

vporrash141089
Advocate
Advocate

Have yout ried c: EPD?

0 Likes
Message 153 of 180

uros_markovicGJACK
Community Visitor
Community Visitor

Thanks @vporrash141089 ,

I couldn't load it and turned that this was the problem and not EPD command to start it.

 

Do you or @Anonymous or @pbejse know how to adjust the area take off to account for my drawing being in mm2?

I can easily do Excel formula conversion, but just wondering if it can be automated as my drawing units are milimeters.

 

Thanks,

Uros

0 Likes
Message 154 of 180

bcddss
Enthusiast
Enthusiast

hello everybody!

someone knows how to modify this lisp to select only the text who have insertion point inside polygon, not the text who crossing the polyline limit. I use this lisp and do not make error i have to shrink all the text to minimum height. Thank you. Very good lisp! keep up 

Ahags
0 Likes
Message 155 of 180

von12_kirakira
Explorer
Explorer

@pbejse Thank you a millon!

Please advise how could I change your script to add both Polyline, 2D Polyline and 3D Polyline.
Thanks again!

0 Likes
Message 156 of 180

OM805
Enthusiast
Enthusiast

Hello @dlanorh...

 

Ran into an issue with space "100 Vestibule".  The space is not being picked up correctly. I'm assuming, it's the circular nature of the space.  Space shows up as three lines per below.  Attached is a DWG for reference and use. Anyway to resolve?

 

Vestibule Polyline is being depicted three time with errors:

OCTAVIOMENDOZA3QG5C_0-1692373280669.png

 

Regards,

 

OM

0 Likes
Message 157 of 180

vporrash141089
Advocate
Advocate

Hey guys, I have slightly modified the lisp on this post, and I have the following issue I wish someone would be able to help me with.

 

 Basically I need the second column to provide the text within polyline in a respective layer to be more specific COMPANY and the first column should be the content from category the rest should remain as is.

 

Any assistance is very much appreciated

 

 

 

 

 

 

(defun c:EXDC (/ all_data area csv_file d data e ent i len openfile pts s ss sstext st)
  (if (and (setq ss (ssget '((0 . "LWPOLYLINE"))))
     (repeat (setq i (sslength ss))
       (setq e  (ssname ss (setq i (1- i)))
       ent  (entget e)
       area ( / (vlax-curve-getarea e) (* 144));;/ 144 (or 12 * 12) Imperial
       len  (vlax-curve-getdistatparam e (vlax-curve-getendparam e));;Length Perimeter
       data (mapcar '(lambda (d) (cdr (assoc d ent))) '(8 70 5))
       pts  (mapcar 'cdr (vl-remove-if-not '(lambda (d) (= 10 (car d))) ent))
       )
       (setq all_data
        (cons
          (list
      (cond
        ((null (setq sstext (ssget "_CP" pts '((0 . "TEXT"))))) "NO SPACE TEXT FOUND")
        ((= (sslength sstext) 1) (cdr (assoc 1 (entget (ssname sstext 0)))))
        ((substr
           (apply
             'strcat
             (mapcar '(lambda (st) (strcat " , " st))
               (vl-sort
           (mapcar '(lambda (s) (cdr (assoc 1 (entget s))))
             (vl-remove-if 'listp (mapcar 'cadr (ssnamex sstext)))
           )
           (function (lambda (a b) (< a b)))
               )
             )
           )
           4
         )
        )
      )
      area
      len
      (car data)
      (if (zerop (logand 1 (cadr data)))
        "No"
        "Yes"
      )
      (caddr data)
          )
          all_data
        )
       )
       all_data
     )
     (setq csv_file
      (getfiled "Save CSV File"
          (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".csv")
          "csv"
          45
      )
     )
      )
    (progn (setq openfile (open csv_file "w"))
     (write-line
       "Space Name/Class,Company,Area (sqft),Perimeter (ft),Layer,Polyline Closed?,Object Handle ID"
       openfile
     )
     (foreach itm (vl-sort all_data '(lambda (a b) (< (cadr a) (cadr b))))
       (write-line
         (strcat (car itm)
           ","
           (strcat (rtos (cadr itm) 2 3) "")
           ","
           (strcat (rtos (/ (caddr itm) 12) 2 3) "");;or /* Divide or Multiply here
           ","
           (cadddr itm)
           ","
           (cadddr (cdr itm))
           ","
           (strcat "\'" (last itm))
         )
         openfile
       )
     )
     (close openfile)
     (startapp "notepad" csv_file)
    )
  )
  (princ)
)

 

0 Likes
Message 158 of 180

chauthienqui
Contributor
Contributor

Hello mate @pbejse 

 

I have used your code for a times, and just stuck in some issues that I posted here: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/request-to-the-help-export-lwpolylin...

 

Would you like to see and guid me to change the code ?

Thank you very much. 

0 Likes
Message 159 of 180

jwylie2020
Advocate
Advocate

Similar to the previous on going versions of this: does someone have a routine to select polylines then export data the following to an excel or CVS file? Layer name, total area SF per layer, total length LF per layer. Selected polyline count per layer would be bonus.

So the result would be 3 or 4 columns of data summing the area, length and count with each row sorted by row.

 

Thanks,

JL

JL
C3D 2024
Win 11 Pro
0 Likes
Message 160 of 180

pbejse
Mentor
Mentor

Let's revisit this old topic, would you mind posting a sample drawing and the resulting csv file?

0 Likes