CAD二次开发 lisp提取提取质心及流水编号ZX python c#
(defun c:ZX()
(setvar"osmode" 0)
(setq dm (getstring “\n请输入村代码(大写字母):”))
(setq c1 (strcat dm “-ZDX”))
(setq c2 (strcat dm “-LSH”))
(setq huzhum “无编号”)
(princ "\n选取加入范围线...")
(setq plines (ssget (list (cons 0 "*POLYLINE") (cons 8 c1))))
(if (/= plines nil)
(progn
(setq count 0)
(while (< count (sslength plines))
(setq entnam1 (ssname plines count)) ;;;;返回选择集中指定图元
(setq entnam (entget entnam1 '("*"))) ;;;;获取对象定义数据
(setq zbc ())
(foreach gxz entnam (if (= 10 (car gxz))(setq zbc (cons (cdr gxz) zbc))))
(setq zbc (reverse zbc)) ;;倒置表的元素顺序
(setq dwdlst zbc dwdnum 0 xx 0 yy 0)
(while
(/= dwdlst nil)
(setq ptl (car dwdlst))
(setq dwdlst (cdr dwdlst))
(setq dwdnum (+ 1 dwdnum))
(setq x (nth 0 ptl)) ;;;;返回表中第N个元素
(setq y (nth 1 ptl))
(setq xx (+ x xx))
(setq yy (+ y yy))
);while
(setq x (/ xx dwdnum))
(setq y (/ yy dwdnum))
(setq dwd (list x y))
(setq huz (ssget "cp" zbc (list (cons 0 "TEXT") (cons 8 c2))))
(setq tm2 (entget (ssname huz 0)))
(setq huzhum (cdr (assoc 1 tm2))) ;;;;返回流水号
(setq fn (strcat "d:/" dm "-ZX.CSV"))
(setq fp1 (open fn "a"))
(write-line (strcat huzhum ","(rtos y 2 3) "," (rtos x 2 3) ",0" ) fp1)
(close fp1)
(command "change" entnam1 "" "p" "c" "2" "")
(setq count (+ 1 count))
(setq huzhum "无编号")
);while
));ifp
(close fn));defun