参考如下规则
Try
Dim g_App As Inventor.InventorServer = ThisApplication
Dim AssDoc As Inventor.AssemblyDocument= ThisDoc.Document
' Create a new part document that will be the shrinkwrap substitute
Dim oPartDoc As PartDocument
oPartDoc = g_App.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)
Dim oPartDef As PartComponentDefinition
oPartDef = oPartDoc.ComponentDefinition
Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(AssDoc.FullDocumentName)
' Set various shrinkwrap related options
oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
Call oDerivedAssemblyDef.SetHolePatchingOptions(DerivedHolePatchEnum.kDerivedPatchNone)
Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(DerivedGeometryRemovalEnum.kDerivedRemoveNone)
Dim oDerivedAss As DerivedAssemblyComponent
oDerivedAss = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
Call oDerivedAss.BreakLinkToFile()
' Save the part
Dim partname As String=ThisDoc.PathAndFileName(False)& ".ipt"
ThisApplication.ActiveView.Fit
ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute
Call oPartDoc.SaveAs(partname , False)
Catch ex As Exception
ErrorMessage = "Error creating ipt file."
End Try
If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!
如果我的回帖解决了您的问题,请点击 "接受为解决方案" 按钮. 这可以帮助其他人更快的找到解决方案!
王 承之
Autodesk AGN [Inventor 俱乐部] Leader
Inventor Club | Bilibili
oPartDoc = g_App.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)
这句话里面加上你的模板路径和名称就可以了
oPartDoc = g_App.Documents.Add(DocumentTypeEnum.kPartDocumentObject, 模板, True)