Text to a CSV

Text to a CSV

StanThe
Enthusiast Enthusiast
2,785 Views
9 Replies
Message 1 of 10

Text to a CSV

StanThe
Enthusiast
Enthusiast

I need a lisp that will extract text on a certain layer from multiple enclosed polylines into a csv file and label it according to which polyline it came from.

SH
0 Likes
Accepted solutions (1)
2,786 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Gonna need more info, what line do you want it coming from cause if its from an enclosed polyline (polygon)... not too sure what you mean.

0 Likes
Message 3 of 10

StanThe
Enthusiast
Enthusiast

This pdf hopefully shows what i want to accomplish. Left side is my drawing and right side is basically what i'd like to see in a csv or xls file.

SH
0 Likes
Message 4 of 10

Sea-Haven
Mentor
Mentor

This is very easily done using ssget "WP" selection set within polygon and look for blocks. I posted elsewhere here almost exactly what you want. Will see if I can edit.

 

Dataextraction should do what you want for now.

 

 

 

 

0 Likes
Message 5 of 10

Sea-Haven
Mentor
Mentor
Accepted solution

Have a look at this, its hard coded for output file but that can be changed.

 

; simple export text
; By Alan H Aug 2019


(defun c:test ( / obj lay lay2 fo ss ss2 ent txt box)
(setq obj (vlax-ename->vla-object (car (entsel "Pick pline object"))))
(setq lay (vla-get-layer obj))
(setq obj (vlax-ename->vla-object (car (entsel "Pick text object"))))
(setq lay2 (vla-get-layer obj))
(setq box 1)
(if (/= (setq ss  (ssget "X" (list (cons 0 "lwpolyline")(cons 8 lay)))) nil)
(progn
(setq fo (open "d:\\acadtemp\\test.csv" "w") )
(repeat (setq x (sslength ss))
(setq ent (ssname ss (setq x (- x 1))))
(if ent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ent)))))
(setq ss2 (ssget "wP" co-ord (list (cons 0 "*text")(cons 8 lay2))))
(repeat (setq y (sslength ss2))
(setq txt (vla-get-textstring (vlax-ename->vla-object (ssname ss2 (setq y (- y 1))))))
(write-line (strcat txt "," "box " (rtos box 2 0)) fo)
)
(setq box (+ box 1))
)
)
)
(close fo)
(alert "done")
(princ)
)

 

 

0 Likes
Message 6 of 10

Moshe-A
Mentor
Mentor

@StanThe  hi,

 

Your request is very simple to solve and creating the csv file is the easiest part but i thought to take it one level up, i mean what happened if the enclose polyline is not a just simple box and contains arcs? (see the weird test1.dwg) so attached dent.vlx (Dump ENclose Text) when prompt for select objects you need to select text + polylines.  overlaid polylines is forbbiden.

 

enjoy

moshe

 

 

0 Likes
Message 7 of 10

StanThe
Enthusiast
Enthusiast

Sorry I haven't even been able to look at this! Been swamped at work! I do appreciate your help!!! Hopefully I'll be able to look at it soon!!!

SH
0 Likes
Message 8 of 10

StanThe
Enthusiast
Enthusiast

This will work and i sincerely thank you! Is there a way to tell it which is box 1, box 2, etc. ? Even if the box at the top would be #1 and the box below that is #2 and so forth?

Thanks again!!!

 

SH
0 Likes
Message 9 of 10

Sea-Haven
Mentor
Mentor

You would have to add a label to each pline, if you just pick all it would be in creation order, if you pick pick pick it would be in that order. There is a centroid of pline.lsp out there that could be added for text point.

0 Likes
Message 10 of 10

StanThe
Enthusiast
Enthusiast

1

SH
0 Likes