提取三维多段线坐标
你好有人知道从三维多段线提取x、y、z顶点数据并将其导出到的方法吗。csv(或.txt文件)
ASMI的3cord工具与我想要的很接近
(我不允许发布链接)
遗憾的是,这在AutoCAD 2004中不起作用,并且不会输出到文件。
提前感谢,
安得烈 你可以用VBA写一些非常简单的东西。 这是可行的,但需要进一步完善。
(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 ASMI,
非常感谢,这正是我想要的。
我确实注意到,在输出文件中,值用分号而不是逗号分隔。这有什么原因吗?
我已经设法和你的*玩了。lsp将输出值用逗号分隔,这似乎确实有效。
我还在开头加了一点描述,在结尾加了一行,提醒我键入什么命令。我已附上*。lsp适用于任何其他可能觉得有用的人。
;;;--------------------------------------------------------------------------;
;;; 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")
再次感谢大家,
安得烈
3csv。lsp :D和其他文字:“Asmi,您最好注释您的代码”:D >抗逆转录病毒
将MS Excel单元格分开(尝试在Excel中打开带有逗号和半列的文件)是为了获得分布坐标。
>福卡罗
你说得有点对,我对代码的评论不太好。但在本例中,我将此代码视为试用代码,但如果它满足要求,则保持原样。 嗨,asmi和ARV,
感谢Asmi的lisp和ARV的评论\描述。
你能告诉我如何在这个CSV中再添加一个数据吗?这是线的层名称。我们可以选择多条线而不是总是选择单行吗。你能告诉我吗?我的Lisp程序不太好,所以我需要你的帮助。
感谢您的帮助。
这个程序不适合我。我得到的只是工作表前三个单元格中的alpha x y z,后面没有坐标?
我没有以任何方式修改代码。它写入正确的目录位置。有什么线索吗? ;;; 试试这个这是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")
由此产生的xls文件如下所示
X Y Z
X Y Z
alpha如上所述,完全没有coords(2000 office premium中的Xcell),带Acad 8(17.1s)
不明白为什么标题下没有坐标?
页:
[1]
2