ARV Posted September 9, 2008 Posted September 9, 2008 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 Quote
CmdrDuh Posted September 9, 2008 Posted September 9, 2008 you could write something in VBA that would be pretty simple. Quote
ASMI Posted September 9, 2008 Posted September 9, 2008 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 Quote
ARV Posted September 10, 2008 Author Posted September 10, 2008 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 Quote
fuccaro Posted September 10, 2008 Posted September 10, 2008 I also stuck a little description at the start and a line at the end to remind me what command to type. :D With other words: "Asmi, you should better comment your code" :D Quote
ASMI Posted September 10, 2008 Posted September 10, 2008 > 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. Quote
rnbhat1 Posted September 14, 2009 Posted September 14, 2009 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. Quote
stevesfr Posted September 14, 2009 Posted September 14, 2009 > 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? Quote
rnbhat1 Posted September 14, 2009 Posted September 14, 2009 (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 March 6, 2013 by SLW210 Quote
stevesfr Posted September 14, 2009 Posted September 14, 2009 (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 March 6, 2013 by SLW210 Quote
stevesfr Posted September 14, 2009 Posted September 14, 2009 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 ! Quote
nadirkazan Posted January 17, 2010 Posted January 17, 2010 Could you please expand it to multiple selection of polylines? I have about 500000 coordinates to extract Thank you Quote
Lee Mac Posted January 17, 2010 Posted January 17, 2010 Have you tried this? http://www.cadtutor.net/forum/showthread.php?t=42954 Quote
Ritchy the Kidney Posted June 19, 2012 Posted June 19, 2012 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 Quote
Lee Mac Posted June 19, 2012 Posted June 19, 2012 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. Quote
Ritchy the Kidney Posted June 19, 2012 Posted June 19, 2012 That will do the trick. Had to look better. Was only focused on the 3dpline. Thanks! Quote
Drafty Posted March 6, 2013 Posted March 6, 2013 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 Quote
Lee Mac Posted March 6, 2013 Posted March 6, 2013 Welcome to CADTutor. Maybe this will help: http://www.cadtutor.net/forum/showthread.php?38525-Coordinates-Blocks-and-Text&p=519887&viewfull=1#post519887 Quote
Recommended Posts
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.