<?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: Add Multiple Virtual Components in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3949827#M130400</link>
    <description>Can you create a pattern of them? That's how I would do it with the UI...</description>
    <pubDate>Fri, 07 Jun 2013 15:21:33 GMT</pubDate>
    <dc:creator>mrattray</dc:creator>
    <dc:date>2013-06-07T15:21:33Z</dc:date>
    <item>
      <title>Add Multiple Virtual Components</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3949646#M130398</link>
      <description>&lt;P&gt;I have a VBA macro that places selected virtual components into an assembly.&amp;nbsp; I can place virtual components with different part numbers into the assembly with no problem.&amp;nbsp; When I try to place the second instance of a virtual component with the same part number I get an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example: If I place a virtual component with the part number C123A456 into an assembly it shows in the tree as C123A456:1 If I try to place C123A456 again it errors at this line.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'Add selected line as a virtual part&lt;/P&gt;&lt;P&gt;Set oOcc = oOccs.AddVirtual(sPartNumber, oMatrix)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can place multiple virtual parts if I append -1, -2, -3 etc to the part number but I would like to let Inventor use the :1, :2, :3 to keep track.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How is this handled?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2013 13:18:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3949646#M130398</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-06-07T13:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: Add Multiple Virtual Components</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3949718#M130399</link>
      <description>&lt;P&gt;Just tried it myself and indeed it seems you cannot add 2 virtual components with the same name. I'm not sure, but I guess this just isn't possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully someone can prove me wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniël&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2013 14:05:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3949718#M130399</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-06-07T14:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: Add Multiple Virtual Components</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3949827#M130400</link>
      <description>Can you create a pattern of them? That's how I would do it with the UI...</description>
      <pubDate>Fri, 07 Jun 2013 15:21:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3949827#M130400</guid>
      <dc:creator>mrattray</dc:creator>
      <dc:date>2013-06-07T15:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Add Multiple Virtual Components</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3949856#M130401</link>
      <description>&lt;P&gt;I am not sure what you mean by creating a pattern since a virtual part only exists in the tree.&amp;nbsp; Can you provide an example of how you would do this?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2013 15:38:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3949856#M130401</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-06-07T15:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Add Multiple Virtual Components</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3949935#M130402</link>
      <description>&lt;P&gt;I use this all the time for misc. purchased parts that I can't or don't want to draw.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" src="https://forums.autodesk.com/t5/image/serverpage/image-id/53919iFE4A25A088D19712/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" align="middle" title="Capture.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture2.JPG" src="https://forums.autodesk.com/t5/image/serverpage/image-id/53920i29B3F3EFDA65EEC8/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" align="middle" title="Capture2.JPG" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2013 16:32:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3949935#M130402</guid>
      <dc:creator>mrattray</dc:creator>
      <dc:date>2013-06-07T16:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: Add Multiple Virtual Components</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3949979#M130403</link>
      <description>&lt;P&gt;You can accomplish what I am trying to do with the following manual workflow.&amp;nbsp; Have not found way to do it in code yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="1.png" src="https://forums.autodesk.com/t5/image/serverpage/image-id/53923iF33E48935BDA066C/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" align="center" title="1.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2013 17:15:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3949979#M130403</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-06-07T17:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Add Multiple Virtual Components</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3950123#M130404</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/882102"&gt;@mrattray&lt;/a&gt; wrote:&lt;BR /&gt;Can you create a pattern of them? That's how I would do it with the UI...&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Great idea! Decided to write a VBA macro to do just that &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Sub CreateVirtPattern()
