Color Override of Derived/Mirrored parts - iLogic & Inv2016

Color Override of Derived/Mirrored parts - iLogic & Inv2016

Anonymous
Not applicable
1,368 Views
12 Replies
Message 1 of 13

Color Override of Derived/Mirrored parts - iLogic & Inv2016

Anonymous
Not applicable

Hello, is there an ilogic piece of code that could remove the "Use color override" checkbox for derived and mirrored parts?

 

Here is my issue; I made a code that checks if the ActiveDocument is a part or an assembly and runs a code that creates variables and changes the color of the activepart, but at every derived or mirrored part, it does not do it because obviously they are by default ticked to use the color override and don't automatically update themselves unless you right click and select "Modify source part" or something like that (I use a French version, so sorry if the terms aren't exact) and then apply settings. I would like to be able to add a piece of line to my code that would say "If this piece is a mirror or derived part, uncheck this box and then keep going with the code".

 

As a temporary (hopefully?!?) solution, I added a RegEdit DWORD variable to permanently uncheck that feature from Inventor (thanks Inventor Forum!), but if I could add that to my code instead, it would be even better as we wouldn't need to remember to do it IF we need to format our machines or change versions of Inventor.

 

Thanks !

0 Likes
Accepted solutions (1)
1,369 Views
12 Replies
Replies (12)
Message 2 of 13

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Read this:

 

https://clintbrown.co.uk/2020/02/01/ilogic-clear-part-appearance-overrides-updated/

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 3 of 13

Anonymous
Not applicable

I am not sure to understand the purpose of that code. It seems to remove the color override of a face, it isn't unticking the "Use color override from source file" for derived or mirrored parts though... or I don't see it written in the code itself. Am I missing something there?

0 Likes
Message 4 of 13

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

Sorry, I saw now that it should run in both parts and assemblies. This post has been edited.

 

Dim oDoc As Document = ThisDoc.Document
If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
For Each oRefDoc As Document In oDoc.AllReferencedDocuments
	If oDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc).Count > 0
		If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
			For Each DerComp As DerivedPartComponent In oRefDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
				Dim oDerDef As DerivedPartDefinition = DerComp.Definition
				oDerDef.UseColorOverridesFromSource = False
				DerComp.Definition = oDerDef
			Next
		End If
	End If
Next
ElseIf oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
	For Each DerComp As DerivedPartComponent In oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
		Dim oDerDef As DerivedPartDefinition = DerComp.Definition
		oDerDef.UseColorOverridesFromSource = False
		DerComp.Definition = oDerDef
	Next
End If
Message 5 of 13

Anonymous
Not applicable

Thank you for your quick answer, however I changed the code slightly and I would need it to be ran independantly.

I am unsure on how to do this. Your code makes sense for an assembly, but the "For each oDerComp" doesn't make any sense to me for a regular if statement. I mean, I understand what it does, it goes through the list and checks if there is any derived component and changes that.. but I don't understand how to put that into an IF statement that would go as follow;

 

IF part = derived THEN

Do the code here

ELSE

Select Case Parameter("TypePiece")

bla bla bla

End Select

 

By the way, thanks for your help !

0 Likes
Message 6 of 13

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

The a derived component is what is derived in the part.

The code I posted can be run in both an assembly and a part 🙂

If the part has nothing derived in it then the for loop will do nothing.

derCOMP.PNG

 

Message 7 of 13

Anonymous
Not applicable

Sorry if I was misunderstood or if I wrote it in a way that made me misunderstood, I am french so sometimes theres the language barrier.

 

I understand that your code can be ran in an assembly or a part, but I was wondering if there was a way to remove the loop, as cycling through all of the part's features would be time consuming for most of the parts we do. (Keeping in mind the rule would be ran in the main assembly, so more often than not over 500 parts... with probably 50 to 100 features for the most part, also keeping in mind that the derived feature is ALWAYS the first one in the list for our workflow)

Hence the reason why I asked if a simple IF could be done, like "if first-feature = derivedpart then remove color association, else do something else"

0 Likes
Message 8 of 13

JhoelForshav
Mentor
Mentor

@Anonymous 

The code is not cycling through all features, only the derived components. If there are no derived components in the part, the code will not even enter the loop 🙂 If there are only one, the code will just change that one. If you have derived from two different components, it'll change the color override for both.

In other words, we're just going through the "derive features". If there are only one, we're only handling that one and not even looking at anything else in the part. "For each derivedcomponent" is not the same as "For each partfeature" 🙂

0 Likes
Message 9 of 13

JhoelForshav
Mentor
Mentor

But sure, if you really want it to only handle the first derived component, even if there are more in the part, and also have an If-Else statement regarding if there are any derived component in the part, you can go with this code:

Dim oDoc As PartDocument = ThisDoc.Document
'If there are any derived components
If oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count > 0
	'Only get the first one
	Dim oDerComp As DerivedPartComponent = oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents(1)
	'Remove color override
	Dim oDerDef As DerivedPartDefinition = oDerComp.Definition
	oDerDef.UseColorOverridesFromSource = False
	oDerComp.Definition = oDerDef
Else
	'Do whatever you want to do if there aren't any derived components
End If

I believe you've misunderstood the first code though...

Message 10 of 13

Anonymous
Not applicable

Thank you, this works perfectly !

Now, I only have one more question regarding derived parts.

Is there a way to read the original part's Sheet Metal style and set it into the derived part?

I know we can use SheetMetal.GetActiveStyle() and SheetMetal.SetActiveStyle() for that, but I don't know how to use that with the derived part to make it work.

0 Likes
Message 11 of 13

JhoelForshav
Mentor
Mentor
Accepted solution

Like this? 🙂

Dim oDoc As PartDocument = ThisDoc.Document
'If there are any derived components
If oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count > 0
	'Only get the first one
	Dim oDerComp As DerivedPartComponent = oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents(1)
	'Remove color override
	Dim oDerDef As DerivedPartDefinition = oDerComp.Definition
	oDerDef.UseColorOverridesFromSource = False
	oDerComp.Definition = oDerDef
	Dim oDerPart As Document = oDerComp.ReferencedDocumentDescriptor.ReferencedDocument
	If TypeOf (oDerPart.ComponentDefinition) Is SheetMetalComponentDefinition _
		AndAlso TypeOf (oDoc.ComponentDefinition) Is SheetMetalComponentDefinition
		oDoc.ComponentDefinition.SheetMetalStyles(oDerPart.ComponentDefinition.ActiveSheetMetalStyle.Name).Activate 
	End If
		
Else
	'Do whatever you want to do if there aren't any derived components
End If
Message 12 of 13

Anonymous
Not applicable

Yes thank you! After testing it in a new iLogic rule, it works flawlessly the way I wanted it to.

Now, I just need to add that to my existing rule, which shouldn't be too hard.

You're amazing, thank you !

0 Likes
Message 13 of 13

Anonymous
Not applicable

Oh well, I guess there is something that is still not functioning properly.

I can't use Parameter(oDerPart, "TypePiece") to read oDerPart's TypePiece variable (where the dimensions are all stored and whatnot..), and I am unsure how to make it work that way.

 

I forgot that for my code to work I need to put yours (the color override) before mine, and that I also need to change "TypePiece" to the same one, yikes! my brain is mush, it's getting too complex for my silly brain heh

0 Likes