Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey, im brand new to inventor and i was given this code to use in my assembly. How to execute it? I never did this before.
Any help will be appreciated with a smile 🙂
I am using inventor 2010 / routing
thanks!
Sub CreateDerivedPartFromAssembly()
'Set a reference to the current assembly document.
Dim AsmDoc As AssemblyDocument
Set AsmDoc = ThisApplication.ActiveDocument
'Create the name of the new part
Dim PartFileName As String
PartFileName = Left(AsmDoc.FullDocumentName, Len(AsmDoc.FullDocumentName) - 4) & ".ipt"
'Make a new part file
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
'Create a derived part feature
Dim oDerivedAsmDef As DerivedAssemblyDefinition
Set oDerivedAsmDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(AsmDoc.FullDocumentName)
Call oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAsmDef)
'Break the link to the assembly
oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Item(1).BreakLinkToFile
'Copy the iProperties from the assembly to the part
Dim Text As String
oPartDoc.PropertySets.Item("Design Tracking Properties").Item("Description").value = _
AsmDoc.PropertySets.Item("Design Tracking Properties").Item("Description").value
oPartDoc.PropertySets.Item("Summary Information").Item("Comments").value = _
AsmDoc.PropertySets.Item("Summary Information").Item("Comments").value
'Save the part
On Error GoTo ErrorHandler:
oPartDoc.SaveAs PartFileName, False
On Error GoTo 0
AsmDoc.Close
oPartDoc.Activate
Exit Sub
ErrorHandler:
MsgBox ("A file with the same name already exists." & Chr(13) & "You may want to delete the existing file and re-do this process.")
oPartDoc.Close (True)
Exit Sub
End Sub

..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................
See My LinkedIn Profile
Solved! Go to Solution.
