reclosedev / pyautocad

AutoCAD Automation for Python ⛺
http://pypi.python.org/pypi/pyautocad/
BSD 2-Clause "Simplified" License
506 stars 143 forks source link

_ctypes.COMError, need help #9

Open workload opened 8 years ago

workload commented 8 years ago

Hi reclosedev, Your lib helps a lot... And here are 2 question I wand to ask. The first one is can I save the drawing use acad.doc.save(r'C:\Users\Administrator\Desktop\1.dwg') or acad.doc.save(r'C:\Users\Administrator\Desktop\1.dwg')?

the example code below:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pyautocad import Autocad, APoint

acad = Autocad(create_if_not_exists=True)
acad.prompt("Hello, Autocad from Python\n")
print acad.doc.Name
try:
    acad.doc.save(r'C:\Users\Administrator\Desktop\1.dwg')
except Exception as e:
    print e

The exception show _ctypes.COMError (-2147352562, '\xce\xde\xd0\xa7\xb5\xc4\xb2\xce\xca\xfd\xca\xfd\xc4\xbf\xa1\xa3', (None, None, None, 0, None))

The second question is how to hatch an object.The doc of ActiveX/VBA gives a VBA code below:

Sub Ch4_AppendInnerLoopToHatch()
    Dim hatchObj As AcadHatch
    Dim patternName As String
    Dim PatternType As Long
    Dim bAssociativity As Boolean

    ' 定义和创建图案填充
    patternName = "ANSI31"
    PatternType = 0
    bAssociativity = True
    Set hatchObj = ThisDrawing.ModelSpace. _
        AddHatch(PatternType, patternName, bAssociativity)

    ' 创建图案填充的外部环
    Dim outerLoop(0 To 1) As AcadEntity
    Dim center(0 To 2) As Double
    Dim radius As Double
    Dim startAngle As Double
    Dim endAngle As Double
    center(0) = 5: center(1) = 3: center(2) = 0
    radius = 3
    startAngle = 0
    endAngle = 3.141592
    Set outerLoop(0) = ThisDrawing.ModelSpace. _
       AddArc(center, radius, startAngle, endAngle)
    Set outerLoop(1) = ThisDrawing.ModelSpace. _
       AddLine(outerLoop(0).startPoint, outerLoop(0).endPoint)

    ' 将外部环附加到 Hatch 对象
    hatchObj.AppendOuterLoop (outerLoop)

    ' 创建一个圆作为图案填充的内部环
    Dim innerLoop(0) As AcadEntity
    center(0) = 5: center(1) = 4.5: center(2) = 0
    radius = 1
    Set innerLoop(0) = ThisDrawing.ModelSpace. _
                                 AddCircle(center, radius)

    ' 将圆作为内部环附加到图案填充
    hatchObj.AppendInnerLoop (innerLoop)

    ' 计算并显示图案填充
    hatchObj.Evaluate
    ThisDrawing.Regen True
End Sub

the code hatchObj.AppendInnerLoop (innerLoop) how to rewrite use python? Need your help, thanks a lot.