Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

use Logic to change color of an assambly

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Darkforce_the_ilogic_guy
392 Views, 5 Replies

use Logic to change color of an assambly

How do I change color of an assembly change color to "RAL 7035" ?

 I need to work on all Assembly

And to use Ilogic and I use before save

5 REPLIES 5
Message 2 of 6

This rule changes the color of all occurrences of the assembly, select the default library color, do not put your color because my library does not have it, and to test the code I assembled it (I tried it and it worked for me)

 

Dim oAsset As Asset
Dim oAsset_Array As New ArrayList
For Each oAsset_Array_X In ThisApplication.ActiveAppearanceLibrary.AppearanceAssets
oAsset_Array.Add(oAsset_Array_X.DisplayName)
oAsset_Array.Sort()
Next
'present the user with the list to choose from
100:
oAsset_Array_Selected = InputListBox("CHOOSE TEXTURE FROM ABOVE LIST", oAsset_Array, oAsset_Array.Item(0), "TEXTURE SELECTION", "LIST OF TEXTURES")
If oAsset_Array_Selected = "" Then GoTo 100 :

'---------------------------------------------------------

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAsmDoc.ComponentDefinition

Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences

	Component.Color(oOccurrence.name)=oAsset_Array_Selected
	iLogicVb.UpdateWhenDone = True 

Next

 

I guess you should have a line something like this

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAsmDoc.ComponentDefinition

Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences

	Component.Color(oOccurrence.name)="RAL 7035"
	iLogicVb.UpdateWhenDone = True 

Next

I hope it helps to solve your problem, greetings


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 6

Thanks that was just what I needed to do the next step in the Ilogic code I am working on... Do you know way it come with I warring that it only works in Assambly ? I have found a workaround ... by simple make it a standalone code aand  just make my other code run it when needed ... but I would love to be enable to use it at one code without the warring

Message 4 of 6

please excuse me @Darkforce_the_ilogic_guy  , but the language barrier does not allow me to understand exactly what you are looking for, if you explain in more detail I would like to help you in something. 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 5 of 6

@Darkforce_the_ilogic_guy,

 

Hoping that below iLogic code helps to change asset only for assembly component in assembly.

 

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
 
Dim oAsmDef As AssemblyComponentDefinition 
oAsmDef = oAsmDoc.ComponentDefinition 

'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	Exit Sub
End If

Dim localAsset As Asset = Nothing
Try
	localAsset = oAsmDoc.Assets.Item("RAL 7035")
Catch 
	Dim assetLib As AssetLibrary = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library") 
 
	Dim libAsset As Asset = assetLib.AppearanceAssets.Item("RAL 7035")

	' Copy the asset locally.
	localAsset = libAsset.CopyTo(oAsmDoc)
End Try

Dim oCompOcc As ComponentOccurrence 

For Each oCompOcc In oAsmDef.Occurrences
	 If oCompOcc.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		 oCompOcc.Appearance = localAsset
	 End If 
Next

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 6 of 6

it is ok. the code you give me. did the part I needed help with.

 

I did only need help with part of my code. And your code did that i needed.

 

my complete code ... Ask the user to add a surface to custom Iperperties... IF the part or assambly is Raw, Colour 1, and so on. 

 

with the new code i add ... it now change the colour of the part or Assambly to the Colour that it would have .. withour the user have to do it them self... and it change this in all view.

 

but most of the other just I already know how to do 

 

 

 

 

Tags (1)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report