sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Set alpha of a face without material

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 2 Posters 222 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.
    • N Offline
      niccah
      last edited by

      When I draw a face, the material of this face is nil.

      But how can I set an alpha value without setting a material?

      Following situation:

      • one large face and something behind that face
      • by clicking on a "show / hide" button, this large face should get semi transparent, to see, what's behind
      • by clicking it again, the face should get the same color as before.

      I would like to avoid, to set at first a material, so set an alpha value. And reverse it again...

      Do you have an idea, how I can handle this problem?

      Thank you very much for your help!

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

        You can't. πŸ˜•

        A new face has a default front material and back material, and they are both a plain color.

        If you want to make a face transparent then you need to assign it a material that is itself transparent; OR place the face inside a group or component-instance that has a transparent material, and thereby it will appear in the container's material provided that it and the default material...

        Swapping the material on a button click is quite easy to do.

        Alternatively your button click could simply hide/show the face, or move the face onto an OFF layer temporarily.

        BUT to give a lone face transparency you need to use a material...
        Why are you so set against this obvious [and only practicable] solution?

        TIG

        1 Reply Last reply Reply Quote 0
        • N Offline
          niccah
          last edited by

          @tig said:

          Why are you so set against this obvious [and only practicable] solution?

          Thanks TIG for your help! No, I'm not completely against this solution. I just thought, if it is possible to set alpha without any material, it would be great. However, then I have to set a material πŸ˜„

          I don't like to hide this faces completely, because, I would like to compare this large face and the face behind that...

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

            So remember the omat=face.material
            Make a new translucent material [OR reuse it if it exists]
            mats=Sketchup.active_model.materials name='Tranz' unless nmat=mats[name] nmat=mats.add(name) nmat.color="White" nmat.alpha=0.5 end#unless face.material=nmat
            Then face is reset later...
            face.material=omat

            Adjust the color and alpha of 'nmat' as desired...

            TIG

            1 Reply Last reply Reply Quote 0
            • N Offline
              niccah
              last edited by

              Now, it works alomost perfectly... I'm able to show / hide the right faces. But I have problems to the save the original material (in case of TIGs idea: "omat").
              How I can save the material for ever - means, one should be able to reopen Sketchup and show the faces again...

              I tried it with "Entity.set_attribute" => but there, I can save just strings... do you have an idea, how I can save the material itself? Or can I save the ID of the material and to show the faces, call the material by its ID again?

              Thanks for your help!

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

                In your 'Tool' code make a class variable @facesmats=[], 'push' [face, material], then with the methods onCancel() or deactivate() reset the face with its material, thus:
                @facesmats.each{|a|a[0].material=a[1]}
                To always exit as you started ?
                OR use a model.start_operation('xxx') and then if there are no real changes in subsequent the code use model.abort_operation to undo all changes, including the material swap[s]...

                TIG

                1 Reply Last reply Reply Quote 0
                • N Offline
                  niccah
                  last edited by

                  Oh, okay, this is a nice trick...

                  I think, I will get a lot of problems, when Sketchup crashes...

                  What do you think about this idea:

                  I will create for every face, which has a material != nil a new material => name: face.to_s
                  To show the faces again, I will remove the materials again...

                  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