lisp - 文本实体的导出坐标
问题描述
我想将特定图层的所有坐标和文本本身提取到 CSV 文件中。我使用的是 Mac 版的 AutoCAD 2018。DATAEXTRACT 似乎在 Mac 上不可用,并且 -ATTEXT 总是写:“提取文件中的 0 条记录。” 使用以下模板文件:
NAME C008000
X N007001
Y N007001
Z N007001
我也用 lisp 尝试过,但我只到了这里:
(defun c:asdf ()
(setq coordinates (assoc 10 (entget (entlast)))))
(alert coordinates)
)
有任何想法吗?提前致谢!
解决方案
抱歉回复晚了,我写了一些功能并根据您的需要进行了修改。加载这个 lisp 并输入命令 TEXT2CSV。
然后程序会询问您图层名称、输出文件夹名称和 CSV 文件名称。如果输入正确,则创建 CSV 文件并保存在目标位置
;
(Defun C:text2CSV (/ extractText FolderBox
makecsvstring lyr layerlist
layerstring
)
;Function-----extractText ---------------------------------------------------------------------
;[filterLIst]--->send selection filter criteria to Function by default nil then select all text
(defun extractText
(filterLIst / outputfile f en i ss name x y z path)
;filterLIst check if filterLIst is nil then select all text from all layer
(if (= nil filterLIst)
(setq filterLIst
'((-4 . "<or") (0 . "TEXT") (0 . "MTEXT") (-4 . "or>"))
)
)
;get file path and file name
;(setq path (FolderBox "Select folder" "D:/" 0))
(setq path (FolderBox "Select Output folder:" "D:/" 0))
(initget 1)
(setq filename (getstring "\nType output CSV filename:"))
(setq outputfile
(strcat path
"/"
filename
".CSV"
)
)
;select entity from dwg and set initial parameter
(setq i -1
ss (ssget "X" filterLIst)
)
;create csv file
(if ss
(progn
(setq f (open outputfile "w"))
(if f
(progn
(write-line (strcat "Name," "X," "Y," "Z,") f)
(while (setq en (ssname ss (setq i (+ 1 i))))
(setq name (makecsvstring (cdr (assoc 1 (entget en)))))
(setq x (rtos (nth 1 (assoc 10 (entget en)))))
(setq y (rtos (nth 2 (assoc 10 (entget en)))))
(setq z (rtos (nth 3 (assoc 10 (entget en)))))
;write to csv
(write-line (strcat name "," X "," Y "," Z) f)
)
(close f)
;done
(Alert "Done!")
)
;if error
(print "\nWrong input unable to create csv file:")
)
)
(print "\nNo text entity found:")
)
(princ)
)
;;---------------------------------------------------------------EnD extractText --------------------------------
;This function to select output folder
(defun FolderBox (message directory flag / folder sh)
;; Arguments:
;; message: the message displayed in th dialog box
;; directory: the directory to browse
;; flag values:
;; 0 = Default
;; 1 = Only file system folders can be selected. If this bit is set, the OK button is disabled if the user selects a folder that doesn't belong to the file system (such as the Control Panel folder).
;; 2 = The user is prohibited from browsing below the domain within a network (during a computer search).
;; 4 = Room for status text is provided under the text box.
;; 8 = Returns file system ancestors only.
;; 16 = Shows an edit box in the dialog box for the user to type the name of an item.
;; 32 = Validate the name typed in the edit box.
;; 512 = None "New folder" button
;; 4096 = Enables the user to browse the network branch of the shell's namespace for computer names.
;; 8192 = Enables the user to browse the network branch of the shell's namespace for printer names.
;; 16384 = Allows browsing for everything.
(vl-load-com)
(setq shell (vlax-create-object "Shell.Application"))
(if (setq
folder (vlax-invoke
shell 'browseforfolder 0 message flag directory)
)
(setq folder
(vlax-get-property (vlax-get-property folder 'self) 'path)
)
(setq folder nil)
)
(vlax-release-object shell)
folder
)
;this function add " to start and end of supply string
(defun makecsvstring (instring)
(if (= nil instring)
(setq instring "")
)
(strcat "\"" instring "\"")
)
;if can send direct layer name
(setq layer (getstring "\nEnter Layer Name:" T))
(if (and (/= layer "") (/= layer nil))
(setq filterLIst
(append
(list (cons 8 layer))
'((-4 . "<or")
(0 . "TEXT")
(0 . "MTEXT")
(-4 . "or>")
)
)
)
(setq filterLIst
'((-4 . "<or")
(0 . "TEXT")
(0 . "MTEXT")
(-4 . "or>")
)
)
;you can Edit for more filter criteria
)
(extractText filterLIst)
)
您可以根据需要进一步修改代码希望这有帮助
推荐阅读
- android - 一旦根据字段添加到 Firestore 中,如何自动索引文档?
- node.js - 在后台做某事并在完成时通知用户
- three.js - 在threejs中渲染大型STL文件
- mongodb - Aggregation with min and max of different fields, incl. output
- python - 追随者从表是多对多关系吗?
- python - Pyparsing Forward() 语法递归
- ruby-on-rails - 尝试创建新实例时,它会丢失这样做所需的相关参数
- r - R list() 的 Python 等价物
- java - 有没有办法在抽象类中使用构建器模式?
- database - 使用 Form.Requery 时出现运行时错误 3246