如何利用lisp程序一次性提取CAD中点的坐标(不要点击每个点,太多了麻烦)
(defun c:md()
(setvar "cmdecho" 0)
(COMMAND ".UNDO" "BE")
(command "-units" "2" "3" "2" "3" "" "")
(setq fp (open "d:/桩号坐标值.xls" "a") s (getvar "cmdecho") n (getint "\n请输入总桩数! "))
(princ "桩号" fp)(princ "\t" fp)
(princ "X坐标值" fp)(princ "\t" fp)
(princ "Y坐标值" fp)(princ "\n" fp)
(repeat n
(setq k (getstring "\n输入桩号(如:K1)!")
p (getpoint "\n选取节点!")
x (strcat "X=" (rtos (nth 0 p)))
y (strcat "Y=" (rtos (nth 1 p))))
(princ k fp)(princ "\t" fp)
(princ x fp)(princ "\t" fp)
(princ y fp)(princ "\n" fp))
(close fp)
(setvar "cmdecho" s))
(princ "\n提示:输入 MD 命令来运行本程序!")
(princ)
(DEFUN C:TT (/ SS FN F N EN PT X Y)
(setq ss (ssget "x" '((0 . "point"))))
(if ss
(progn
(setq fn "f:\\坐标.txt")
(setq f (open fn "w"))
(repeat (setq n (sslength ss))
(setq en (ssname ss (setq n (1- n))))
(setq pt (cdr (assoc 10 (entget en)))
x (car pt)
y (cadr pt)
)
(write-line (strcat (rtos x 2 3) "," (rtos y 2 3)) f)
)
(close f)
(startapp "notepad.exe" fn)
)
)
(princ)
)
这个是刚从网上看到的,说是图元集的方法,不过输入命令TT没反应啊。。求各位大神指教,急急急急急急!! 展开
推荐于2017-09-21 · 知道合伙人软件行家
(DEFUN C:TT ( / ss ff ss1 en pt x y)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(setvar "dimzin" 0)
(vl-load-com);;加载vlax扩展函数
(setq ss (ssget '((0 . "point"))) n 0);;请选择点
(if (/= ss nil)
(progn
(setq ff (open "d://文字到TXT.txt" "w") ss1 '());;在D盘建立记事本《文字到TXT》这里可以查看内容
(repeat (sslength ss);;循环选择
(setq en (ssname ss n) n (+ n 1);;提取图元
pt (cdr (assoc 10 (entget en)));;取得点坐标
ss1 (cons pt ss1);;加入表
)
)
(setq ss1 (vl-sort ss1 (function (lambda (x y)(< (car x) (car y))))));;X排序从左到右
(setq ss1 (vl-sort ss1 (function (lambda (x y)(> (cadr x) (cadr y))))));;Y排序从上到下
(foreach en ss1;;函数遍历表,将其中每一个元素依次赋给变量,并对每一个表达式求值
(setq x (rtos (car en) 2 5))
(setq y (rtos (cadr en)2 5));;取得Y坐标精确到小数点后5位
(princ x ff)
(princ "," ff)
(princ y ff)
(princ "\n" ff)
)
(close ff)
)
)
(princ)
)
这个TT命令修改了一下,可以对点坐标排序,保存到D盘《文字到TXT》记事本里面;实际上坐标需要X=;Y=这个标记的,这个标记表示大地坐标;大地坐标X=cad里面的y坐标,同样的Y=cad里面的x坐标,所以不能够随便修改文字格式。
提取的对象必须是(点),交点或块里面的点都不能够提取。
要得到交点的话,需要别的方法,如这条多段线里面有多少个点提取出来,就可以了。
(setq ss (ssget '((0 . "point"))) n 0);以下修改为:
(setq ss (ssget '((0 . "point,LWPOLYLINE"))) n 0)
(if (/= ss nil)
(progn
(setq ff (open "d://文字到TXT.txt" "w") ss1 '())
(repeat (sslength ss)
(setq en (ssname ss n) n (+ n 1)
pt (mapcar 'cdr (vl-remove-if '(lambda (X) (/= 10 (car x))) (entget en)))
i (length pt)
L 0
)
(repeat i
(setq pt1 (nth L pt)
L (+ L 1)
ss1 (cons pt1 ss1);;加入表
)
)
)
(setq ss1 (reverse ss1) ss (cdr (assoc 0 (entget (ssname ss 0)))));;取得第一个图元
(if (/= ss "LWPOLYLINE");不是多段线的话排序
(setq ss1 (vl-sort ss1 (function (lambda (x y)(< (car x) (car y)))))
ss1 (vl-sort ss1 (function (lambda (x y)(> (cadr x) (cadr y)))))
)
)
(foreach en ss1
(setq x (rtos (car en) 2 5))
(setq y (rtos (cadr en)2 5))
(princ x ff)
(princ "," ff)
(princ y ff)
(princ "\n" ff)
)
(close ff)
)
)
(princ)
)
输出的坐标与CAD中实际坐标值不一样啊,而且比如说下图中自己划分网格数的坐标点数有200多个,txt中生成的有500多个怎么回事啊。。
autocad的坐标分为系统坐标和用户坐标,两者可以不一样。