Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assembly Macro Color (keeping component properties) 1

Status
Not open for further replies.

tgoudie000

Aerospace
Jul 12, 2004
4
So I am interested in coloring a part inside of an assembly using the 'component properties'. However I cannot find how to do this using a macro.

I am interested in doing this because I am exporting the file in VRML format and it will only recognize color if the color is specified in the assembly (rather than the part).

The macros that I have seen can color a particular part, but this color will continue throughout all the other (similar) parts that are inserted into the assembly.
I want to color each individual part a different color on the assembly level and I cannot color the part using the feature properties or face panels to get this effect.

Could someone point me to some code or to a function call inside of solidworks... Im using 2003

Thanks
 
Replies continue below

Recommended for you

RMB the part in the assembly and either "Click Properties" or "Appearance"

Properties =

Click the "Color" button and select the color you want for the part at the assembly stage.

Appearance =

Click "Color" in the flyout menu. In the Color Properties in the Property Manager you can select the Color of the part your seeking.

Regards,

Scott Baugh, CSWP [pc2]

If you are in the SW Forum Check out the FAQ section

To make the Best of Eng-Tips Forums FAQ731-376
 
below are excerpts pasted from SW help...

Code:
Component2.MaterialPropertyValues = MaterialPropertyValues (VB Set property)

SWAPIhelp said:
The format of the parameters or return values is an array of doubles as follows:
[ R, G, B, Ambient, Diffuse, Specular, Shininess, Transparency, Emission ]


[bat]Due to illness, the part of The Tick will be played by... The Tick.[bat]
 
Hi all thanks for the quick response...
However using the MaterialPropertyValues goes into the part of the assembly and changes the color, then that color is then displayed throughout the assembly. The problem this creates is that all the subsequent parts that are in the assembly which share the same name are then colored the same.

I am interested in changing the color in the assembly for each individual part that is contained in the assembly. Not for every part that shares the same name inside the assembly.

List of the code:

Dim Temp As Variant
Dim (Everything else as an object) and
Dim Component() as Object

Set swApp = CreateObject("SldWorks.Application")
Set AssyDoc = swApp.ActiveDoc
Set Configuration = AssyDoc.GetActiveConfiguration()
Set RootComponent = Configuration.GetRootComponent()
Component = RootComponent.GetChildren
Set Child = Component(0)
Set Component2 = Child.GetModelDoc
Temp = Component2.MaterialPropertyValues
Temp(0) = 16711680
Temp(1) = 0
Temp(2) = 1
Temp(3) = 1
Temp(4) = 0.21
Temp(5) = 0.21
Temp(6) = 0.21
Temp(7) = 0.21
Temp(8) = 0.21

Component2.MaterialPropertyValues = Temp

I havent seen anything which can do this yet on the forums, but if someone can point me in the right direction that would be great

Thanks

 
Here's your culprit:
Code:
Set Component2 = Child.GetModelDoc

You are setting "Component2" to be the ModelDoc object, which is the part file. You want to change the properties of "Child".

[bat]Due to illness, the part of The Tick will be played by... The Tick.[bat]
 
Thanks for the info I actually had to keep
Set Component2 = Child.GetModelDoc

but I changed the Child properties at the end
Child.MaterialPropertyValues = Temp

Something was wrong with mismatching the information

Thanks
 
tgoudie000,
Have you looked at the macros on Matt Lombard's website?
Go to:
then click the "Macro Library" button.

There is a macro in there to change color of all of the parts in an assembly. I don't know that it'll work *exactly* the way you want, but maybe it'll shed some light for a solution.
Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor