Jump to content

Recommended Posts

Posted

Hi all, currently working as a Setting Out Civil Engineer using AutoCAD 2008. I have been provided with design stringlines, in .csv with "pt id, x, y, z" data. Stringlines can represent pretty much anything we are building but easiest to imagine is the edge of a road (kerbs). Along a stringline, points will typically be at 10m intervals or chainages, with each point having an ID and XYZ data.

 

I need to import this csv data into CAD to see what it looks like. Best way of doing this I have found is to create a 3dpoly script (although working in 2d drafting) as I can then see the 'plan' view of the stringlines in X&Y co-ordinates but the elevation data is retained. Requires some data handling to remove Pt ID etc but this then does the job of getting the string data into CAD. If I then need to move some of the allignments (by using points as handles) is there anyway to get AutoCAD to output the new X,Y & Z values as .csv for each point? As my Total Station (EDM) requires the revised CSV data to physically then mark this out on the ground.

 

I have tried the list function, which works for a standard pline, outputting X&Y for each individual point along the pline, but when used on a 3dpoly the info for each point doesnt appear to be outputted, just two random points somewhere along its length.

 

So in summary from a 3d poly I need an output of XYZ for each point along the line in .csv format.

 

I appreciate the above explanation might not make sense for anyone not involved in the construction industry, if neccesary I can find some example data.

Posted

So basically you need to be able to export your breaklines once you have modified them to a data file (in this case a csv file)? I'm pretty sure this is what your asking. I may have a lisp routine that will do just that. I'll search for it in a few and post it here. Or maybe Lee Mac can whip out one real quick if he doesn't already have such. That is if he is lurking about. These sort of things usually make him pop out of his hole and add some input.

Posted
Or maybe Lee Mac can whip out one real quick if he doesn't already have such. That is if he is lurking about. These sort of things usually make him pop out of his hole and add some input.

 

Hahaha :lol: :lol: That made my day :D

 

I wrote this a while back { Exports vertices to Excel }

 

;; Polyline Vertex Exporter  ~   by Lee McDonnell  ~  27.11.2009

