用Python来玩Inventor,好处是简单暴力。缺点是,暂时没有现成的包。需要大量引用官方API。深入的事件处理,还需要慢慢琢磨。好吧,先记录下简单的。
import win32com.client
from win32com.client import gencache, Dispatch, constants, DispatchExoApp = win32com.client.Dispatch(‘Inventor.Application’)
oApp.Visible = True
mod = gencache.EnsureModule(‘{D98A091D-3A0F-4C3E-B36E-61F62068D488}’, 0, 1, 0)
oApp = mod.Application(oApp)
# oApp.SilentOperation = True
oDoc = oApp.ActiveDocument
oDoc = mod.PartDocument(oDoc)
#装配体文档时,注意切换调试
#oDoc = mod.AssemblyDocument(oDoc)
prop = oApp.ActiveDocument.PropertySets.Item("Design Tracking Properties")# 获取部分 iproperties
Descrip = prop(‘Description’).Value
Designer = prop(‘Designer’).Value
print("Description: ",Descrip)
print("Designer: ",Designer)# 获取重量和面积
MassProps = oDoc.ComponentDefinition.MassProperties
#零件面积
dArea = MassProps.Area
print("area: ",dArea)
#重量
mass = MassProps.Mass
print("mass: ",mass)
运行结果: