<?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: change sected parts colour in an assembley in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7855345#M81979</link>
    <description>&lt;P&gt;thank you for your help, in this it works when I put&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;oOcc.Appearance = oAsset &lt;/PRE&gt;&lt;P&gt;inside the if statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;</description>
    <pubDate>Thu, 15 Mar 2018 09:25:19 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-03-15T09:25:19Z</dc:date>
    <item>
      <title>change sected parts colour in an assembley</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7846013#M81802</link>
      <description>&lt;P&gt;hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to put a bit of code together to over ride the appearance colour of parts in an assembly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;we are using cable tray and we change the colour of the tray in one view rep to show if it is for power or signal, we also want everyone who works on the project to do it the same way (this is where iLogic come in)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to put together a button (for example 24v needing to be red) so you select the parts ( that could be in the top level or in sub-assemblies) and then click the button and the rule changes the appearance colour to red.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have looked all over and seam to find different codes but none does or can be easily changed to do what I need&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any help would be great.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 13:48:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7846013#M81802</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-12T13:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: change sected parts colour in an assembley</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7846505#M81807</link>
      <description>&lt;P&gt;1. Post your sample code.&lt;/P&gt;
&lt;P&gt;2. Post links of things that might be similar to what you want if you don't know how to code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;'define the assembly&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oAssyDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;AssemblyDocument&lt;/SPAN&gt;
&lt;SPAN&gt;oAssyDoc&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;ActiveDocument&lt;/SPAN&gt;

&lt;SPAN&gt;'define the appearance library&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oLib&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;AssetLibrary&lt;/SPAN&gt;
&lt;SPAN&gt;oLib&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;AssetLibraries&lt;/SPAN&gt;(&lt;SPAN&gt;"Autodesk Appearance Library"&lt;/SPAN&gt;)

&lt;SPAN&gt;'make sure colors are in assembly doc&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;libAsset&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Asset&lt;/SPAN&gt;
&lt;SPAN&gt;libAsset&lt;/SPAN&gt; = &lt;SPAN&gt;oLib&lt;/SPAN&gt;.&lt;SPAN&gt;AppearanceAssets&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"Smooth - Red"&lt;/SPAN&gt;)
&lt;SPAN&gt;Try&lt;/SPAN&gt; 
	&lt;SPAN&gt;localAsset&lt;/SPAN&gt; = &lt;SPAN&gt;libAsset&lt;/SPAN&gt;.&lt;SPAN&gt;CopyTo&lt;/SPAN&gt;(&lt;SPAN&gt;oAssyDoc&lt;/SPAN&gt;)
&lt;SPAN&gt;Catch&lt;/SPAN&gt;
&lt;SPAN&gt;'catch error if it's already local&lt;/SPAN&gt;
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Try&lt;/SPAN&gt;

&lt;SPAN&gt;libAsset&lt;/SPAN&gt; = &lt;SPAN&gt;oLib&lt;/SPAN&gt;.&lt;SPAN&gt;AppearanceAssets&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"Smooth - Black"&lt;/SPAN&gt;)
&lt;SPAN&gt;Try&lt;/SPAN&gt; 
	&lt;SPAN&gt;localAsset&lt;/SPAN&gt; = &lt;SPAN&gt;libAsset&lt;/SPAN&gt;.&lt;SPAN&gt;CopyTo&lt;/SPAN&gt;(&lt;SPAN&gt;oAssyDoc&lt;/SPAN&gt;)
&lt;SPAN&gt;Catch&lt;/SPAN&gt;

&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Try&lt;/SPAN&gt;

&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oAsmCompDef&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;AssemblyComponentDefinition&lt;/SPAN&gt;
&lt;SPAN&gt;oAsmCompDef&lt;/SPAN&gt; = &lt;SPAN&gt;oAssyDoc&lt;/SPAN&gt;.&lt;SPAN&gt;ComponentDefinition&lt;/SPAN&gt;
 
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oOcc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ComponentOccurrence&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oAsset&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Asset&lt;/SPAN&gt;

&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oSS&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;SelectSet&lt;/SPAN&gt;
&lt;SPAN&gt;oSS&lt;/SPAN&gt; = &lt;SPAN&gt;oAssyDoc&lt;/SPAN&gt;.&lt;SPAN&gt;SelectSet&lt;/SPAN&gt;

&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oSelCollection&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;New&lt;/SPAN&gt; &lt;SPAN&gt;Collection&lt;/SPAN&gt;
&lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;Each&lt;/SPAN&gt; &lt;SPAN&gt;oItem&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;oSS&lt;/SPAN&gt;
	&lt;SPAN&gt;oSelCollection&lt;/SPAN&gt;.&lt;SPAN&gt;Add&lt;/SPAN&gt;(&lt;SPAN&gt;oItem&lt;/SPAN&gt;)
&lt;SPAN&gt;Next&lt;/SPAN&gt;

