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

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

Anonymous
Not applicable
51,916 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,917 Views
179 Replies
Replies (179)
Message 61 of 180

pbejse
Mentor
Mentor

@jalal.mousa wrote:
Omg 😴

 

Just kidding ... guess you clearly did not get the joke (well, at least one did  Smiley Happy)

I'll post the code later today

 

Hang in there..

 

 

0 Likes
Message 62 of 180

jalal.mousa
Advocate
Advocate

🙂

I got it believe me

have a good day

 

0 Likes
Message 63 of 180

pbejse
Mentor
Mentor

Is there a "blank Lwpolyline" (no text inside) with an "overlap" ?

 

0 Likes
Message 64 of 180

jalal.mousa
Advocate
Advocate

Hi,

it could be all options

 

0 Likes
Message 65 of 180

pbejse
Mentor
Mentor

 

How would the table look after all these additional options?

 

0 Likes
Message 66 of 180

jalal.mousa
Advocate
Advocate
Hi There,
I am not interested any more
Thanks

0 Likes
Message 67 of 180

pbejse
Mentor
Mentor

No worries buddy.

 

Cheers

0 Likes
Message 68 of 180

Anonymous
Not applicable

First of all I want to thanks for the coding.......

I want additional column after which can show length of Polyline.

 

0 Likes
Message 69 of 180

Anonymous
Not applicable

@pbejse I am also new to creating lisp and have been struggling with composing data extraction process that can produce similar results as @Anonymous needed. I am trying extract Polyline, Room IDs, Area in both mm2 and sq ft, show if polyline are open/close. If you can provide me with guidance i would greatly appreciate it. It would save me the time of manually re-creating the table. Please find attached sample drawing. Thank You,

0 Likes
Message 70 of 180

pbejse
Mentor
Mentor

@Anonymous wrote:

@pbejse I am also new to creating lisp and have been struggling with composing data extraction process that can produce similar results as @Anonymous needed. I am trying extract Polyline, Room IDs, Area in both mm2 and sq ft, show if polyline are open/close. If you can provide me with guidance i would greatly appreciate it. It would save me the time of manually re-creating the table. Please find attached sample drawing. Thank You,


 

Sure, give me some time to familiarize with code, and get back to you later.

0 Likes
Message 71 of 180

aashiqueali46
Community Visitor
Community Visitor

sorry to ask this can you explain me step by step am so new to this lips topics,.

0 Likes
Message 72 of 180

Anonymous
Not applicable

I am working on trying to export the data from AutoCAD that a CAFM software would do. I have a floor plan office layout that has been polylined per BOMA Standards. Each space has a unique identifier (ID #). I am trying to create a LISP that would extract the following data from the file: Polyline ID# and Square Footage. I would like to export this data in a format that I can upload to Excel and create a chart/report. 

 

There are other pieces of data that I would collect eventually, but would like to get the basic before proceeding. I have been manually collecting this information for a while as the owner refuses to obtain a proper CAFM software to expedite the process. 

 

If there is a source that anybody can provide me where I can learn to compose such LISP, it would be of great help. 

 

Thanks,

0 Likes
Message 73 of 180

OM805
Enthusiast
Enthusiast

Hello,

 

The following works well but, I need the Area to be in SQFT and the Perimeter to be in Lineal Feet. Tried a few things on my end without success.  Any assistance would be appreciated.

 

POLYLINE: MULTI TEXT/AREA/PERIMETER/CLOSED/HANDLE ID

 

 

(defun c:EPD (/ all_data area csv_file d data e ent i len openfile pts s ss sstext st)
					; Export Polyline Data
  ;;            pBe Sep 2018            ;;
  (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)
		   ;; RJP » 2019-01-17 added length to results
		   len	(vlax-curve-getdistatparam e (vlax-curve-getendparam e))
		   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"))))) "-")
			  ((= (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
	     "Text inside polyline?,Polyline Area (m2),Polyline Length (m),Layer,Closed?,Handle"
	     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")
		       ","
		       (strcat (rtos (caddr itm) 2 2) " m")
		       ","
		       (cadddr itm)
		       ","
		       (cadddr (cdr itm))
		       ","
		       (last itm)
	       )
	       openfile
	     )
	   )
	   (close openfile)
	   (startapp "notepad" csv_file)
    )
  )
  (princ)
)

 

 

Regards,

 

OM

0 Likes
Message 74 of 180

OM805
Enthusiast
Enthusiast

Figured it out... The following works for me.

(defun c:epd (/ 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,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 2) "")
		       ","
		       (strcat (rtos (/ (caddr itm) 12) 2 2) "");;or /* Divide or Multiply here
		       ","
		       (cadddr itm)
		       ","
		       (cadddr (cdr itm))
		       ","
		       (last itm)
	       )
	       openfile
	     )
	   )
	   (close openfile)
	   (startapp "notepad" csv_file)
    )
  )
  (princ)
)

 

0 Likes
Message 75 of 180

kDQCX7
Participant
Participant

Hi all,

 

Is there way to modify this so instead of having polyline m2 and total length can have the X & Y axis lengths?

 

Thanks. 

0 Likes
Message 76 of 180

kDQCX7
Participant
Participant

Hi,

 

Is anyone able to help with this small change?  This will the give everything I need.  I am happy to try and modify myself if someone can point me in the right direction but am new and dont know where to start.

 

Thanks.

0 Likes
Message 77 of 180

dlanorh
Advisor
Advisor
Are these always rectangles and always orthogonal?

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

0 Likes
Message 78 of 180

kDQCX7
Participant
Participant

Hi dlanorh,

 

Thanks for the reply. Yes these are always rectangles or squares.

 

Thanks 

0 Likes
Message 79 of 180

dlanorh
Advisor
Advisor

@kDQCX7 wrote:

Hi dlanorh,

 

Thanks for the reply. Yes these are always rectangles or squares.

 

Thanks 


OK, but are they always orthogonal (drawn with ortho mode on).

 

There are many requests for different exports in this thread. What information do you want exported, and in what order?

Do the rectangles contain text, and if so is it text or mtext?

 

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

0 Likes
Message 80 of 180

kDQCX7
Participant
Participant

Yes always with ortho mode on.  This is the lisp that best suits.  I am after the text inside polyline, the length & width and polyline layer (I dont need the closed or handle but can keep in if its easier).  Text is always text, not mtext. 

The current order this exported in is good, just need to replace current polyline area with X axis length and the polyline length with the Y axis length.

 

Thanks.

0 Likes