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

Request to the help: Export LWPolyline Data with crossed (and overlap, inner) text

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
chauthienqui
644 Views, 12 Replies

Request to the help: Export LWPolyline Data with crossed (and overlap, inner) text

 

Hello everyone.

Previously, I used lisp EPD (downloaded from another topic), however, there were some obstacles, so I wrote this topic, hoping to receive help from autolisp experts.

Specifically:

I have 2 LWPolyline groups with text overlapping on the contour line, or inside.

After using lisp EPD (attached), the result I received was a csv file as shown below:

Image to show issues.jpg

 

I would like to adjust lisp to achieve the following expectations.

chauthienqui_0-1728143078194.png

 

1. The single-segment LWpolylines in Group 2: Could export the list of text that crossed (or overlap) with itself.

2. The LWpolylines in Group 1: Dont export the text that isn't crossed the line (i.e: Space 2,space3 with text W02). Keeping export text that cross and be inside the lwpolyline. 

3. Text inside polyline (or crossed, or overlap etc..) - Column A: Sort by the Layer name first, then sort by the alphabet of content). with same serepate  by " | "

 

Other columns: Area, Perimeter, Layer etc,.. please keep it, 

 

There is ACAD file, CSV file, and the lisp file that I used.

 

I have actually searched the entire forum and really hope someone can help to adjust the lisp code, with at least one issue.

 

Edit: I post the lisp code EPD that I used

 

 

(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) )
		       ","
		       (strcat (rtos (caddr itm) 2 2) )
		       ","
		       (cadddr itm)
		       ","
		       (cadddr (cdr itm))
		       ","
		       (last itm)
	       )
	       openfile
	     )
	   )
	   (close openfile)
	   (startapp "notepad" csv_file)
    )
  )
  (princ)
)

 

 

12 REPLIES 12
Message 2 of 13
pbejse
in reply to: chauthienqui

 Hi @chauthienqui 
Can you please post the link of the topic where this was taken so i can understand the original intent of EPD?

 

Message 3 of 13
chauthienqui
in reply to: pbejse

@pbejse Thank for answering

 

This is the topic that I got the lisp code: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-polyline-data-area-layer-and-...

 

You could see the comment Message #80 

 

Message 4 of 13
pbejse
in reply to: chauthienqui

The quickest fix for this is

(null (setq sstext (ssget
						 (if (zerop (Cdr (assoc 70 ent)))  "_F" "_CP" )
						pts '((0 . "TEXT")))))

But this will not produced the desired result.

For example 

Row #7 on your example shows

D04	0	2450	Wall Line

The mod will still catch W03 as we are using Fence

D04 | W03	0	2450	Wall Line

Unless you move the W03 text a bit down, we can however use WP and include a fuzz value for the points

 

Message 5 of 13
chauthienqui
in reply to: pbejse

Ah I see. That seems the text boundaries of W03 touch the line.

 

I am understanding like that.

 

So, I am so happy, it still worked for me. I just need to adjust the way of dratfing

 

Message 6 of 13
pbejse
in reply to: chauthienqui


@chauthienqui wrote:

Ah I see. That seems the text boundaries of W03 touch the line.

I am understanding like that.

So, I am so happy, it still worked for me. I just need to adjust the way of dratfing


All good then
Glad it helps.

 

Message 7 of 13
chauthienqui
in reply to: pbejse

I have just checked, it's pretty funny that when I randomly  made a text wihout any words cross the lwpollyline,

 

=> The result is no text 

chauthienqui_1-1728408098918.png

 

chauthienqui_0-1728408069710.png

 

Message 8 of 13
pbejse
in reply to: chauthienqui


@chauthienqui wrote:

I have just checked, it's pretty funny that when I randomly  made a text wihout any words cross the lwpollyline,

 

=> The result is no text 


Interesting, but i didn't really understand what you mean 😀.
A sample drawing on what describe would help.

 

 

Message 9 of 13
chauthienqui
in reply to: pbejse

That means there is slighlty gap between C and D charater. Even the full text is CD-TI.2.N.1
The lwpoline goes into that slighlty gap, with the algorithm you wrote, it will understand that the text is not on the lwpline.

The result will be like this:

chauthienqui_0-1728409008246.png

 

Message 10 of 13
pbejse
in reply to: chauthienqui


@chauthienqui wrote:

That means there is slighlty gap between C and D charater. Even the full text is CD-TI.2.N.1
The lwpoline goes into that slighlty gap, with the algorithm you wrote, it will understand that the text is not on the lwpline.


I guess we are going to go with this route after all

 

we can however use WP and include a fuzz value for the points

I'll post the code later @chauthienqui 

Message 11 of 13
chauthienqui
in reply to: pbejse

Many thanks, you already helped me to deeply understand the code
Message 12 of 13
Sea-Haven
in reply to: chauthienqui

Just a comment, when using ssget "F" it can miss linetypes with gaps as well, changing the variable "LTGAPSELECTION" fixes. Would using ssget "CP" be better method. I add 1st point to end of points list so its closed.

Message 13 of 13
chauthienqui
in reply to: Sea-Haven

How could we add 1 more point to selection area without modifying the shape of lwpolyine.?
Would you please guide me to change the code

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report