Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Error changing part colour using VBA macro

isocam
Collaborator

Error changing part colour using VBA macro

isocam
Collaborator
Collaborator

Can anybody help?

Can somebody try the following VBA macro and tell me if they get an error on the line that contains the words "Set color"?

 

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(255, 42,27) ' Red
End Function

 

I cannot get the macro to work. Does anybody know what's wrong.

 

Many thanks in advance!!!

 

Darren

0 Likes
Reply
338 Views
2 Replies
Replies (2)

HideoYamada
Advisor
Advisor

Hello,

 

Your macro works and the color of part has been changed to red.

 

capture.png

 

My system is...

- Windows 10 Pro 1903 64bit Japanese

- Inventor 2020.1 + Japanese language pack

 

Does the appearance of your part document have an item "generic_diffuse"?

Run the macro follows and check having it or not.

 

Public Sub Dump()
    Dim obj As Object

    For Each obj In ThisApplication.ActiveDocument.ActiveAppearance
        Debug.Print obj.Name
    Next
End Sub

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes

matt_jlt
Collaborator
Collaborator

One thing that could cause it to throw an error is not having the correct appearance library active (the colour specified isn't in the active library). You may need to have an additional check to see if it's in there first or activate it then run the code again.

0 Likes