批量坐标,请教大神
求教,我想实现,图形中,同边的位置,写文件时,2.2,2.3 ,用1.2,1.3替代。源码那抄的忘记了。
;********************************批量坐标20231110************************************************
(defun c:plzb()
(setq os(getvar "osmode"))
(setvar "osmode" 0)
(setq ffn (getfiled "坐标写入文本文件" "c:/Users/Administrator/Desktop/坐标" "zlb" 1))
(setq high (getreal "\n请输入字高(默认2): "))
(if (= high nil) (setq high 2))
(setq opf (open ffn "w"))
(setq ss(ssget '((0 . "*LINE"))))
(setq txt (strcat "点" "," "X坐标" "," "Y坐标"))
(write-line txt opf)
(setq i -1)
(setq key 10)
(setq n(sslength ss))
(repeat n
(setq ent (entget (ssname ss (setq i (1+ i)))))
(setq qz ( - n (- n (+ i 1))))
(setq count 1)
(foreach xy ent
(if (eq (car xy) key)
(progn
(setq pe (cdr xy))
(setq x (rtos(cadr pe)2 3))
(setq y (rtos(car pe)2 3))
(setq Dname (strcat(strcat (itoa qz) ".") (itoa count)))
(write-line (strcat Dname "," x "," y) opf)
(setq p0 (list (car pe) (cadr pe)))
(biaozb p0 Dname high)
(setq count (1+ count))
)
)
)
)
(close opf)
(setvar "osmode" os)
(princ(strcat "\n坐标已写入文本: " ffn))
(princ)
)
(defun biaozb( pt dn zg );坐标,点名,字高
(setq fzx "X:" fzy "Y:")
(setq p1a (polar pt (* 0.3 pi) (* zg 3)))
(setq p1 (polar p1a (* 0.5 pi) (* zg 0.6))) ;注记位置
(setq p2 (polar p1a (* 1.5 pi) (* zg 0.6))) ;注记位置
(setq xx (nth 1 pt) yy (nth 0 pt))
(setq xx1 (rtos xx 2 3))
(setq yy1 (rtos yy 2 3))
(setq xxx (strcat fzx xx1))
(setq yyy (strcat fzy yy1))
(command "layer" "make" "坐标" "c""4" "坐标" "")
(command "pline" pt"w" 0 "" p1a "@14<0" "")
(command "text" "bl" p1 zg 0 xxx)
(command"text" "tl" p2 zg 0 yyy)
(setq p3 (polar p1a (* PI 0.5) (* zg 3)))
(command "layer" "make" "点号" "c""20" "点号" "")
(command "circle" pt 0.3)
(command "text" "TL"p3 zg 0 dn)
)
;********************************批量坐标************************************************
本帖最后由 NSHX 于 2024-3-20 21:27 编辑
Hi~ o(* ̄▽ ̄*)ブ
(defun c:plzb()
(setq pts nil);;初始化
(setq os(getvar "osmode"))
(setvar "osmode" 0)
(setq ffn (getfiled "坐标写入文本文件" "c:/Users/Administrator/Desktop/坐标" "zlb" 1));规定了文件后缀
(setq high (getreal "\n请输入字高(默认2): "))
(if (= high nil) (setq high 2))
(setq opf (open ffn "w"))
(setq ss(ssget '((0 . "*LINE"))))
(setq txt (strcat "点" "," "X坐标" "," "Y坐标"))
(write-line txt opf)
(setq i -1)
(setq key 10)
(setq n(sslength ss))
(repeat n
(setq ent (entget (ssname ss (setq i (1+ i)))))
(setq qz ( - n (- n (+ i 1))))
(setq count 1)
(foreach xy ent
(if (eq (car xy) key)
(progn
(setq pe (cdr xy))
(setq x (rtos(cadr pe)2 3))
(setq y (rtos(car pe)2 3))
(setq Dname (strcat(strcat (itoa qz) ".") (itoa count)))
(setq X2 (ATOF X));;把字符串X,转成数X2
(setq Y2 (ATOF Y));;把字符串Y,转成数Y2
(setq Dname2 (ATOF Dname));;把字符串点名,转成数Dname2
(setq pts (cons (list y2 x2 Dname2) pts));;把读取到的图形点,组成一个list
(setq pt3 (list Y2 X2 ));;设置当前点
(setq plist (vl-remove-if '(lambda (x3) (> (distance pt3 x3) 0.02)) pts));;从 pts中剔除距离当前点(pt3)大于0.02的点。预计剩余本身。
(setq listLength (length plist));;获取plist的长度
(if (= listLength 2);;长度=2说明,有重复点,这里也可以改成长度不等于1,或者大于1
(progn
(setq Dname (strcat (rtos(caddr(CADR plist)) 2 3 )));;通过调试,发现这样可以实现,但好像仅仅针对长度2有效。或许这里可以调整成最后一个表的第三个数据
)
)
(Write-line (strcat Dname "," x "," y) opf)
(setq p0 (list (car pe) (cadr pe)))
(biaozb p0 Dname high)
(setq count (1+ count))
)
)
)
)
(close opf)
(setvar "osmode" os)
(princ(strcat "\n坐标已写入文本: " ffn))
(princ)
)
(defun biaozb( pt dn zg );坐标,点名,字高
(setq fzx "X:" fzy "Y:")
(setq p1a (polar pt (* 0.3 pi) (* zg 3)))
(setq p1 (polar p1a (* 0.5 pi) (* zg 0.6))) ;注记位置
(setq p2 (polar p1a (* 1.5 pi) (* zg 0.6))) ;注记位置
(setq xx (nth 1 pt) yy (nth 0 pt))
(setq xx1 (rtos xx 2 3))
(setq yy1 (rtos yy 2 3))
(setq xxx (strcat fzx xx1))
(setq yyy (strcat fzy yy1))
(command "layer" "make" "坐标" "c""4" "坐标" "")
(command "pline" pt"w" 0 "" p1a "@14<0" "")
(command "text" "bl" p1 zg 0 xxx)
(command"text" "tl" p2 zg 0 yyy)
(setq p3 (polar p1a (* PI 0.5) (* zg 3)))
(command "layer" "make" "点号" "c""20" "点号" "")
(command "circle" pt 0.3)
(command "text" "TL"p3 zg 0 dn)
)
;********************************批量坐标************************************************
实现了,大体上是读取图形X,Y的时候构建一个点表pts。每读一个点,pts就多一个。
然后创建个临时表plist,计算当前点距离pts表里的点的距离,大于0.02(也可以自己改更小)的剔除,稳定剩一个,如果剩两个,就说明有重复点。这时候把点名Dname,赋值成plist里的数据,也就是赋值成重复的点名。剩下的就正常走了。
页:
[1]