<?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: Create ComponentOccurrence Type Class - Assign Object to Base of Class in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/create-componentoccurrence-type-class-assign-object-to-base-of/m-p/13118279#M4739</link>
    <description>&lt;P&gt;Very very nice, Ill have to figure out how to shrink the size a little bit, but other than that, awesome!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does this do the calculation every time you call on that property? That could get... slow.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Oct 2024 15:15:56 GMT</pubDate>
    <dc:creator>C_Haines_ENG</dc:creator>
    <dc:date>2024-10-30T15:15:56Z</dc:date>
    <item>
      <title>Create ComponentOccurrence Type Class - Assign Object to Base of Class</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/create-componentoccurrence-type-class-assign-object-to-base-of/m-p/13118045#M4735</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to assign the initial variable used to create a class as an object? Similar to how you have a&amp;nbsp;&lt;SPAN&gt;ComponentOccurrence object, that has further parameters. It might be easier to explain with code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;Sub&lt;/SPAN&gt; &lt;SPAN&gt;Main&lt;/SPAN&gt;
	
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oAsm&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;AssemblyDocument&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Document&lt;/SPAN&gt;
	&lt;SPAN&gt;Part&lt;/SPAN&gt;.&lt;SPAN&gt;oApp&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;
		
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;Part_1&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;New&lt;/SPAN&gt; &lt;SPAN&gt;Part&lt;/SPAN&gt;
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;Part_2&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;New&lt;/SPAN&gt; &lt;SPAN&gt;Part&lt;/SPAN&gt;
	
	&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;Part_1&lt;/SPAN&gt; &lt;SPAN&gt;Is&lt;/SPAN&gt; &lt;SPAN&gt;Part_2&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt; &lt;SPAN&gt;MsgBox&lt;/SPAN&gt;(&lt;SPAN&gt;"Parts are the same!"&lt;/SPAN&gt;)
	
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;

&lt;SPAN&gt;Class&lt;/SPAN&gt; &lt;SPAN&gt;Part&lt;/SPAN&gt;
	
	&lt;SPAN&gt;Public&lt;/SPAN&gt; &lt;SPAN&gt;Shared&lt;/SPAN&gt; &lt;SPAN&gt;oApp&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Inventor&lt;/SPAN&gt;.&lt;SPAN&gt;Application&lt;/SPAN&gt;
	
	&lt;SPAN&gt;Frame&lt;/SPAN&gt; = &lt;SPAN&gt;oApp&lt;/SPAN&gt;.&lt;SPAN&gt;CommandManager&lt;/SPAN&gt;.&lt;SPAN&gt;Pick&lt;/SPAN&gt;(&lt;SPAN&gt;SelectionFilterEnum&lt;/SPAN&gt;.&lt;SPAN&gt;kAssemblyLeafOccurrenceFilter&lt;/SPAN&gt;, &lt;SPAN&gt;"SELECT PART 1"&lt;/SPAN&gt;)
	
	&lt;SPAN&gt;Public&lt;/SPAN&gt; &lt;SPAN&gt;Property&lt;/SPAN&gt; &lt;SPAN&gt;Name&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt; = &lt;SPAN&gt;Frame&lt;/SPAN&gt;.&lt;SPAN&gt;Name&lt;/SPAN&gt;
	
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Class&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;This doesn't work of course, but It would be nice to have the base item represent an object. I don't think this is possible but It would be very nice.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The same way the base of a&amp;nbsp;ComponentOccurrence is an object, can a class be the same or do I need to set a variable representing the Component.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 13:29:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/create-componentoccurrence-type-class-assign-object-to-base-of/m-p/13118045#M4735</guid>
      <dc:creator>C_Haines_ENG</dc:creator>
      <dc:date>2024-10-30T13:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create ComponentOccurrence Type Class - Assign Object to Base of Class</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/create-componentoccurrence-type-class-assign-object-to-base-of/m-p/13118197#M4736</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12191678"&gt;@C_Haines_ENG&lt;/a&gt;.&amp;nbsp; What you posted is a little confusing.&amp;nbsp; What is your end goal of trying to create something like that?&amp;nbsp; In iLogic rules, the &lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-ComponentOccurrence" target="_blank" rel="noopener"&gt;ComponentOccurrence&lt;/A&gt;&amp;nbsp;object is an &lt;A href="https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/interfaces/" target="_blank" rel="noopener"&gt;Interface&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WCrihfield_0-1730298585824.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1427656i4EA0D6A35858F02C/image-size/large?v=v2&amp;amp;px=999" role="button" title="WCrihfield_0-1730298585824.png" alt="WCrihfield_0-1730298585824.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;You can not use the 'New' keyword to create a new instance of an Interface, like you can a Class.&amp;nbsp; But a Class can 'Implement' an Interface, to use it.&amp;nbsp; However, if you just want to be able to add functionality to an 'instance' of a ComponentOccurrence, such as one that a variable in your code represents (after it has been assigned a value), then you may be able to use a &lt;A href="https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/modules" target="_blank" rel="noopener"&gt;Module&lt;/A&gt;.&amp;nbsp; A &lt;A href="https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/module-statement" target="_blank" rel="noopener"&gt;Module&lt;/A&gt; can be used to define 'extensions' to instances of existing Types.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 14:36:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/create-componentoccurrence-type-class-assign-object-to-base-of/m-p/13118197#M4736</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2024-10-30T14:36:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create ComponentOccurrence Type Class - Assign Object to Base of Class</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/create-componentoccurrence-type-class-assign-object-to-base-of/m-p/13118216#M4737</link>
      <description>&lt;P&gt;The goal is to add properties to a ComponentOccurance,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't see how this is possible with a module, could you put a simple example?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 14:44:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/create-componentoccurrence-type-class-assign-object-to-base-of/m-p/13118216#M4737</guid>
      <dc:creator>C_Haines_ENG</dc:creator>
      <dc:date>2024-10-30T14:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create ComponentOccurrence Type Class - Assign Object to Base of Class</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/create-componentoccurrence-type-class-assign-object-to-base-of/m-p/13118260#M4738</link>
      <description>&lt;P&gt;Here is an example of a Module being used within an iLogic rule, to add what acts like a Property to the ComponentOccurrence type object, as an 'extension' of that instance.&amp;nbsp; This adds a 'member' named 'IsVirtual', which provides a Boolean Type value.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Class ThisRule
	Sub Main
		Dim oPickedOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a Component.")
		If oPickedOcc Is Nothing Then Return
		If oPickedOcc.IsVirtual() Then
			MsgBox("IsVirtual = True",,"")
		Else
			MsgBox("IsVirtual = False",,"")
		End If
	End Sub