(defun c:pExp (/ *error* ObjRel ss col row ent tot j pt)
 (vl-load-com)

 (defun *error* (e)
   (ObjRel (list xlApp xlCells))
   (or (wcmatch (strcase e) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error : " e " **")))
   (princ))

 (defun ObjRel (lst)
   (mapcar
     (function
       (lambda (x)
         (if (and (eq (type x) 'VLA-OBJECT) (not (vlax-object-released-p x)))
           (vl-catch-all-apply 'vlax-release-object (list x))))) lst))

 (if  (setq i -1 ss (ssget '((0 . "*POLYLINE"))))
   (progn
     (setq xlApp     (vlax-get-or-create-object "Excel.Application")                
           xlCells   (vlax-get-property
                       (vlax-get-property
                         (vlax-get-property
                           (vlax-invoke-method
                             (vlax-get-property xlApp "Workbooks")
                             "Add")
                           "Sheets")
                         "Item" 1)
                       "Cells") col 0 row 1)

     (mapcar (function
               (lambda (x)
                 (vlax-put-property xlCells "Item" row (setq col (1+ col)) x)))
             '("Point""X""Y""Z""Distance""Total"))

     (while (setq ent (ssname ss (setq i (1+ i))))
       (setq tot 0. row (1+ row) j (1- (vlax-curve-getStartParam ent)))

       (while (<= (setq j (1+ j)) (vlax-curve-getEndParam ent))
         (setq col 0 pt (mapcar 'rtos (vlax-curve-getPointatParam ent j)))          

         (mapcar
           (function
             (lambda (x)
               (vlax-put-property xlCells "Item" row (setq col (1+ col)) x)))
           
           (list   (rtos (1+ j) 2 0)
                   (car pt)  (cadr pt) (caddr pt) 
                   (rtos (setq dis (- (vlax-curve-getDistatParam ent j)
                                      (if (zerop j) 0 (vlax-curve-getDistatParam ent (1- j)))))) 
                   (rtos (setq tot (+ dis tot)))))
         
         (setq row (1+ row))))
     
     (vlax-put-property xlApp 'Visible :vlax-true)
     (ObjRel (list xlApp xlCells))))

 (princ))

 

Or Perhaps this: { Exports to CSV }

 

;; Polyline Vertex Exporter  ~   by Lee McDonnell  ~  26.11.2009

(defun c:pExp (/ ss tmp i j ent tot dis pt)
 (vl-load-com)

 (if (and (setq ss   (ssget '((0 . "*POLYLINE"))))
          (setq tmp  (getfiled "Output File" (cond (*load) ("")) "txt;csv" 9)))
   (progn
     (setq *load tmp tmp (open tmp "a") i -1)
     (write-line "Point,X,Y,Z,Distance,Total" tmp)

     (while (setq ent (ssname ss (setq i (1+ i))))
       (setq tot 0. j (1- (vlax-curve-getStartParam ent)))

       (while (<= (setq j (1+ j)) (vlax-curve-getEndParam ent))
         (setq pt (mapcar 'rtos (vlax-curve-getPointatParam ent j)))          

         (write-line
           
           (strcat (rtos (1+ j) 2 0) (chr 44)
                   (car pt) (chr 44) (cadr pt) (chr 44) (caddr pt) (chr 44)
                   (rtos (setq dis (- (vlax-curve-getDistatParam ent j)
                                      (if (zerop j) 0 (vlax-curve-getDistatParam ent (1- j)))))) (chr 44)
                   (rtos (setq tot (+ dis tot))))
           tmp))

       (write-line "" tmp))
     
     (close tmp)))

 (princ))

 

The original request was to include distances etc, but it should be along the lines of what you require.

 

 

... Now to get back into my hole... :P

Posted

Well I am glad you got out of your hole! :)

 

This is pretty much exactly what I wanted! Although can I be cheeky and ask if there is any chance of you editing it to only ouput ID,X,Y,Z? As the additional columns of data would make my Total Station fall over itself. If not means I will manually have to delete these uneeded columns each time, and I intend using this LISP lots so would soon get a bit annoying!

 

I have another problem along a similar vein, but I will create a new thread for that!

 

Cheers for your help!

Posted

No problem:

 

;; Polyline Vertex Exporter  ~   by Lee McDonnell  ~  27.11.2009

(defun c:pExp (/ *error* ObjRel i ss xlApp xlCells col row ent j pt)
 (vl-load-com)

 (defun *error* (e)
   (ObjRel (list xlApp xlCells))
   (or (wcmatch (strcase e) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error : " e " **")))
   (princ))

 (defun ObjRel (lst)
   (mapcar
     (function
       (lambda (x)
         (if (and (eq (type x) 'VLA-OBJECT) (not (vlax-object-released-p x)))
           (vl-catch-all-apply 'vlax-release-object (list x))))) lst))

 (if  (setq i -1 ss (ssget '((0 . "*POLYLINE"))))
   (progn
     (setq xlApp     (vlax-get-or-create-object "Excel.Application")                
           xlCells   (vlax-get-property
                       (vlax-get-property
                         (vlax-get-property
                           (vlax-invoke-method
                             (vlax-get-property xlApp "Workbooks")
                             "Add")
                        "Sheets")
                      "Item" 1)
                    "Cells") col 0 row 1)

     (mapcar (function
               (lambda (x)
                 (vlax-put-property xlCells "Item" row (setq col (1+ col)) x))) '("Point""X""Y""Z"))

     (while (setq ent (ssname ss (setq i (1+ i))))
       (setq row (1+ row) j (1- (vlax-curve-getStartParam ent)))

       (while (<= (setq j (1+ j)) (vlax-curve-getEndParam ent))
         (setq col 0 pt (mapcar 'rtos (vlax-curve-getPointatParam ent j)))          

         (mapcar
           (function
             (lambda (x)
               (vlax-put-property xlCells "Item" row (setq col (1+ col)) x)))
           
           (list (rtos (1+ j) 2 0) (car pt) (cadr pt) (caddr pt)))
         
         (setq row (1+ row))))
     
     (vlax-put-property xlApp 'Visible :vlax-true)
     (ObjRel (list xlApp xlCells))))

 (princ))

 

 

;; Polyline Vertex Exporter  ~   by Lee McDonnell  ~  26.11.2009

(defun c:pExp (/ ss tmp i j ent tot dis pt)
 (vl-load-com)

 (if (and (setq ss   (ssget '((0 . "*POLYLINE"))))
          (setq tmp  (getfiled "Output File" (cond (*load) ("")) "txt;csv" 9)))
   (progn
     (setq *load tmp tmp (open tmp "a") i -1) (write-line "Point,X,Y,Z" tmp)

     (while (setq ent (ssname ss (setq i (1+ i))))
       (setq j (1- (vlax-curve-getStartParam ent)))

       (while (<= (setq j (1+ j)) (vlax-curve-getEndParam ent))
         (setq pt (mapcar 'rtos (vlax-curve-getPointatParam ent j)))          

         (write-line (strcat (rtos (1+ j) 2 0) (chr 44)
                             (car pt) (chr 44) (cadr pt) (chr 44) (caddr pt)) tmp))

       (write-line "" tmp))
     
     (close tmp)))

 (princ))

 

Lee

Posted
Hahaha :lol: :lol: That made my day :D

 

... Now to get back into my hole... :P

 

LOL I'm glad that brightened up your day Lee. Always good to do such a thing especially since you have contributed so much to this community. As I'm sure everyone that has been here a while knows, you are a boon to this forum.

Posted

Your very welcome. The lisp routines you provide is a great contribution and certainly helps those in need. I'm thinking you should be nominated as the great philanthropist of CADTutor

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