悬赏已过期 后悬赏过期
悬赏

zwcad怎么获取曲线长度,怎么读取指令框输出参数?

邀请:

我使用pyzwcad:

使用获取命令框里的数据,但不起作用

import win32com.client

# 定义事件处理类
class CommandEvents:
    def OnCommandWillStart(self, CommandName):
        """命令开始时触发"""
        print(f"命令开始: {CommandName}")

    def OnCommandEnded(self, CommandName):
        """命令结束时触发"""
        print(f"命令结束: {CommandName}")
        if CommandName == "LIST":
            # 获取命令输出
            doc = self.Application.ActiveDocument
            ed = doc.Utility
            output = ed.GetString(True, "LIST命令输出:\n")
            print("输出内容:", output)

# 连接中望CAD并注册事件
zwcad = win32com.client.Dispatch("ZWCAD.Application")
win32com.client.WithEvents(zwcad, CommandEvents)  # 关键修正:动态绑定事件

# 测试命令监听
doc = zwcad.ActiveDocument
doc.SendCommand("LINE 0,0 100,100\n")  # 绘制测试线
doc.SendCommand("LIST\n")              # 执行LIST命令

直接打印不出来,后来查了一下接口没有OnCommandWillStartOnCommandEnded函数,所以直接使用

doc = self.Application.ActiveDocument
            ed = doc.Utility
            output = ed.GetString(True, "LIST命令输出:\n")
            print("输出内容:", output)

但是,功能还是不对:GetString是读取从cad里输入的信息,而我需要读取输出指令,
所以又去找线条参数:

from pyzwcad import ZWCAD,APoint
zwcad=ZWCAD()

p1=APoint(x1,y1)
p2=APoint(x2,y2)
.......

line=zwcad.model.AddLine(p1,p2)
print(line.length)  # 可以打印出来

points=[p1,p2,p3,p4.......]
point_t=points[1]-points[0]
point_w=points[-1]-points[-2]

spline=zwcad.model.AddSpline(points,point_t,point_w)
print(spline.length)  # 直接显示“没有length参数”

直线有length参数,但是曲线没有。

怎么读取指令框输出参数,或者读取曲线的长度参数,(曲线上的点,沿着曲线到终点的长度)

收藏0
分享
您的回答

回答

默认排序 时间排序
图片审查中...
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
复制链接
微信扫码
已复制到剪贴板