' JDK 2013 - Create virtual component then pattern it
    Dim oAssDoc As AssemblyDocument
    Set oAssDoc = ThisApplication.ActiveDocument
    Dim oAssDef As AssemblyComponentDefinition
    Set oAssDef = oAssDoc.ComponentDefinition
    Dim oMatrix As Matrix
    Set oMatrix = ThisApplication.TransientGeometry.CreateMatrix
    
    ' Create virtual component
    Dim sName As String
    sName = "VirtualComp"
    Set oNewOcc = oAssDef.Occurrences.AddVirtual(sName, oMatrix)

    Dim oOccurrence As ComponentOccurrence
    For Each oOccurrence In oAssDef.Occurrences
    
        ' Look for virtual components
        If TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then&lt;BR /&gt;
            ' Look for name match
            sNameS = Split(oOccurrence.name, ":")
            If sName &amp;amp; ":" &amp;amp; sNameS(1) = oOccurrence.name Then
                Dim XAxis As WorkAxis
                Set XAxis = oAssDef.WorkAxes(1)
 
                ' Create object collection
                Dim objCol As ObjectCollection
                Set objCol = ThisApplication _
                .TransientObjects.CreateObjectCollection
 
                ' Add virtual comp to object collection
                objCol.Add oAssDef.Occurrences.Item(1)
                
                ' How many components in pattern
                Dim iNum As Integer
                iNum = 3
                
                ' Create pattern
                Call oAssDef.OccurrencePatterns _
                .AddRectangularPattern(objCol, _
                XAxis, True, 10, iNum)
            End If
        End If
    Next
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the iLogic version as well...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;' JDK 2013 - Create virtual component then pattern it
Dim oAssDoc As AssemblyDocument = ThisDoc.Document
Dim oAssDef As AssemblyComponentDefinition = oAssDoc.ComponentDefinition
Dim oMatrix As Matrix: oMatrix = ThisApplication.TransientGeometry.CreateMatrix
    
' Create virtual component
sName = "VirtualComp"
oNewOcc = oAssDef.Occurrences.AddVirtual(sName, oMatrix)

Dim oOccurrence As ComponentOccurrence
    For Each oOccurrence In oAssDef.Occurrences
	
        ' Look for virtual components
        If TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
		
            ' Look for name match
            sNameS = Split(oOccurrence.Name, ":")
            If sName &amp;amp; ":" &amp;amp; sNameS(1) = oOccurrence.Name Then
                Dim XAxis As WorkAxis: XAxis = oAssDef.WorkAxes(1)
				
                ' Create object collection
                Dim objCol As ObjectCollection
                objCol = ThisApplication _
                .TransientObjects.CreateObjectCollection
				
                ' Add virtual comp to object collection
                objCol.Add(oAssDef.Occurrences.Item(1))
                
                ' How many components in pattern
                Dim iNum As Integer
                iNum = 3
                
                ' Create pattern
                Call oAssDef.OccurrencePatterns _
                .AddRectangularPattern(objCol, _
                XAxis, True, 10, iNum)
            End If
        End If
    Next&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jun 2013 20:15:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/3950123#M130404</guid>
      <dc:creator>jdkriek</dc:creator>
      <dc:date>2013-06-07T20:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Add Multiple Virtual Components</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/4293153#M130405</link>
      <description>&lt;P&gt;Give this a try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Public Sub AddVirtual()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim asmDoc As AssemblyDocument&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set asmDoc = ThisApplication.ActiveDocument&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim occs As ComponentOccurrences&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set occs = asmDoc.ComponentDefinition.Occurrences&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim identity As Matrix&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set identity = ThisApplication.TransientGeometry.CreateMatrix&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim virtOcc As ComponentOccurrence&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set virtOcc = occs.AddVirtual("TestVirtual", identity)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Call occs.AddByComponentDefinition(virtOcc.Definition, identity)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Call occs.AddByComponentDefinition(virtOcc.Definition, identity)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Call occs.AddByComponentDefinition(virtOcc.Definition, identity)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Call occs.AddByComponentDefinition(virtOcc.Definition, identity)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Call occs.AddByComponentDefinition(virtOcc.Definition, identity)&lt;BR /&gt;End Sub&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jun 2013 00:13:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/4293153#M130405</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2013-06-09T00:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: Add Multiple Virtual Components</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/4293670#M130406</link>
      <description>&lt;P&gt;Thanks Brian.&amp;nbsp; That is what I was looking for.&amp;nbsp; Didn't think to use the AddByComponentDefinition for virtual part additions after the first.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I used if it helps anyone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;'Function to add virtual parts to the assembly
