Results 1 to 2 of 2

Thread: Create Derived Part from Assembly

  1. #1
    Active Member ed.w.cler's Avatar
    Join Date
    2008-02
    Location
    Central IL
    Posts
    53
    Login to Give a bone
    0

    Default Create Derived Part from Assembly

    I am looking for some help getting started with some code that when executed will create a new derived part using the active assembly or part as a source. It would be really nice if it could break the link and delete the source files (if the user wishes). Any help would be appreciated.
    Ed
    Dell Precision T3400 - Q6600 @ 2.4GHz 8GB Ram - Nvidia Quadro FX 3700

  2. #2
    Active Member ed.w.cler's Avatar
    Join Date
    2008-02
    Location
    Central IL
    Posts
    53
    Login to Give a bone
    0

    Default Re: Create Derived Part from Assembly

    I got it. This code does most of it, I have mixed feelings about making it delete the source files, so I left that part out.

    Let me know what you think.

    Code:
    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
    Ed
    Dell Precision T3400 - Q6600 @ 2.4GHz 8GB Ram - Nvidia Quadro FX 3700

Similar Threads

  1. I crash every time I try to create a new part inside an Assembly
    By d.m.polsky in forum Inventor - General
    Replies: 1
    Last Post: 2012-10-05, 01:41 PM
  2. Drag or paste part into another part file to create assembly
    By Wish List System in forum Inventor Wish List
    Replies: 0
    Last Post: 2012-09-13, 07:08 PM
  3. Automatic IDW Creation of Derived Part/assembly
    By inventor.wishlist1738 in forum Inventor Wish List
    Replies: 0
    Last Post: 2008-06-08, 07:06 PM
  4. Mirror a Sheet Metal Part That is Not a Derived part
    By inventor.wishlist1738 in forum Inventor Wish List
    Replies: 0
    Last Post: 2006-05-14, 07:50 PM
  5. Making a Derived Part After Modifying Assembly
    By inventor.wishlist1738 in forum Inventor Wish List
    Replies: 0
    Last Post: 2006-05-04, 03:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •