<?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 Creating Virtual Component in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11754672#M26979</link>
    <description>&lt;P&gt;The code below is used to add Virtual Components.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AddByComponentDefinition as used in the code sample below, generates an error after upgrading to Inventor 2023.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What would be the proper way to add multiple VC's in the new version of Inventor?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;'create first instance of the virtual part&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;virtOcc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ComponentOccurrence&lt;/SPAN&gt;
&lt;SPAN&gt;virtOcc&lt;/SPAN&gt; = &lt;SPAN&gt;oOccs&lt;/SPAN&gt;.&lt;SPAN&gt;AddVirtual&lt;/SPAN&gt;(&lt;SPAN&gt;sVirtPart&lt;/SPAN&gt;, &lt;SPAN&gt;identity&lt;/SPAN&gt;)

&lt;SPAN&gt;'add next instance starting at instance2 (if applicable)&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;index&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Integer&lt;/SPAN&gt; 
&lt;SPAN&gt;index&lt;/SPAN&gt; = 2
&lt;SPAN&gt;Do&lt;/SPAN&gt; &lt;SPAN&gt;While&lt;/SPAN&gt; &lt;SPAN&gt;index&lt;/SPAN&gt; &amp;lt;= &lt;SPAN&gt;iQTY&lt;/SPAN&gt;
&lt;SPAN&gt;oOccs&lt;/SPAN&gt;.&lt;FONT color="#FF6600"&gt;&lt;SPAN&gt;AddByComponentDefinition&lt;/SPAN&gt;&lt;/FONT&gt;(&lt;SPAN&gt;virtOcc&lt;/SPAN&gt;.&lt;SPAN&gt;Definition&lt;/SPAN&gt;, &lt;SPAN&gt;identity&lt;/SPAN&gt;) 
&lt;SPAN&gt;index&lt;/SPAN&gt; += 1
&lt;SPAN&gt;Loop&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Feb 2023 19:31:12 GMT</pubDate>
    <dc:creator>kmorehouseUCMBR</dc:creator>
    <dc:date>2023-02-14T19:31:12Z</dc:date>
    <item>
      <title>Creating Virtual Component</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11754672#M26979</link>
      <description>&lt;P&gt;The code below is used to add Virtual Components.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AddByComponentDefinition as used in the code sample below, generates an error after upgrading to Inventor 2023.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What would be the proper way to add multiple VC's in the new version of Inventor?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;'create first instance of the virtual part&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;virtOcc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ComponentOccurrence&lt;/SPAN&gt;
&lt;SPAN&gt;virtOcc&lt;/SPAN&gt; = &lt;SPAN&gt;oOccs&lt;/SPAN&gt;.&lt;SPAN&gt;AddVirtual&lt;/SPAN&gt;(&lt;SPAN&gt;sVirtPart&lt;/SPAN&gt;, &lt;SPAN&gt;identity&lt;/SPAN&gt;)

&lt;SPAN&gt;'add next instance starting at instance2 (if applicable)&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;index&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Integer&lt;/SPAN&gt; 
&lt;SPAN&gt;index&lt;/SPAN&gt; = 2
&lt;SPAN&gt;Do&lt;/SPAN&gt; &lt;SPAN&gt;While&lt;/SPAN&gt; &lt;SPAN&gt;index&lt;/SPAN&gt; &amp;lt;= &lt;SPAN&gt;iQTY&lt;/SPAN&gt;
&lt;SPAN&gt;oOccs&lt;/SPAN&gt;.&lt;FONT color="#FF6600"&gt;&lt;SPAN&gt;AddByComponentDefinition&lt;/SPAN&gt;&lt;/FONT&gt;(&lt;SPAN&gt;virtOcc&lt;/SPAN&gt;.&lt;SPAN&gt;Definition&lt;/SPAN&gt;, &lt;SPAN&gt;identity&lt;/SPAN&gt;) 
&lt;SPAN&gt;index&lt;/SPAN&gt; += 1
&lt;SPAN&gt;Loop&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 19:31:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11754672#M26979</guid>
      <dc:creator>kmorehouseUCMBR</dc:creator>
      <dc:date>2023-02-14T19:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Virtual Component</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11754737#M26980</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12924411"&gt;@kmorehouseUCMBR&lt;/a&gt;.&amp;nbsp; Are you using iLogic shortcut snippets to create/add your 'virtual' components, or Inventor API code to do it?&amp;nbsp; If using API code, then this following method seems like the right one to use:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oADef.Occurrences
