利用COM在AutoCAD中制作Hatch对象

2024-09-27 21:26:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Python语言和comtypes库处理AutoCAD绘图。这是我的代码片段:

from comtypes.client import *
from comtypes.automation import *

def connect_acad(self):
    self.acad = GetActiveObject("AutoCAD.Application")
    self.dwg = self.acad.ActiveDocument
    self.mspace = self.dwg.ModelSpace

def mark_point(self, xy, num, lay):

    def point(*args):
        lst = [0.]*3
        if len(args) < 3:
            lst[0:2] = [float(x) for x in args[0:2]]
        else:
            lst = [float(x) for x in args[0:3]]
        return VARIANT(array("d",lst))

    def variant(data):
        return VARIANT(VT_VARIANT, data)

    def vararr(*data):
        if (  len(data) == 1 and 
              isinstance(data, collections.Iterable) ):
            data = data[0]
        return map(variant, data)

    p1 = point(xy[0], xy[1])
    ent = self.mspace.AddCircle(p1, 0.3)
    htch = self.mspace.AddHatch(0, 'SOLID', False)
    htch.appendOuterLoop(vararr([ent,]))
    htch.Evaluate()

如果有人感兴趣,请在此输入完整代码:https://github.com/nsedenkov/py_acadcoord/blob/master/acadcoord.py

任何事情都是正确的,除了命令附件.htoop引发异常“ComTypeError”。也许有人知道AutoCAD的数组是不是有人知道?谢谢您!在


Tags: 代码selfdatareturndefargspointvariant
1条回答
网友
1楼 · 发布于 2024-09-27 21:26:14

预期类型为:

Type: Variant (array of Arc, Circle, Ellipse, Line, Polyline, Region, Spline objects)

我还建议再次检查一下情况:

An array of objects forming a closed boundary. The array can consist of one or more objects. If more than one object is used, their endpoints must coincide for the loop to be created properly.

请参阅http://knowledge.autodesk.com/support/autocad-mechanical/getting-started/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-ActiveX/files/GUID-4CA06494-CDFF-46FA-9E1D-A0E8220F69F4-htm.html上的完整文档

相关问题 更多 >

    热门问题