2

I'm new to pyautocad and trying to work with an existing .dwg file open in a running instance of autoCAD.

from pyautocad import Autocad, APoint
acad = Autocad(create_if_not_exists=False, visible = True)
acad.Application #this gives me an error

I cannot even get the active application instance. When I try to access the active application instance via acad.Application or acad.app I get an error:

[WinError -2147221005] Invalid class sting

Even the example from the docs doesn't work.

acad = Autocad(create_if_not_exists=True)
acad.prompt("Hello, Autocad from Python\n")
print(acad.doc.Name)

What am I doing wrong? Is there another Python library I can use to interact with AutoCAD?

unbutu
  • 125
  • 2
  • 9

1 Answers1

0

You can try directly using comtypes modules as pyautocad itself is based on comtypes:

import win32com.client

acad = win32com.client.Dispatch("AutoCAD.Application")

acad.Visible = True
acadModel = acad.ActiveDocument.ModelSpace

You can also check our blog for more details.

RiveN
  • 2,595
  • 11
  • 13
  • 26