Dim oMatrix As Matrix = ThisApplication.TransientGeometry.CreateMatrix
Dim oVirtOcc As ComponentOccurrence = oOccs.AddVirtual("VirtualOccName", oMatrix)&lt;/LI-CODE&gt;
&lt;P&gt;If this solved your problem, or answered your question, please click &lt;SPAN&gt;&lt;STRONG&gt; ACCEPT SOLUTION &lt;/STRONG&gt;&lt;/SPAN&gt;.&lt;BR /&gt;Or, if this helped you, please click (LIKE or KUDOS) &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 20:00:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11754737#M26980</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2023-02-14T20:00:59Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Virtual Component</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11754761#M26981</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12924411"&gt;@kmorehouseUCMBR&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These related links might be of interests as well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://inventortrenches.blogspot.com/2013/07/ilogic-add-standard-virtual-parts-from_29.html" target="_blank"&gt;http://inventortrenches.blogspot.com/2013/07/ilogic-add-standard-virtual-parts-from_29.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://inventortrenches.blogspot.com/2013/07/ilogic-add-standard-virtual-parts-from.html" target="_blank"&gt;http://inventortrenches.blogspot.com/2013/07/ilogic-add-standard-virtual-parts-from.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;BR /&gt;Best of luck to you in all of your Inventor pursuits,&lt;BR /&gt;Curtis&lt;BR /&gt;&lt;A href="http://inventortrenches.blogspot.com" target="_blank"&gt;http://inventortrenches.blogspot.com&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 20:14:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11754761#M26981</guid>
      <dc:creator>Curtis_W</dc:creator>
      <dc:date>2023-02-14T20:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Virtual Component</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11754929#M26982</link>
      <description>&lt;P&gt;Both iLogic and Inventor API with the same result. Both worked fine before the upgrade to 2023.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 21:31:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11754929#M26982</guid>
      <dc:creator>kmorehouseUCMBR</dc:creator>
      <dc:date>2023-02-14T21:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Virtual Component</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11754989#M26983</link>
      <description>&lt;P&gt;You are not allowed to use the same occurrence name 2 times. To solve this Inventor adds a ":" and a number to names. Some strange things seem to happen when you add/create an occurrence. But I found a workaround. have a look at this script.&lt;/P&gt;
&lt;LI-CODE lang="visual-basic"&gt;Sub Main()

    Dim iQTY = 4
    Dim sVirtPart = "My VC name"

    Dim doc As AssemblyDocument = ThisDoc.Document

    AddVirtualComponent(doc, sVirtPart)

    For i = 2 To iQTY
        AddVirtualComponent(doc, sVirtPart)
    Next

End Sub

Public Sub AddVirtualComponent(doc As AssemblyDocument, name As String)

    Dim occs = doc.ComponentDefinition.Occurrences
    Dim matrix = ThisApplication.TransientGeometry.CreateMatrix()

    If (name.Contains(":")) Then
        name = name.Split(":")(0)
    End If

    Try
        Dim orgName = name
        If (Not orgName.Contains(":")) Then
            orgName = orgName &amp;amp; ":1"
        End If

        Dim oldOcc = occs.ItemByName(orgName)
        occs.AddByComponentDefinition(oldOcc.Definition, matrix)
    Catch ex As Exception
        occs.AddVirtual(name, matrix)
    End Try
End Sub&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 22:06:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11754989#M26983</guid>
      <dc:creator>JelteDeJong</dc:creator>
      <dc:date>2023-02-14T22:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Virtual Component</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11757472#M26984</link>
      <description>&lt;P&gt;I feel like everyone's misunderstanding the question.&amp;nbsp; It's a question of adding additional occurrences of a unique virtual component.&amp;nbsp; The following VBA code runs in 2019.&amp;nbsp; Could someone with 2023 run this in a empty assembly and confirm that AddByComponentDefinition fails?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Public Sub AddVirtuals()

Dim app As Application

