Jump to content

Recommended Posts

Posted

Hi,

Does anyone know of a way to extract the x,y,z vertices data from a 3D polyline and export it to a .csv (or .txt file)

 

ASMI has something close to what i am looking for with his 3cord tool

 

(i'm not allowed to post the link)

 

unfortunately this does not work in AutoCAD 2004, and does not output to a file.

 

Thanks in advance,

Andrew

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    4

  • stevesfr

    3

  • ASMI

    2

  • rich1983

    2

Posted

you could write something in VBA that would be pretty simple.

Posted

It works, but need to polysh up.

 

(defun c:3csv (/ cPl cFmn fVar pLst cAns *error*)

 (vl-load-com)

 (defun *error*(msg) 
   (if fVar(close fVar))
   (princ) 
   ); end of *error*

 (defun Extract_3DPoly_Vertexes(Ent / cLst oLst)
   (if(= 'ENAME(type Ent))
     (setq Ent(vlax-ename->vla-object Ent))
     ); end if
   (if(= "AcDb3dPolyline"(vla-get-ObjectName Ent))
     (progn
       (setq cLst(vlax-safearray->list
	    (vlax-variant-value
	      (vla-get-Coordinates Ent))))
(while cLst
  (setq oLst(cons
	      (list
		(car cLst)
		(cadr cLst)
		(nth 2 cLst))
	      oLst)
	); end setq
  (repeat 3(setq cLst(cdr cLst)))
   ); end while
(reverse oLst)
); end progn
     ); end if
   ); end of Extract_3DPoly_Vertexes

 (if(and
      (setq cPl(entsel "\nSelect 3D-Polyline > "))
      (= "POLYLINE"(cdr(assoc 0(entget(setq cPl(car cPl))))))
      ); and
   (progn
     (setq fVar(open(setq cFmn(strcase(strcat(getvar "DWGPREFIX")
	   (vl-filename-base(getvar "DWGNAME")) ".csv"))) "a")
    pLst(Extract_3DPoly_Vertexes cPl)
   ); end setq
     (write-line "X;Y;Z" fVar)
     (foreach pt pLst
  (write-line
    (strcat(rtos(car pt))";"(rtos(cadr pt))";"(rtos(last pt)))
    fVar)
       ); end foreach
      (close fVar)
     (alert(strcat "\nCSV File location: " cFmn))
     ); end progn
   (princ "<!> It isn't 3D-Polyline <!> ")
   ); end if
 (princ) 
 ); end of c:3csv

Posted

ASMI,

 

Thank you very much, this is just what i was looking for.

I did notice that in the output file the values were separated by semi colons rather than commas. Was there a reason for this?

I have managed to play about with your *.lsp to get the output values to be separated by commas and this does seem to work.

I also stuck a little description at the start and a line at the end to remind me what command to type. I've attached the *.lsp for anyone else who might find it useful.

 

;;;--------------------------------------------------------------------------;
;;; DESCRIPTION
;;;   This is a utility that exports the X,Y,Z co-ordinates of the selected 3D polyline to a *.csv file.
;;;   The *.csv file is saved in the same folder as the autocad *.DWG with the same file name prefix.
;;;   e.g. the CSV file created from a 3d polyline extracted from "Example.dwg" would be named "Example.csv"
;;;   
;;;   Thank you to ASMI for writing this .lsp
;;;   

(defun c:3csv (/ cPl cFmn fVar pLst cAns *error*)

 (vl-load-com)

 (defun *error*(msg) 
   (if fVar(close fVar))
   (princ) 
   ); end of *error*

 (defun Extract_3DPoly_Vertexes(Ent / cLst oLst)
   (if(= 'ENAME(type Ent))
     (setq Ent(vlax-ename->vla-object Ent))
     ); end if
   (if(= "AcDb3dPolyline"(vla-get-ObjectName Ent))
     (progn
       (setq cLst(vlax-safearray->list
           (vlax-variant-value
             (vla-get-Coordinates Ent))))
   (while cLst
     (setq oLst(cons
             (list
           (car cLst)
           (cadr cLst)
           (nth 2 cLst))
             oLst)
       ); end setq
     (repeat 3(setq cLst(cdr cLst)))
      ); end while
   (reverse oLst)
   ); end progn
     ); end if
   ); end of Extract_3DPoly_Vertexes

 (if(and
      (setq cPl(entsel "\nSelect 3D-Polyline > "))
      (= "POLYLINE"(cdr(assoc 0(entget(setq cPl(car cPl))))))
      ); and
   (progn
     (setq fVar(open(setq cFmn(strcase(strcat(getvar "DWGPREFIX")
          (vl-filename-base(getvar "DWGNAME")) ".csv"))) "a")
       pLst(Extract_3DPoly_Vertexes cPl)
      ); end setq
     (write-line "X,Y,Z" fVar)
     (foreach pt pLst
     (write-line
       (strcat(rtos(car pt))","(rtos(cadr pt))","(rtos(last pt)))
       fVar)
       ); end foreach
      (close fVar)
     (alert(strcat "\nCSV File location: " cFmn))
     ); end progn
   (princ "<!> It isn't 3D-Polyline <!> ")
   ); end if
 (princ) 
 ); end of c:3csv

(princ "\nType 3csv to run")

Thank you again,

Andrew

3csv.lsp

Posted
I also stuck a little description at the start and a line at the end to remind me what command to type.

:D:D With other words: "Asmi, you should better comment your code" :D:D

Posted

> ARV

 

I did notice that in the output file the values were separated by semi colons rather than commas. Was there a reason for this?

 

It for distribution coordinates to separate MS Excel cells (try to open file with commas and semicolumns in Excel).

 

> fuccaro

 

With other words: "Asmi, you should better comment your code".

 

You are partly right, I not so well make comments on a code. But in this case I considered this code as trial but if it satisfies let remains as is.

  • 1 year later...
Posted

Hi asmi & ARV,

Thanks Asmi for the lisp & thanks ARV for the commenting\description.

can u please let me know how to add one more data to this CSV its the layer name of the line & can we also select multiple lines instead of single line always. Is it possible can u please let me know? I am not that good in lisp so I need ur help.

Any help is appreciated.

Posted
> ARV

 

 

 

It for distribution coordinates to separate MS Excel cells (try to open file with commas and semicolumns in Excel).

 

> fuccaro

 

 

 

You are partly right, I not so well make comments on a code. But in this case I considered this code as trial but if it satisfies let remains as is.

 

Program isn't working for me. All I get is the alpha x y z in the first three cells of the worksheet with no coordinates that should follow?

I have not modified the code in any way at all. It writes to the correct directory location. Any clue what may be wrong here?

Posted (edited)

;;; Try this this is the original from alex

 

;;;--------------------------------------------------------------------------;
;;; DESCRIPTION
;;; This is a utility that exports the X,Y,Z co-ordinates of the selected 3D polyline to a *.csv file.
;;; The *.csv file is saved in the same folder as the autocad *.DWG with the same file name prefix.
;;; e.g. the CSV file created from a 3d polyline extracted from "Example.dwg" would be named "Example.csv"
;;; 
;;; Thank you to ASMI for writing this .lsp
;;; 

(defun c:3csv (/ cPl cFmn fVar pLst cAns *error*)

(vl-load-com)

(defun *error*(msg) 
(if fVar(close fVar))
(princ) 
); end of *error*

(defun Extract_3DPoly_Vertexes(Ent / cLst oLst)
(if(= 'ENAME(type Ent))
(setq Ent(vlax-ename->vla-object Ent))
); end if
(if(= "AcDb3dPolyline"(vla-get-ObjectName Ent))
(progn
(setq cLst(vlax-safearray->list
(vlax-variant-value
(vla-get-Coordinates Ent))))
(while cLst
(setq oLst(cons
(list
(car cLst)
(cadr cLst)
(nth 2 cLst))
oLst)
); end setq
(repeat 3(setq cLst(cdr cLst)))
); end while
(reverse oLst)
); end progn
); end if
); end of Extract_3DPoly_Vertexes

(if(and
(setq cPl(entsel "\nSelect 3D-Polyline > "))
(= "POLYLINE"(cdr(assoc 0(entget(setq cPl(car cPl))))))
); and
(progn
(setq fVar(open(setq cFmn(strcase(strcat(getvar "DWGPREFIX")
(vl-filename-base(getvar "DWGNAME")) ".csv"))) "a")
pLst(Extract_3DPoly_Vertexes cPl)
); end setq
(write-line "X,Y,Z" fVar)
(foreach pt pLst
(write-line
(strcat(rtos(car pt))","(rtos(cadr pt))","(rtos(last pt)))
fVar)
); end foreach
(close fVar)
(alert(strcat "\nCSV File location: " cFmn))
); end progn
(princ "<!> It isn't 3D-Polyline <!> ")
); end if
(princ) 
); end of c:3csv

(princ "\nType 3csv to run")

Edited by SLW210
Posted (edited)
;;; Try this this is the original from alex

 

;;;--------------------------------------------------------------------------;
;;; DESCRIPTION
;;; This is a utility that exports the X,Y,Z co-ordinates of the selected 3D polyline to a *.csv file.
;;; The *.csv file is saved in the same folder as the autocad *.DWG with the same file name prefix.
;;; e.g. the CSV file created from a 3d polyline extracted from "Example.dwg" would be named "Example.csv"
;;; 
;;; Thank you to ASMI for writing this .lsp
;;; 

(defun c:3csv (/ cPl cFmn fVar pLst cAns *error*)

(vl-load-com)

(defun *error*(msg) 
(if fVar(close fVar))
(princ) 
); end of *error*

(defun Extract_3DPoly_Vertexes(Ent / cLst oLst)
(if(= 'ENAME(type Ent))
(setq Ent(vlax-ename->vla-object Ent))
); end if
(if(= "AcDb3dPolyline"(vla-get-ObjectName Ent))
(progn
(setq cLst(vlax-safearray->list
(vlax-variant-value
(vla-get-Coordinates Ent))))
(while cLst
(setq oLst(cons
(list
(car cLst)
(cadr cLst)
(nth 2 cLst))
oLst)
); end setq
(repeat 3(setq cLst(cdr cLst)))
); end while
(reverse oLst)
); end progn
); end if
); end of Extract_3DPoly_Vertexes

(if(and
(setq cPl(entsel "\nSelect 3D-Polyline > "))
(= "POLYLINE"(cdr(assoc 0(entget(setq cPl(car cPl))))))
); and
(progn
(setq fVar(open(setq cFmn(strcase(strcat(getvar "DWGPREFIX")
(vl-filename-base(getvar "DWGNAME")) ".csv"))) "a")
pLst(Extract_3DPoly_Vertexes cPl)
); end setq
(write-line "X,Y,Z" fVar)
(foreach pt pLst
(write-line
(strcat(rtos(car pt))","(rtos(cadr pt))","(rtos(last pt)))
fVar)
); end foreach
(close fVar)
(alert(strcat "\nCSV File location: " cFmn))
); end progn
(princ "<!> It isn't 3D-Polyline <!> ")
); end if
(princ) 
); end of c:3csv

(princ "\nType 3csv to run")

 

Resulting xls file from this is just the following

 

X Y Z

X Y Z

 

alpha just as above, no coords at all (Xcell out of 2000 office premium) w/ Acad 8 (17.1s)

can't figure out why no coords below the header?

Edited by SLW210
Posted
Resulting xls file from this is just the following

 

X Y Z

X Y Z

 

alpha just as above, no coords at all (Xcell out of 2000 office premium) w/ Acad 8 (17.1s)

can't figure out why no coords below the header?

 

Edit:

Ah ha, stupid me, line to grab is 3Dpoly, not just any old pline !!

thanks for neat code...... works perfect after dummy draws correct linetype !

  • 4 months later...
Posted

Could you please expand it to multiple selection of polylines? :( I have about 500000 coordinates to extract

 

Thank you

  • 2 years later...
Posted

Hi Lee Mac, first of all "What a great programming!" Respect.

 

I have a request do. Is it possible to write the points out to file from a 3D poly not only from the vertexes but from points with a certain distance along the 3dpolyline?

We need this to get the alignment from Civil 3D in to Revit as a Revit object instead as a CAD object. With the last one you can not do a sweep with addaptive points (for the insiders of Revit).

 

greetz Ritchy

Posted

Hi Ritchy,

 

Hi Lee Mac, first of all "What a great programming!" Respect.

 

Firstly, thank you for your appreciation of my work, I'm glad you like it :)

 

I have a request do. Is it possible to write the points out to file from a 3D poly not only from the vertexes but from points with a certain distance along the 3dpolyline?

 

This is not directly possible with the current program, though, as an alternative indirect method, you could use the AutoCAD Measure command to generate points at specific distances along your object, then use my Point Manager program (or AutoCAD's Data Extraction) to extract the coordinates of these points to file.

Posted

That will do the trick. Had to look better. Was only focused on the 3dpline. Thanks!

  • 8 months later...
Posted

Hi All,

I am newbie to this forum.

 

I am trying to generate a .CSV file of polygons made with pline (they don't have a z value). Is there anyone that could edit the lisp routine in this thread in order for it to work with plines and to also select multiple polygons as opposed to selecting individually?

 

Any help muchly apreciated

Thanks

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