明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: wanhongron

[提问] 随心随意测距

[复制链接]
 楼主| 发表于 2022-5-18 17:13 | 显示全部楼层
@gzcsun侠,你的程序非常完美,辛苦了
发表于 2022-5-18 18:20 | 显示全部楼层
Python win32com

  1. import pythoncom
  2. import win32com.client

  3. Cad = win32com.client.Dispatch("AutoCAD.Application")
  4. Uti = Cad.ActiveDocument.Utility

  5. def pt(x, y, z=0):
  6.     return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (x, y, z))

  7. def dist(pt1, pt2):
  8.     x1 = pt1[0]; y1 = pt1[1]; x2 = pt2[0]; y2 = pt2[1]
  9.     return ((x2 - x1)**2 + (y2 - y1)**2)**0.5

  10. dd = 0
  11. pt1 = Uti.GetPoint(pt(0,0),"First point: ")
  12. while True:
  13.     pt2 = Uti.GetPoint(pt(pt1[0], pt1[1]), "Next point >>> ")
  14.     dd += dist(pt1, pt2)
  15.     Uti.Prompt("Total Dist= " + str(dd) + "\n\r")
  16.     pt1 = pt2



发表于 2022-5-18 21:11 | 显示全部楼层
gzcsun 发表于 2022-5-18 15:33
(defun c:tt1(/ N n1 P1 p22 P2)
  (setq n 0)
        (setq n1 0)

大师,很好用,能否把小数位数改为3位小数,谢谢 !
发表于 2022-5-19 12:44 | 显示全部楼层
liufii 发表于 2022-5-18 11:30
多谢分享!

试了下出现错误,只能测量一段,错误如下:

出现了相同的问题
发表于 2022-5-20 07:39 | 显示全部楼层
厉害,收藏一下
 楼主| 发表于 2022-5-21 08:38 | 显示全部楼层
能否把测的结果随鼠标位置显示
 楼主| 发表于 2022-5-21 10:24 | 显示全部楼层
或在屏幕中间显示,免得老是低头看命令栏
发表于 2022-5-21 11:19 | 显示全部楼层


;; 不具有通用性

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2022-5-21 14:53 | 显示全部楼层
wanhongron 发表于 2022-5-21 10:24
或在屏幕中间显示,免得老是低头看命令栏

打开动态输入就可以
发表于 2022-5-21 14:56 | 显示全部楼层
cj52000 发表于 2022-5-18 21:11
大师,很好用,能否把小数位数改为3位小数,谢谢 !

(rtos n 2 2)
改为
(rtos n 2 3)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-3 07:35 , Processed in 5.442629 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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