End Class

Friend Module ComponentOccurrenceModule
	
	&amp;lt;System.Runtime.CompilerServices.Extension&amp;gt;
	Public Function IsVirtual(oOcc As Inventor.ComponentOccurrence) As Boolean
		If Not oOcc.Suppressed Then
			If TypeOf oOcc.Definition Is VirtualComponentDefinition Then
				Return True
			End If
		End If
		Return False
	End Function
End Module&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 15:05:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/create-componentoccurrence-type-class-assign-object-to-base-of/m-p/13118260#M4738</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2024-10-30T15:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create ComponentOccurrence Type Class - Assign Object to Base of Class</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/create-componentoccurrence-type-class-assign-object-to-base-of/m-p/13118279#M4739</link>
      <description>&lt;P&gt;Very very nice, Ill have to figure out how to shrink the size a little bit, but other than that, awesome!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does this do the calculation every time you call on that property? That could get... slow.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 15:15:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/create-componentoccurrence-type-class-assign-object-to-base-of/m-p/13118279#M4739</guid>
      <dc:creator>C_Haines_ENG</dc:creator>
      <dc:date>2024-10-30T15:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create ComponentOccurrence Type Class - Assign Object to Base of Class</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/create-componentoccurrence-type-class-assign-object-to-base-of/m-p/13118315#M4740</link>
      <description>&lt;P&gt;Not sure what 'calculation' you mean, but yes, it does the 'checks' / 'processing' each time it is called.&amp;nbsp; If we try to access the ComponentOccurrence.Definition property of one that is currently Suppressed, it will throw an error.&amp;nbsp; And the only way that comes to mind for me to check if a component is 'virtual' or not, is by checking the Type of its ComponentDefinition, using that property, therefore it must always do 2 checks, to avoid the potential error.&amp;nbsp; You could also use a Try...Catch...End Try statement, without that first check, but that may require even more processing, due to 'handling' an Exception.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, we can only add 'extension methods' (Subs or Functions), and not 'extension properties'.&amp;nbsp; If you needed actual properties, then you would have to create a derived Class, which Implements the&amp;nbsp;ComponentOccurrence Interface.&amp;nbsp; But if you do that, then it requires you to also Implement each of the 'parent' Interface's Properties, Methods, and Events, which would require a TON of code...that we do not have access to the 'source' code for, to properly duplicate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&amp;nbsp; Also, if you are worried about 'space' (you mentioned wanting to 'shrink it'), then you could put the extensions Module code out in its own separate external iLogic rule file, and set its 'Straight VB Code' option on.&amp;nbsp; Then, to use that Module's resources from another 'regular' rule, you would have to add the 'AddVbFile' line of code within the 'Header' of your other rule (the rule wanting to use it), followed by the file name (including file extension) of that external iLogic rule file.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 15:32:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/create-componentoccurrence-type-class-assign-object-to-base-of/m-p/13118315#M4740</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2024-10-30T15:32:03Z</dc:date>
    </item>
  </channel>
</rss>

