<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Inventor VBA - How to change DerivedPart reference in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/inventor-vba-how-to-change-derivedpart-reference/m-p/6660985#M106330</link>
    <description>&lt;P&gt;The following code VB.Net code will allow you to select a new base component for your derived part reference. One thing you need to be aware of is that the method only works if your target part's geometry is a basic geometric match with the original geometry. For instance, it works great with using Copy Design in Vault because Copy Design doesn't copies the base geometry for modification but does not (at least in Vault 2014) edit the derived part reference path.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    Public Sub DeriveComponentReplace()

        If ThisApplication.ActiveEditObject.DocumentType &amp;lt;&amp;gt; DocumentTypeEnum.kPartDocumentObject Then
            Exit Sub
        End If
        Dim oDoc As PartDocument = ThisApplication.ActiveEditDocument
        Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition

        Dim oSubs As Inventor.DerivedAssemblyComponents = oDef.ReferenceComponents.DerivedAssemblyComponents '.Item(1)
        Dim oSubs1 As DerivedPartComponents = oDef.ReferenceComponents.DerivedPartComponents
        If oSubs.Count = 0 Then
            If oSubs1.Count = 0 Then
                MessageBox.Show("No derived assembly components present.", "Derived Assembly Replace", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub
            End If
        End If
        Dim oRefFile As FileDescriptor
        Try
            oRefFile = oSubs.Item(1).ReferencedDocumentDescriptor.ReferencedFileDescriptor
        Catch
            oRefFile = oSubs1.Item(1).ReferencedDocumentDescriptor.ReferencedFileDescriptor
        End Try

        Dim AppPath As String = ShowOpenDialog(oDoc)
        If AppPath = "" Then
            Exit Sub
        End If
        Try
            oRefFile.ReplaceReference(AppPath)
        Catch
            MessageBox.Show("The file selected is not suitable for replacement. This tool is intended for use to account for derived component update errors upon using copy design and as such, the target file must be geometrically identical to file being replaced.", "Derived Component Replace", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End Try

        oDoc.Update2()
    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will take a little bit of work to adapt to VBA but it's very doable. I just didn't have time to do it beforehand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Nov 2016 20:57:35 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-11-01T20:57:35Z</dc:date>
    <item>
      <title>Inventor VBA - How to change DerivedPart reference</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/inventor-vba-how-to-change-derivedpart-reference/m-p/6602696#M106329</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in A.IPT, how can I change the DerivedPart reference file from es. part.ipt to newpart.ipt?&lt;/P&gt;&lt;P&gt;Via VBA?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, best regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 12:47:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/inventor-vba-how-to-change-derivedpart-reference/m-p/6602696#M106329</guid>
      <dc:creator>it.drr</dc:creator>
      <dc:date>2016-10-05T12:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Inventor VBA - How to change DerivedPart reference</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/inventor-vba-how-to-change-derivedpart-reference/m-p/6660985#M106330</link>
      <description>&lt;P&gt;The following code VB.Net code will allow you to select a new base component for your derived part reference. One thing you need to be aware of is that the method only works if your target part's geometry is a basic geometric match with the original geometry. For instance, it works great with using Copy Design in Vault because Copy Design doesn't copies the base geometry for modification but does not (at least in Vault 2014) edit the derived part reference path.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    Public Sub DeriveComponentReplace()

        If ThisApplication.ActiveEditObject.DocumentType &amp;lt;&amp;gt; DocumentTypeEnum.kPartDocumentObject Then
            Exit Sub
        End If
        Dim oDoc As PartDocument = ThisApplication.ActiveEditDocument
        Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition

        Dim oSubs As Inventor.DerivedAssemblyComponents = oDef.ReferenceComponents.DerivedAssemblyComponents '.Item(1)
        Dim oSubs1 As DerivedPartComponents = oDef.ReferenceComponents.DerivedPartComponents
        If oSubs.Count = 0 Then
            If oSubs1.Count = 0 Then
                MessageBox.Show("No derived assembly components present.", "Derived Assembly Replace", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub
            End If
        End If
        Dim oRefFile As FileDescriptor
        Try
            oRefFile = oSubs.Item(1).ReferencedDocumentDescriptor.ReferencedFileDescriptor
        Catch
            oRefFile = oSubs1.Item(1).ReferencedDocumentDescriptor.ReferencedFileDescriptor
        End Try

        Dim AppPath As String = ShowOpenDialog(oDoc)
        If AppPath = "" Then
            Exit Sub
        End If
        Try
            oRefFile.ReplaceReference(AppPath)
        Catch
            MessageBox.Show("The file selected is not suitable for replacement. This tool is intended for use to account for derived component update errors upon using copy design and as such, the target file must be geometrically identical to file being replaced.", "Derived Component Replace", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End Try

        oDoc.Update2()
    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will take a little bit of work to adapt to VBA but it's very doable. I just didn't have time to do it beforehand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2016 20:57:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/inventor-vba-how-to-change-derivedpart-reference/m-p/6660985#M106330</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-11-01T20:57:35Z</dc:date>
    </item>
  </channel>
</rss>

