Change Part Colour Using "RGB" Values

Change Part Colour Using "RGB" Values

isocam
Collaborator Collaborator
1,867 Views
4 Replies
Message 1 of 5

Change Part Colour Using "RGB" Values

isocam
Collaborator
Collaborator

Can anybody help?

 

I am trying to set the colour of a part, via a VBA macro, using RGB Values.

 

Can someone try the following VBA macro on a Inventor part (ipt) document and let me know if you are getting the same error as me?

 

Public Function SetPartColour()
Dim oDoc As PartDocument

Set oDoc = ThisApplication.ActiveDocument

Dim color As ColorAssetValue

Set color = oDoc.ActiveAppearance.Item("generic_diffuse")

color.Value = ThisApplication.TransientObjects.CreateColor(Red, Green, Blue)
End Function

 

I get an error on the line highlighted in RED

 

Does anybody know how I can fix the error?

 

Many thanks in advance!!!!

 

Darren

0 Likes
Accepted solutions (2)
1,868 Views
4 Replies
Replies (4)
Message 2 of 5

mcgyvr
Consultant
Consultant

What version of Inventor are you using? 

 

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 3 of 5

isocam
Collaborator
Collaborator

I am currently using 2021 (And testing 2022).

 

Are there different macros to change the colour depending on what version of inventor you are using?

 

Many thanks in advance!!

 

Kind Regards

 

Darren

0 Likes
Message 4 of 5

FINET_Laurent
Advisor
Advisor
Accepted solution

Hi,

 

Here is how I do it :

 

Dim oAppearence As Asset
oAppearence = oDoc.Assets.Add(kAssetTypeAppearance, "Generic", "Appearances")

Dim oColor As ColorAssetValue
oColor = oAppearence.Item("generic_diffuse")

oColor.Value = ThisApplication.TransientObjects.CreateColor(0,145,255)

oExtrude1.Appearance = oAppearence

 oExstrude1 is set before hand.

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 5 of 5

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @isocam 

 

In case it's of interest, attached is a 2019 file that creates a new appearance in the part and allows you to use sliders in a form to change the color dynamically.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature