不确定您希望输出看起来如何,
-
- (defun
- c:test2 (/ cLn cPl lLst pLst fn f)
- (if (and
- (setq cLn (entsel "\nPick line > "))
- (setq cPl (entsel "\nPick pentagon > "))) ; and
- (progn
- (setq
- cLn (entget (car cLn)) ; get DXF-codes of line
- cPl (entget (car cPl)) ; get DXF-codes of polyline
- lLst (list ; extract list of ((start pt)(end pt)) for line
- (cdr (assoc 10 cLn))
- (cdr (assoc 11 cLn))) ; end list
- pLst (mapcar
- 'cdr ; extract list ((vertex1)(vertex2)...) for polyline
- (vl-remove-if-not '(lambda (i) (= 10 (car i))) cPl)))
- ; end pLst
- ) ; end progn
- ) ; end if
- (list lLst pLst) ; returns ((list 1)(list 2))
- (if (not
- (setq
- fn
- (getfiled "Export to file" (getvar "dwgprefix") "csv" 1)))
- (progn (alert "No file selected!") (quit)))
- (setq f (open fn "a"))
- [color=blue](write-line[/color]
- [color=blue] (strcat[/color]
- [color=blue] (vl-princ-to-string (car llst))[/color]
- [color=blue] ","[/color]
- [color=blue] (vl-princ-to-string (cadr llst)))[/color]
- [color=blue] f)[/color]
- [color=blue](write-line[/color]
- [color=blue] (strcat[/color]
- [color=blue] (vl-princ-to-string (car plst))[/color]
- [color=blue] ","[/color]
- [color=blue] (vl-princ-to-string (cadr plst)))[/color]
- [color=blue] f)[/color]
- (close f)
- (alert (strcat "Finish export points to file: " fn)))
结果如下所示
两列
A列
(-122.807 179.928 0.0)
(-4.48415 271.639 0.0)
(118.262 191.53)
(167.471 248.987)
B列
(-122.807 179.928 0.0)
(-4.48415 271.639 0.0)
(118.262 191.53)
(167.471 248.987)
我改变了这个
(打开fn“w”)
到这个
(打开fn“a”))
w-开放写作。如果文件名不存在,则会创建并打开一个新文件。如果文件名已经存在,
其现有数据被覆盖。传递到打开文件的数据实际上不会写入,直到使用关闭函数关闭文件。
虽然
a-打开以进行追加。如果文件名不存在,则会创建并打开一个新文件。如果文件名已经存在,
它被打开,指针位于现有数据的末尾,因此写入文件的新数据将附加到现有数据。
希望这有帮助 |