PDA

View Full Version : 3d polylines to csv files question



scampymoogin
10th Oct 2011, 03:14 pm
I have received a CAD file direct from specialist software that contains 3d polylines. The software I am using (Microdrainage Windes) accepts csv files so that I can create a 3d tin. What I am doing at the moment is painstakingly dividing the individual lines into a number of points (I don’t really care how many, it doesn’t have to be that accurate), once they have been divided I use the data extraction tool. So my questions are:

· Is there any way to extract the 3d polyline information as individual points without dividing the line first.
· Is there any way to divide multiple lines at once (lisp routine perhaps),
· Can anybody think of a better way for me to do this.


Any help really appreciated!!

fuccaro
10th Oct 2011, 09:08 pm
Hello!
Try this quick one. It will process all the "Old style" polylines found in the drawing. Run it, copy the relevant part from the text screen (F2) and paste in Excel or even in Notepad. From there you can save as CSV. It should be simple to adjust the lisp to save directly in a CSV file, but I really don't have the time right now. Maybe tomorrow -if in the mean time you wont get better help.

(defun c:test()
(setq ss (ssget "X" (list '(0 . "POLYLINE"))))
(princ (strcat "\n" (itoa (setq i (sslength ss))) " polilines found"))
(repeat i
(setq en (entnext (ssname ss (setq i (1- i)))) el (entget en))
(while (= (cdr (assoc 0 el)) "VERTEX")
(setq a (mapcar 'rtos (cdr (assoc 10 el)))
st (strcat (car a) "," (cadr a) "," (caddr a)))
(princ (strcat "\n" st))
(setq el (entget (setq en (entnext en))))
)
(princ "\n")
)
(princ)
)

scampymoogin
11th Oct 2011, 10:25 am
Thanks a lot for the reply! Is there any way I can specify how many points the polyline divides into. For example every 5m?

fuccaro
11th Oct 2011, 12:07 pm
This should work better. Don't divide the polylines; just run the Lisp and see in the CSV file the coords

(defun c:Plist( / s ss file f i en el a st)
;| Grabs the 3DPolylines found in the drawing
and saves the vertices in a CSV file
mfuccaro@hotmail.com 11 Oct 2011 |;
(setq s ",") ;separator can be ";" or "," -Change to suit
;(setq s ";")
(setq ss (ssget "X" '((0 . "POLYLINE")(-4 . "&=")(70 . 8))))
(setq file (getfiled "Output file" (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 3)) "Csv" 5))
(setq f (open file "w"))
(princ (strcat "\n" (itoa (setq i (sslength ss))) " polilines found \nX" s "Y" s "Z") f)
(repeat i
(setq en (entnext (ssname ss (setq i (1- i)))) el (entget en))
(while (= (cdr (assoc 0 el)) "VERTEX")
(setq a (mapcar 'rtos (cdr (assoc 10 el)))
st (strcat (car a) s (cadr a) s (caddr a)))
(princ (strcat "\n" st) f)
(setq el (entget (setq en (entnext en))))
)
(princ "\n" f)
)
(close f)
(setq s "File saved")
)

scampymoogin
11th Oct 2011, 12:31 pm
Thanks alot, that works.

fuccaro
11th Oct 2011, 08:17 pm
You are more than welcome, Scampymoogin! :)

scampymoogin
16th Nov 2011, 12:17 pm
Bump.

The solution above is dividing my 3d polyline at the points where the polyline has a change in its 3d value. When I import the csv file into my software the interpolation between the points isn't accurate enough. I am looking for a slight edit to the lisp above the divides the 3d polyline's in the CAD file into points every 5m. Having these extra points should give me the accuracy I need.

Any Ideas?

Thanks!

BIGAL
17th Nov 2011, 02:47 am
Fuccaro maybe just add a divide to the code to create POINTS plus vertice's as points then just write a full points list to a csv. Only question would be a inc factor.

fuccaro
18th Nov 2011, 04:32 pm
Sorry for the delay, I had no time for programming these days. I rewrote the program, give it a try:

(defun c:test( / sep f file ss pn)
(setq sep ";")
(setq f (getfiled "Output file" "" "CSV" 1)
file (open f "w"))
(setq ss (ssget "X" '((0 . "POLYLINE"))))
(repeat (setq pn (sslength ss))
(pl1 (ssname ss (setq pn (1- pn))) file sep)
(princ "\n" file)
)
(close file)
)
(defun pl1(en file sep / prev m el)
(setq en (entnext en) el (entget en) prev nil)
(while (= "VERTEX" (cdr (assoc 0 el)))
(setq a (cdr (assoc 10 el)))
(if prev (slice prev a file sep))
(setq prev a)
(setq en (entnext en) el (entget en))
)
(setq m (mapcar 'rtos prev)
m (strcat (car m) sep (cadr m) sep (caddr m) "\n"))
(princ m file)
)
(defun slice(x y file sep / dist n d1 d2 p)
(setq m (mapcar 'rtos x)
m (strcat (car m) sep (cadr m) sep (caddr m) "\n"))
(princ m file)
(setq dist 150) ;change here the desired distance
(setq n (fix (/ (distance x y) (* 0.99 dist))))
(setq d1 (mapcar '/ (mapcar '- y x) (list n n n)))
(setq i 0)
(repeat (1- n)
(setq i (1+ i))
(setq d2 (mapcar '* d1 (list i i i)))
(setq p (mapcar '+ x d2))
(setq m (mapcar 'rtos p)
m (strcat (car m) sep (cadr m) sep (caddr m) "\n"))
(princ m file)
)
)

scampymoogin
1st Dec 2011, 10:45 am
Thanks for the above reponse but it just outputs a blank csv file :cry:

To confirm I am after a lisp routine that can pick up all the 3d polylines in a drawing and divide them into points every 5m. This is to save me using the divide command over and over again.

Thanks for all your efforts and any more help will be gretaly appreaciated!

fuccaro
2nd Dec 2011, 05:35 am
Well, I just tested it in AutoCAD 2006 and it exported as expected all the 3DPolylines found in the drawing. Sorry if it doesn't work in AutoCAD 2011, it seems that you will have to wait somebody else -using up to day software- to help you.
Are you sure that your drawing is made of 3dPolylines? Select one of them and see in the Properties window what it says.

fuccaro
2nd Dec 2011, 06:24 am
I sent the lisp to a friend and he just sent me a positive feed-back; the program worked in AutoCAD 2012.
Scampymoogin, is that CSV file *really* empty? Open it in Notepad.