&lt;SPAN&gt;'set color overrides of components at the assembly level&lt;/SPAN&gt;
&lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;Each&lt;/SPAN&gt; &lt;SPAN&gt;oOcc&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;oAsmCompDef&lt;/SPAN&gt;.&lt;SPAN&gt;Occurrences&lt;/SPAN&gt;.&lt;SPAN&gt;AllLeafOccurrences&lt;/SPAN&gt;
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;MatchFound&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Boolean&lt;/SPAN&gt; = &lt;SPAN&gt;False&lt;/SPAN&gt;
	
	&lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;Each&lt;/SPAN&gt; &lt;SPAN&gt;oItem&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;oSelCollection&lt;/SPAN&gt;
		&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oOcc&lt;/SPAN&gt;.&lt;SPAN&gt;Equals&lt;/SPAN&gt;(&lt;SPAN&gt;oItem&lt;/SPAN&gt;) &lt;SPAN&gt;Then&lt;/SPAN&gt;
			&lt;SPAN&gt;MatchFound&lt;/SPAN&gt; = &lt;SPAN&gt;True&lt;/SPAN&gt;
		&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
	&lt;SPAN&gt;Next&lt;/SPAN&gt;
	
	&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;MatchFound&lt;/SPAN&gt; = &lt;SPAN&gt;True&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
		&lt;SPAN&gt;oAsset&lt;/SPAN&gt; = &lt;SPAN&gt;oAssyDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Assets&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"Smooth - Red"&lt;/SPAN&gt;)
	&lt;SPAN&gt;Else&lt;/SPAN&gt;
		&lt;SPAN&gt;oAsset&lt;/SPAN&gt; = &lt;SPAN&gt;oAssyDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Assets&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"Smooth - Black"&lt;/SPAN&gt;)
	&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
	&lt;SPAN&gt;oOcc&lt;/SPAN&gt;.&lt;SPAN&gt;Appearance&lt;/SPAN&gt; = &lt;SPAN&gt;oAsset&lt;/SPAN&gt;
&lt;SPAN&gt;Next&lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Edited by&lt;BR /&gt;Discussion_Admin&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 17:40:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7846505#M81807</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2018-03-12T17:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: change sected parts colour in an assembley</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7850258#M81886</link>
      <description>&lt;P&gt;thank you,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;first off sorry I didn't attach the code I already have&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what you have done is grate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am still learning how to code,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if you would be able to alter it to only change the selected part? and explain it to help me understand it better? ( at the moment it changes the selected parts red and the not selected parts back)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have had a go changing it myself and have had mixed results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 17:24:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7850258#M81886</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-13T17:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: change sected parts colour in an assembley</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7850279#M81887</link>
      <description>&lt;P&gt;You are likely better off buying and reading a book on programming in vb.net or object oriented programming.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are many blogs/guides/documents online as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remove these 2 lines from the code to avoid setting everything else to black... As the "If/Else" construct implies....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;	Else
		oAsset = oAssyDoc.Assets.Item("Smooth - Black")&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 17:33:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7850279#M81887</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2018-03-13T17:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: change sected parts colour in an assembley</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7853567#M81949</link>
      <description>&lt;P&gt;I thought that would do it as well but I get this error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error in rule: change, in document: Assembly1&lt;/P&gt;&lt;P&gt;The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have put a message box to check/ debug that it is not the rest of the code. all that works fine up until the message box ( I have commented it out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;'define the assembly
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument

'define the appearance library
Dim oLib As AssetLibrary
oLib = ThisApplication.AssetLibraries("Autodesk Appearance Library")

'make sure colors are in assembly doc
Dim libAsset As Asset
libAsset = oLib.AppearanceAssets.Item("Smooth - Red")
Try 
	localAsset = libAsset.CopyTo(oAssyDoc)
Catch
'catch error if it's already local
End Try

libAsset = oLib.AppearanceAssets.Item("Smooth - Black")
Try 
	localAsset = libAsset.CopyTo(oAssyDoc)
Catch

End Try

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAssyDoc.ComponentDefinition
 
Dim oOcc As ComponentOccurrence
Dim oAsset As Asset

Dim oSS As SelectSet
oSS = oAssyDoc.SelectSet

Dim oSelCollection As New Collection
For Each oItem In oSS
	oSelCollection.Add(oItem)
Next

'set color overrides of components at the assembly level
For Each oOcc In oAsmCompDef.Occurrences.AllLeafOccurrences
	Dim MatchFound As Boolean = False
	
	For Each oItem In oSelCollection
		If oOcc.Equals(oItem) Then
			MatchFound = True
		End If
	Next
	' this works fine till this point' MessageBox.Show("Message", "Title")

	If MatchFound = True Then
		oAsset = oAssyDoc.Assets.Item("Smooth - Red")


	End If
	oOcc.Appearance = oAsset
Next &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 17:10:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7853567#M81949</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-14T17:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: change sected parts colour in an assembley</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7853767#M81956</link>
      <description>&lt;P&gt;Ok, so if the code works good up until that point, you need to very careful examine everything that happens after.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;	If MatchFound = True Then
		oAsset = oAssyDoc.Assets.Item("Smooth - Red")
	End If
	oOcc.Appearance = oAsset
Next &lt;/PRE&gt;
&lt;P&gt;What we set is that oASSET is assigned a value inside an if loop. If TRUE, the oASSET value gets assigned, if FALSE, the oAsset value isn't assigned. Look back through all of the code before this, and we see there is no default value assigned to the oASSET OBJECT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If we look past the IF Statement, we see that the program is trying to assign the oASSET to an object, so of course it will fail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's really only 2 ways to fix it: ensure the oAsset variable DOES have a value when we try to assign it, or don't assign it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We could add an if statement before the&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;oOcc.Appearance = oAsset&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;line to ensure that the line is only run if&amp;nbsp; NOT (oAsset is Nothing)... but that would be redundant, since we can just move the line inside of the if loop that assigns the oAsset value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 18:03:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7853767#M81956</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2018-03-14T18:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: change sected parts colour in an assembley</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7855345#M81979</link>
      <description>&lt;P&gt;thank you for your help, in this it works when I put&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;oOcc.Appearance = oAsset &lt;/PRE&gt;&lt;P&gt;inside the if statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 09:25:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/change-sected-parts-colour-in-an-assembley/m-p/7855345#M81979</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-15T09:25:19Z</dc:date>
    </item>
  </channel>
</rss>

