Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need Help fixing Code

1 REPLY 1
Reply
Message 1 of 2
DeerSpotter
192 Views, 1 Reply

Need Help fixing Code

The following code was given to me to use. Doesnt work 😕

 

I don't know how to make it work, as this is not my department. Any help will be appreciated with a smile 🙂

 

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

 TY!

 

(using inventor 2010)

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
1 REPLY 1
Message 2 of 2

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report