明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 206|回复: 2

[讨论] 批量坐标,请教大神

[复制链接]
发表于 2024-3-20 17:41 | 显示全部楼层 |阅读模式
1明经币


求教,我想实现,图形中,同边的位置,写文件时,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)

)
;********************************批量坐标************************************************

附件: 您需要 登录 才可以下载或查看,没有账号?注册
发表于 2024-3-20 21:03 | 显示全部楼层
本帖最后由 NSHX 于 2024-3-20 21:27 编辑

[size=9.5475pt]
Hi~ o(* ̄▽ ̄*)ブ

评分

参与人数 1明经币 +1 收起 理由
弥勒 + 1 很给力!

查看全部评分

回复

使用道具 举报

发表于 2024-3-20 21:26 | 显示全部楼层
(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里的数据,也就是赋值成重复的点名。剩下的就正常走了。

评分

参与人数 3明经币 +3 收起 理由
bluefcc1 + 1
bssurvey + 1 赞一个!
baitang36 + 1 很给力!

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-27 17:12 , Processed in 0.180492 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表