Set app = ThisApplication
If app.ActiveDocumentType &amp;lt;&amp;gt; kNoDocument Then
    If app.ActiveDocumentType = kAssemblyDocumentObject Then
        Dim asmDoc As AssemblyDocument
        Set asmDoc = app.ActiveDocument
        Dim virtOcc As ComponentOccurrence
        Dim pos As Matrix
        Set pos = app.TransientGeometry.CreateMatrix
        Set virtOcc = asmDoc.ComponentDefinition.Occurrences.AddVirtual("VirtualComponent", pos)
        asmDoc.ComponentDefinition.Occurrences.AddByComponentDefinition virtOcc.Definition, pos
    End If
End If

End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 19:01:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11757472#M26984</guid>
      <dc:creator>jjstr8</dc:creator>
      <dc:date>2023-02-15T19:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Virtual Component</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11757693#M26985</link>
      <description>&lt;P&gt;I've determined that the original code works as expected when applied to a new Inventor assembly, but not an existing assembly that has been migrated to 2023. I tried removing everything from the existing&amp;nbsp;assembly and setting the Model State and Representation to match the new assembly and it still doesn't work. Continuing to test...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 20:32:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11757693#M26985</guid>
      <dc:creator>kmorehouseUCMBR</dc:creator>
      <dc:date>2023-02-15T20:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Virtual Component</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11759893#M26986</link>
      <description>&lt;P&gt;After extensive testing, I've determined that the original vb.net code works as&amp;nbsp;intended until any model state has been added. Once another Model State exists the &lt;FONT color="#FF6600"&gt;AddByComponentDefinition&lt;/FONT&gt; will no longer functions. This was never an issue in Inventor 2021 prior to Model States.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See the pictures.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 15:42:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11759893#M26986</guid>
      <dc:creator>kmorehouseUCMBR</dc:creator>
      <dc:date>2023-02-16T15:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Virtual Component</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11759931#M26987</link>
      <description>&lt;P&gt;Very interesting situation there.&amp;nbsp; Any time any new parameter or iProperty is created within a model document that has any custom model states, it effects all model states equally, because that new parameter or iProperty will exist for all of them, and will all have the same initial value.&amp;nbsp; I was assuming that adding virtual components would be a similar situation, but maybe not yet.&amp;nbsp; I wander if you set the member edit scope to all members before doing this, if that would make this process work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&amp;nbsp; I just did some testing in iLogic (2022.4) and found same situation, and member edit scope did not seem to effect the outcome.&amp;nbsp; However, as a work-around, I simply used a 'Copy &amp;amp; Paste' routine to accomplish 'virtually' the same thing.&lt;span class="lia-unicode-emoji" title=":face_savoring_food:"&gt;😋&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 16:00:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11759931#M26987</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2023-02-16T16:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Virtual Component</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11760083#M26988</link>
      <description>&lt;P&gt;Good old, Copy and Paste. Thank you! that was brilliant.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 16:34:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11760083#M26988</guid>
      <dc:creator>kmorehouseUCMBR</dc:creator>
      <dc:date>2023-02-16T16:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Virtual Component</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11760201#M26989</link>
      <description>&lt;P&gt;One problem with the copy &amp;amp; paste routine is you are not left with a reference to the virtual component you just created.&amp;nbsp; So, if you want to use a naming scheme/routine, or adjust properties for each one, you might seem out of luck.&amp;nbsp; However, I believe you should be able to use something like:&lt;/P&gt;
&lt;P&gt;oNewVOcc = oOccs.Item(oOccs.Count)&lt;/P&gt;
&lt;P&gt;just after each copy paste, to get a reference to the last component it just created, so you could still do your naming or property changes.&amp;nbsp; It's sort of a last resort way of doing it, but if it works and saves you time, why not.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 17:22:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/11760201#M26989</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2023-02-16T17:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Virtual Component</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/12357244#M26990</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7812054"&gt;@WCrihfield&lt;/a&gt;&amp;nbsp; thank you for posting the copy/paste workflow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Resolved our issue with 2024 and placing multiple copies of the same part.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now if we can just get VS 2019 to allow us to make a new Windows Form Dialog project we'll be golden!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;M.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2023 15:24:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-virtual-component/m-p/12357244#M26990</guid>
      <dc:creator>MICHAEL.JONES.AMCE</dc:creator>
      <dc:date>2023-11-06T15:24:02Z</dc:date>
    </item>
  </channel>
</rss>

