Change Material Based on Component Dimension
-
I am trying to setup a dynamic component to change colour if a dimension is changed.
The context is that of a construction panel for building houses. If the panel is standard width (1200mm) the panel is blue, however if it is less than 1200mm it needs to be cut and the colour needs to change to red to identify that.
I have tried setting up the attributes as follows within the component top level:
Material:=IF(Current("LenX")=120,#5E8CD1,#FF0000)
This does not seem to work. Do I have my syntax incorrect? Any advice would be most appreciated.
Brad
-
The hex color codes should be inside ''. So try:
Material:
=IF(LenX=120, '#5E8CD1', '#FF0000')
And depending on how the rest of your DC code works... perhaps
Current!LenX=
... ? -
Hi TIG,
Thanks for the reply however it still hasn't solved my issue. I have tried all the following and I still get the red #:
=IF(LenX=120, '#5E8CD1', '#FF0000')
=IF(Current!LenX=120, '#5E8CD1', '#FF0000')
=IF(Current("LenX")=120, '#5E8CD1', '#FF0000')
=IF(EX_W_165_2.4!LenX=120, '#5E8CD1', '#FF0000')
- this is the top level component name
=IF(SH_EX_12_2.4!LenX=120, '#5E8CD1', '#FF0000')
- this is a child that always has the same LenX valueAny other advice?
Brad
-
Hi TIG,
I have tried what you suggested however I am still getting the Red #. Below are the variations i have tried so far.
=IF(LenX=120, '#5E8CD1', '#FF0000')
=IF(Current!LenX=120, '#5E8CD1', '#FF0000')
=IF(Current("LenX=120"), '#5E8CD1', '#FF0000')
=IF(EX_W_165_2.7!LenX=120, '#5E8CD1', '#FF0000') -- This is the component Name.
=IF(SH_EX_12_2.7!LenX=120, '#5E8CD1', '#FF0000') -- This is a child component with a LenX that always = the parent.Any other ideas?
Brad
-
Use " around DC strings NOT '.
Also it seems the Materials specified in the test needs to be loaded in the model.
You can also try it without the hex '#' - I believe it's optional.
But the hex color needs to match the Material color !
Also try using another way of specifying the color, to see if that is the issue...
I think two Materials named "Red" and "Green" and referenced as that in the DC will work.Also try this side-step:
Add an attribute:
lx: =LenX
Then edit the
Material: =if(lx=120, "Green", "Red")
Do you want it to only appear that color if it's exactly that length ?
use <= or >= otherwise?PS:
A trick to enable the two Materials in an imported DC - AND so as to be unPurge-able - is to make a very small 'swatch' face inside the DC - located within its main volume so it's not seen - color the front 'Red' and its back 'Green' [use a section-plane to temporarily access the interior]. If you need more materials use more swatch faces... -
TIG,
Every suggestion you have made works perfectly; the issue was actually with my system.
I am running OSX and it turns out that when smart quotes are enabled sketchup does not recognise " as a valid symbol. I discovered this when I copied and pasted code I found online it worked but when I retyped it, symbol for symbol, it did not. Very weird
In order to fix this I needed to do the following:
System Preferences -> Keyboard -> Text -> uncheck "Use smart quotes and dashes"This is something that I am sure trips up many OSX users and should probably be looked at by Sketchup.
Thanks again for all your help.
Brad
Advertisement