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

    Assigning a default material.

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 5 Posters 1.3k Views 5 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.
    • D Offline
      Deanby7
      last edited by

      I am trying to add a Brick_Antique material to a face with Ruby. The material is in the model already, but will not apply the material with this code....

      mats = Sketchup.active_model.materials
      brick = mats['Brick_Antique']
      ......
      oface.material = brick
      
      

      However, if I make the Brick material current in the model and then use this....

      current = Sketchup.active_model.materials.current
      .....
      oface.material = current
      

      It works!
      I assume from this that the display name cannot be used to reference the material. So how would I get the internal name of any in-model material if you only know its display name?

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        @deanby7 said:

        I am trying to add a Brick_Antique material to a face with Ruby. The material is in the model already, but will not apply the material with this code....

        mats = Sketchup.active_model.materials
        > brick = mats['Brick_Antique']
        > ......
        > oface.material = brick
        > 
        

        However, if I make the Brick material current in the model and then use this....

        current = Sketchup.active_model.materials.current
        > .....
        > oface.material = current
        

        It works!
        I assume from this that the display name cannot be used to reference the material. So how would I get the internal name of any in-model material if you only know its display name?

        This should

        mats = Sketchup.active_model.materials
        brick = mats['[Brick_Antique]']
        ......
        oface.material = brick
        

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • D Offline
          driven
          last edited by

          or use grep

          
          oface.material = Sketchup.active_model.materials.grep(/Brick_Antique/)
          

          john

          learn from the mistakes of others, you may not live long enough to make them all yourself...

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

            A material has two 'names'.
            If you have created it then they'll be the same,
            material.name >>> "SomeName" material.display_name >>> "SomeName"
            but if you have imported it from an external collection then they are likely to be different - e.g. inside []...
            material.name >>> "[SomeName]" material.display_name >>> "SomeName"
            Another way to set it by ' display_name' [i.e. what you can read] would be...
            mats = model.materials name = 'Brick_Antique' mat = nil mats.each{|m| if m.display_name == name mat = m break end } oface.material = mat

            In you case I assume it's relating to your 'hole making' ?
            If you want to match the new reveals' material to the cut face, then you don't even need to know the material's name at all.
            Let's assume the face you are making the hole in is referenced as ' face'.
            Then use
            omat = **face**.material oface.material = omat
            Which takes a direct reference to the material [if any] - sidestepping any need to know its name/display_name at all...

            TIG

            1 Reply Last reply Reply Quote 0
            • D Offline
              Deanby7
              last edited by

              The last code is exactly what I want. Thanks.

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                @tig said:

                Another way to set it by ' display_name' [i.e. what you can read] would be...
                mats = model.materials name = 'Brick_Antique' mat = nil mats.each{|m| if m.display_name == name mat = m break end } oface.material = mat

                Still another way:
                mats = model.materials name = 'Brick_Antique' mat = mats.find {|m| m.display_name == name } oface.material = mat

                I'm not here much anymore.

                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