Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

156 REPLIES 156
SOLVED
Reply
Message 1 of 157
Anonymous
23152 Views, 156 Replies

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

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!

156 REPLIES 156
Message 41 of 157
pbejse
in reply to: wacho31

This

 

";"
(strcat (rtos (Cadr itm) 2 2) " m2")
";"

to

";"
(strcat (vl-string-translate "." "," (rtos (Cadr itm) 2 2)) " m2")
";"

Good job buddy

 

🙂

Message 42 of 157
wacho31
in reply to: pbejse

You are magician! works perfect!

Thank you

 

Here is a result (attachments)

Message 43 of 157
wacho31
in reply to: pbejse

Is it possible to add below exported data in csv file

- in first column:

string "Total area:"

 

- in second column:

value with sum of areas

 

Thank You!

 

Message 44 of 157
jalal.mousa
in reply to: pbejse

Hi There,

can you edit lisp to add column for perimeter of room beside area ?


@pbejse wrote:

@Anonymous wrote:

 

Just one more detail, would it be possible to add a 4th column to the table with the information on whether the polylines are closed or not (field "Closed" in "Misc" properties, attached image).

Here you go.

 

(defun c:EPD (/ ss i area layer all_data pts csv_file openfile) ; Export Polyline Data
;;			pBe Sep 2018			;;
  (if (and
        (setq all_data nil
              ss       (ssget '((0 . "LWPOLYLINE")))
        )
	        (repeat (setq i (sslength ss))
	          (setq e     (ssname ss (setq i (1- i)))
	                area  (vlax-curve-getarea e)
	                layer (cdr (assoc 8 (setq ent (entget e))))
	                cl_op (cdr (assoc 70 ent))
	                pts   (mapcar 'cdr
	                              (vl-remove-if-not
	                                '(lambda (d)
	                                   (= 10 (car d))
	                                 )
	                                ent
	                              )
	                      )
	          )
	          (if (setq ssText (ssget "_CP" pts '((0 . "TEXT"))))
	            (setq all_data
	                   (cons
	                     (list (if (= (sslength ssText) 1)
	                             (cdr (assoc 1 (entget (ssname ssText 0))))
	                             "-"
	                           )
	                           area
	                           layer
	                           (if (zerop ( logand 1 cl_op)) "No" "Yes")
	                     )
	                     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
            "Text inside polyline,Polyline Area (m2),Layer,Closed"
            openfile
          )
          (foreach itm (vl-sort all_data
                                '(lambda (a b) (< (Cadr a) (cadr b)))
                       )
            (write-line
              (Strcat (Car itm)
                      ","
                      (strcat (rtos (Cadr itm) 2 2) " m2")
                      ","
                      (caddr itm)
                      ","
                      (last itm)
              )
              openfile
            )
          )
          (close openfile)
          (startapp "notepad" csv_file)
        )
      )
  (princ)

)

 

Message 45 of 157
pbejse
in reply to: jalal.mousa

I assume you meant "length", it is the same is it not? Can you confirm that it is.

 

 

Message 46 of 157
jalal.mousa
in reply to: pbejse

Hi,
Yes you are right, once you use polyline it will give you in properties area and length
I would like to get :

1. Text inside polyline
2. Polyline layer name
3. Area (in sf or sm depends on inits)
4. Length (in lf or lm)
[cid:image001.png@01D4D7E7.FD000080]
Message 47 of 157
CLL_PBE
in reply to: jalal.mousa


@jalal.mousa wrote:
Hi,
Yes you are right, once you use polyline it will give you in properties area and length
I would like to get :

1. Text inside polyline
2. Polyline layer name
3. Area (in sf or sm depends on inits)
4. Length (in lf or lm)
[cid:image001.png@01D4D7E7.FD000080]

 

Sure

 

command: TPAL [ attached file ]

 

Result:

Text inside polyline,Layer,Polyline Area (m2),Length
Single line 2,Alayer,248.44 m2,69.41
Single line 5,AnotherLayer,226.73 m2,60.32
Single line 4,AndAnother,610.96 m2,98.92
Single line 1,YetAnotherLayer,215.65 m2,58.78

 

HTH

 

 

 

 

 

 

Message 48 of 157
jalal.mousa
in reply to: CLL_PBE

Hi There,
Thanks a lot for your help this is great, but I am facing trouble with using this code with all polylines I draw
It loads lisp successfully but when I run it and select objects it won't wright results to notepad/excel
When I tried lisp on sample provided it works
Any thoughts on why it is not working?
Please see attached file with 3 rooms I draw (room 100,102,103) that lisp won't work with
I am using Autocad 2015 not sure if it's matters
Thanks in advance

Message 49 of 157
pbejse
in reply to: jalal.mousa


@jalal.mousa wrote:
..
Please see attached file with 3 rooms I draw (room 100,102,103) that lisp won't work with
..

 

Those must be invisible drawing files I've been hearing about in the past 3 months Smiley Very Happy

Try attaching the file again @jalal.mousa .

 

 

 

 

 

Message 50 of 157
jalal.mousa
in reply to: pbejse

Hi not sure why it did not attached it maybe because i reply in e-mail

please see attached hope it will work

Message 51 of 157
CLL_PBE
in reply to: jalal.mousa


@jalal.mousa wrote:

Hi not sure why it did not attached it maybe because i reply in e-mail

please see attached hope it will work


 

On your previous post, you posted a code that you want to modify, and it shows below.

So...

 

change 

(setq ssText (ssget "_CP" pts '((0 . "TEXT"))))

To

(setq ssText (ssget "_CP" pts '((0 . "MTEXT"))))

HTH

 

Message 52 of 157
jalal.mousa
in reply to: CLL_PBE

this solution works perfect 

thanks a lot

I was wondering if I can ask for last few things

please see attached file that different polyline overlap each other in few locations

would it be possible to provide  a count column and total length where they overlap ?

so in attached file you will see notes I put to clarify above

overlap count and length.PNG

Message 53 of 157
jalal.mousa
in reply to: jalal.mousa

sorry for bothering you again

can you add:

  1. would it also possible to list all text that have no polyline around
  2. add column beside text content for text layer name 

in our example the answer would be ;

  1. Text with no poliyline around ( 101)
  2. name of layer (0)

many thanks in advance

Message 54 of 157
jalal.mousa
in reply to: jalal.mousa

sorry for bothering you again

can you add:

  1. would it also possible to list all text that have no polyline around
  2. add column beside text content for text layer name 

in our example the answer would be ;

  1. Text with no poliyline around ( 101)
  2. name of layer (0)

many thanks in advance

Message 55 of 157
CLL_PBE
in reply to: jalal.mousa


@jalal.mousa wrote:

this solution works perfect 

thanks a lot

I was wondering if I can ask for last few things..

...

would it be possible to provide  a count column and total length where they overlap

....

can you add:

  1. would it also possible to list all text that have no polyline around
  2. add column beside text content for text layer name 

 


 

You can ask by all means.

Yes  Yes, and Yes

 

Would you like some fries to go with that lisp?

download.jpeg

 

 

 

 

 

Message 56 of 157
jalal.mousa
in reply to: CLL_PBE

LOL
I know it is too much to ask
Message 57 of 157
pbejse
in reply to: jalal.mousa


@jalal.mousa wrote:
LOL
I know it is too much to ask

 

Just playing with you, I'll post the modified code later 

 

Cheers

 

Message 58 of 157
jalal.mousa
in reply to: pbejse

sorry to bother you again

i just notice that :

  1. if there is more than one text inside closed polyline it won't grab any of the text but -
  2. it won't grab closed polyline if no text inside
  3. it won't grab text if no closed polyline around it (this mentioned probably part of last email)

is this something can be fixed ?

Lisp issues.PNG

Message 59 of 157
pbejse
in reply to: jalal.mousa

 


@jalal.mousa wrote:

sorry to bother you again

i just notice that :

  1. if there is more than one text inside closed polyline it won't grab any of the text but -
  2. it won't grab closed polyline if no text inside
  3. it won't grab text if no closed polyline around it (this mentioned probably part of last email)

is this something can be fixed ?

 


 

Are you serious right now?

The answer is still YES

But first

Deposit 50 USD to this account number 

(73 39 109 32 97 98 117 115 105 110 103 32 121 111 117 114 32 107 105 110 100 110 101 115 115)

 

....

 

Message 60 of 157
jalal.mousa
in reply to: pbejse

Omg 😴

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta