sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Change Material Based on Component Dimension

    Scheduled Pinned Locked Moved Dynamic Components
    sketchup
    6 Posts 2 Posters 1.8k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      knewstubb
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        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=... ?

        TIG

        1 Reply Last reply Reply Quote 0
        • K Offline
          knewstubb
          last edited by

          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 value

          Any other advice?

          Brad

          1 Reply Last reply Reply Quote 0
          • K Offline
            knewstubb
            last edited by

            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

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              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

              1 Reply Last reply Reply Quote 0
              • K Offline
                knewstubb
                last edited by

                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

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement