Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding
Community
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Visual Style - every part with different color

Visual Style - every part with different color

Most of the companies are designing their CAD models with realistic colors today.

Unfortunately, it is not always possible to differentiate the parts from each other in assemblies.

Creating special view representations is not an option since this have to be re-done for each assembly and for each "real" view representation.

 

So please create a new visual style, where each part (or each assembly occurrence) gets an unique color.

 

Example with realistic colorsExample with realistic colorsExample with falsified colorsExample with falsified colorsNew visual styleNew visual style

30 Comments

Hello @all

 

@Anonymous, you were right on the unresolved assambly components. VBA works like a charm but crashes in assamblys with unresolved comps.

 

 

 

 

tdant
Collaborator

You could probably harness the magic of Try...Catch in iLogic to fix your problem. Something like:

'Code based on an Inventor Ideas forum post by Tanner Dant
'https://forums.autodesk.com/t5/Inventor-ideas/visual-style-every-part-With-different-color/idc-p/8713666#M34691
'Adapted for iLogic by @ClintBrown3D, originally posted at https://clintbrown.co.uk/ilogic-set-every-part-to-a-different-colour

Sub Main()
    Dim topAsm As AssemblyDocument
    topAsm = ThisApplication.ActiveDocument
    
    Dim trans As Transaction
    trans = ThisApplication.TransactionManager.StartTransaction(topAsm, "Unique Colors")
    
    Dim ucRep As DesignViewRepresentation
    
    On Error GoTo CreateDV
    ucRep = topAsm.ComponentDefinition.RepresentationsManager.DesignViewRepresentations("Unique Colors")
    On Error GoTo 0
    
    ucRep.Activate
	
    Dim compOcc As ComponentOccurrence
    For Each compOcc In topAsm.ComponentDefinition.Occurrences
        Dim uAppearance As Asset
        uAppearance = topAsm.Assets.Add(kAssetTypeAppearance, "Generic", "appearances")
		        
        Dim uColor As ColorAssetValue
        uColor = uAppearance.Item("generic_diffuse")
		RNG = Round(Rnd * 255)
		RNG1 = Round(Rnd * 255)
		RNG2 = Round(Rnd * 255)

        uColor.Value = ThisApplication.TransientObjects.CreateColor(RNG, RNG1, RNG2)
        
        Try
            compOcc.Appearance = uAppearance
        Catch
        End Try
    Next
    
    trans.End
    Exit Sub
    
CreateDV:
    ucRep = topAsm.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Add("Unique Colors")
    Resume Next
End Sub
thom-g
Advocate

Hi @all,

@tdant  & @Anonymous : thank you both for sharing the source code.

 

I made a small change to your code, which should solve the issue with the unresolved components.

Please check the code first since I am not familar with VBA.

'Code based on an Inventor Ideas forum post by Tanner Dant
'https://forums.autodesk.com/t5/Inventor-ideas/visual-style-every-part-With-different-color/idc-p/8713666#M34691
'Adapted for iLogic by @ClintBrown3D, originally posted at https://clintbrown.co.uk/ilogic-set-every-part-to-a-different-colour

Sub Main()
    Dim topAsm As AssemblyDocument
    topAsm = ThisApplication.ActiveDocument
    
    Dim trans As Transaction
    trans = ThisApplication.TransactionManager.StartTransaction(topAsm, "Unique Colors")
    
    Dim pBar As ProgressBar
    pBar = ThisApplication.CreateProgressBar(False, topAsm.ComponentDefinition.Occurrences.Count, "Unique Colors", False)

    ThisApplication.UserInterfaceManager.UserInteractionDisabled = True
    
    Dim ucRep As DesignViewRepresentation
    
    On Error GoTo CreateDV
    ucRep = topAsm.ComponentDefinition.RepresentationsManager.DesignViewRepresentations("Unique Colors")
    On Error GoTo 0
    
    ucRep.Activate
	
    Dim compOcc As ComponentOccurrence
    Dim docDesc As DocumentDescriptor
    For Each compOcc In topAsm.ComponentDefinition.Occurrences
        docDesc = compOcc.ReferencedDocumentDescriptor
        If docDesc.ReferenceMissing = False Then
            If docDesc.ReferenceSuppressed = False Then
                If compOcc.Suppressed = False Then
                    If compOcc.Excluded = False Then
                        Dim uAppearance As Asset
                        uAppearance = topAsm.Assets.Add(kAssetTypeAppearance, "Generic", "appearances")
		        
                        Dim uColor As ColorAssetValue
                        uColor = uAppearance.Item("generic_diffuse")
	            	    RNG = Round(Rnd * 255)
	            	    RNG1 = Round(Rnd * 255)
	            	    RNG2 = Round(Rnd * 255)

                        uColor.Value = ThisApplication.TransientObjects.CreateColor(RNG, RNG1, RNG2)
        
                        Try
                            pBar.Message = "Changing color of component: " + componentOccurrence.Name
                            pBar.UpdateProgress
                            compOcc.Appearance = uAppearance
                        Catch
                        End Try
                    End If
                End If
            End If
        End If
    Next
    
    ThisApplication.UserInterfaceManager.UserInteractionDisabled = False
    pBar.Close
    trans.End
    Exit Sub
    
CreateDV:
    ucRep = topAsm.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Add("Unique Colors")
    Resume Next
End Sub

And the same in C#:

/// <summary>
/// creates an unique color for each component occurrence
/// </summary>
/// <remarks>
/// original source by user "tdant": https://forums.autodesk.com/t5/inventor-ideas/visual-style-every-part-with-different-color/idc-p/9257138
/// </remarks>
private static void UniqueColorRep()
{
    if (Application.ActiveDocument == null)
        return;

    if (Application.ActiveDocument.DocumentType != Inventor.DocumentTypeEnum.kAssemblyDocumentObject)
        return;

    Inventor._AssemblyDocument assemblyDocument = Application.ActiveDocument as Inventor._AssemblyDocument;

    Inventor.Transaction transaction = Application.TransactionManager.StartTransaction(assemblyDocument as Inventor._Document, "Unique Colors");
    Inventor.ProgressBar progressBar = Application.CreateProgressBar(false, assemblyDocument.ComponentDefinition.Occurrences.Count, "Unique Colors", false);
    Application.UserInterfaceManager.UserInteractionDisabled = true;
    try
    {
        Inventor.DesignViewRepresentation ucRep = null;
        foreach (Inventor.DesignViewRepresentation designViewRepresentation in assemblyDocument.ComponentDefinition.RepresentationsManager.DesignViewRepresentations)
        {
            if (designViewRepresentation.Name.Equals("Unique Colors"))
            {
                ucRep = designViewRepresentation;
                break;
            }
        }
        if (ucRep == null)
            ucRep = assemblyDocument.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Add("Unique Colors");
        ucRep.Activate();

        Random rnd = new Random();
        foreach (Inventor.ComponentOccurrence componentOccurrence in assemblyDocument.ComponentDefinition.Occurrences)
        {
            Inventor.DocumentDescriptor documentDescriptor = componentOccurrence.ReferencedDocumentDescriptor;
            if (documentDescriptor.ReferenceMissing)
                continue;
            if (documentDescriptor.ReferenceSuppressed)
                continue;
            if (componentOccurrence.Suppressed)
                continue;
            if (componentOccurrence.Excluded)
                continue;

            progressBar.Message = $"Changing color of component: {componentOccurrence.Name}";
            progressBar.UpdateProgress();

            Inventor.Asset assetAppearance = assemblyDocument.Assets.Add(Inventor.AssetTypeEnum.kAssetTypeAppearance, "Generic", "Appearances");
            Inventor.ColorAssetValue colorAssetValueAppearance = assetAppearance["generic_diffuse"] as Inventor.ColorAssetValue;
            colorAssetValueAppearance.Value = Application.TransientObjects.CreateColor(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)));

            componentOccurrence.Appearance = assetAppearance;
        }
    }
    catch (Exception ex)
    {
        System.Diagnostics.Trace.TraceError($"ERROR: {ex.Message}");
    }
    finally
    {
        Application.UserInterfaceManager.UserInteractionDisabled = false;
        progressBar.Close();
        transaction.End();
    }
}
Anonymous
Not applicable

@tdant great idea! 

rubengualtero
Observer

thank you so much @tdant !!!!

sobalvarro
Participant

Quite an old thread, but until this idea gets implemented there is an AddIn that do the work with one click.

ReColor | Inventor | Autodesk App Store

I had to develop it myself as while projecting on meetings, there was no contrast that allows to differentiate the parts.

@Anonymous Thanks for the ilogic very good ideia, is there any possibility to make the same parts the same color but always distinct from the others?

 

rkov_no
Participant

This is a very good suggestion.
I have also taken the liberty of posting a somewhat similar suggestion, for a more subtle/realistic look. Take a look at the idea: "Differentiating colours along component edges".

Yijiang.Cai
Autodesk
Status changed to: Accepted

Many thanks for posting the idea to us, and accepted as [INVGEN-66574]

Yijiang.Cai
Autodesk
Status changed to: Implemented

This idea has been implemented within Autodesk Inventor 2025. Please review the Inventor 2025 What's New article here. For more information regarding how you may leverage the feature, and please review this page. Special thanks to everyone who cast a vote for it.

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

Submit Idea  

Autodesk Design & Make Report