Jump to content

3d polylines to csv files question


scampymoogin

Recommended Posts

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!!

Link to comment
Share on other sites

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)
 )

Link to comment
Share on other sites

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 . ))) 
 (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")
 )

Link to comment
Share on other sites

  • 1 month later...

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!

Link to comment
Share on other sites

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)   
     )
   )
   

Link to comment
Share on other sites

  • 2 weeks later...

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...