2015-06-15 173 views
1

我嘗試將Python用於Autodesk Inventor API。例如,我嘗試在使用Python製作的Inventor零件文檔中製作新草圖。使用Python的Autodesk Inventor API

但我在添加草圖時遇到了問題。我所有的嘗試都是錯誤的。 這裏的(很多之一)的代碼示例:

import win32com.client 

from win32com.client import constants 


invApp = win32com.client.Dispatch("Inventor.Application") 
invApp.Visible = True 

asd = invApp.Documents.Add(constants.kPartDocumentObject,"",True) 

nsk = asd.PartDocuments.ComponentDefinition.Sketches.Add() 

有一個錯誤:

AttributeError: '<win32com.gen_py.Autodesk Inventor Object Library.Document instance at 0x284773312>' object has no attribute 'PartDocuments' 

我試圖找到調用屬性的正確方法,但我沒有任何成功。

回答

0

我不是Python的專家......但Documents.Add方法返回新的文件,所以ASD應包含PartDocument型

asd = invApp.Documents.Add(constants.kPartDocumentObject,"",True) 
nsk = asd.ComponentDefinition.Sketches.Add() 
+0

感謝。我試過這樣,但也有同樣的錯誤:對象沒有屬性'ComponentDefinition'。 –

+0

我認爲它也可能是不正確的工作模塊「win32com.client」 –