Public Sub AddVirtualPart_Click()

'Variable declarations
Dim oAssemblyDoc As AssemblyDocument
Dim oAssemblyCompDef As AssemblyComponentDefinition
Dim oVirtualCompDef As VirtualComponentDefinition
Dim oTransientGeometry As TransientGeometry
Dim oMatrix As Matrix
Dim oOccs As ComponentOccurrences
Dim oOcc As ComponentOccurrence
Dim sLine As String
Dim sPartNumber As String
Dim sDescription As String
Dim iListIndex As Integer
Dim i As Integer


'Set the list index
iListIndex = Me.ItemToAddListBox.ListIndex

'Check if something was selected
If iListIndex = -1 Then
    MsgBox "Please select a part to add!"
Else
    'Set the assembly document
    Set oAssemblyDoc = ThisApplication.ActiveDocument

    'Set the assembly component definition
    Set oAssemblyCompDef = oAssemblyDoc.ComponentDefinition

    'Set the transient geometry
    Set oTransientGeometry = ThisApplication.TransientGeometry

    'Set the matrix
    Set oMatrix = oTransientGeometry.CreateMatrix

    'Set selected line
    sLine = Me.ItemToAddListBox.Text

    'Set the part number
    sPartNumber = Left(sLine, 20)
    
    'Remove spaces from the part number
    sPartNumber = RemoveSpaces(sPartNumber)
    
    'Set the occurrences collection
    Set oOccs = oAssemblyCompDef.Occurrences
    
    'Initialize
    i = 1

    'Check for other occurrences
    For Each oOcc In oOccs
        If Not InStr(oOcc.Name, sPartNumber) = 0 Then
            i = i + 1
        Else
        End If
    Next

    'Check if this is the first occurrence
    If i = 1 Then
        'Add the virtual part
        Set oOcc = oOccs.AddVirtual(sPartNumber, oMatrix)
        
        'Set the virtual part component definition
        Set oVirtualCompDef = oOcc.Definition
    Else
        'Set the virtual part component definition from one of the occurrences
        For Each oOcc In oOccs
            If Not InStr(oOcc.Name, sPartNumber) = 0 Then
                Set oVirtualCompDef = oOcc.Definition
                Exit For
            Else
            End If
        Next
        
        'Add the virtual part
        Call oOccs.AddByComponentDefinition(oVirtualCompDef, oMatrix)
    End If
    
    'Set the description
    sDescription = Mid(sLine, 21, Len(sLine) - 21)
    
    'Remove spaces
    sDescription = RemoveSpaces(sDescription)
    
    'Set the description
    oVirtualCompDef.PropertySets.Item("Design Tracking Properties").Item("Description").Value = sDescription
    
    'Set the part number
    oVirtualCompDef.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = sPartNumber

End If


'Unload objects
Set oAssemblyDoc = Nothing
Set oAssemblyCompDef = Nothing
Set oTransientGeometry = Nothing
Set oMatrix = Nothing
Set oOcc = Nothing

End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2013 11:35:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/4293670#M130406</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-06-10T11:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Add Multiple Virtual Components</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/4296659#M130407</link>
      <description>&lt;P&gt;Thanks Brian, didn't think about that either.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2013 17:26:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/4296659#M130407</guid>
      <dc:creator>jdkriek</dc:creator>
      <dc:date>2013-06-12T17:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Add Multiple Virtual Components</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/5620207#M130408</link>
      <description>&lt;P&gt;to add inside the model within the browser tree you add the name:1, name:2 and so on,&amp;nbsp; I would think you would do the same if adding via VBA.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 May 2015 17:30:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/add-multiple-virtual-components/m-p/5620207#M130408</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-05-04T17:30:10Z</dc:date>
    </item>
  </channel>
</rss>

