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

    Getting the material of a face not directly assigned...

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 4 Posters 341 Views 4 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.
    • F Offline
      fizgig
      last edited by

      Good point. Trouble is I often have the face within a group within a group within a group... I suppose I could write a function to keep going backward if worse comes to worse. Just wondering if there's a better way.

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        ahh I see. True. But I tihnk that is how it has to be done. You will need to check the parent.material of entity with material==nil. And do that backwards until the parent is the active model. And the first parent with a material applied is the one that is actively showing on the face. If no parent has a material applied, then the face is actually displaying as the default material. But that is a little bit of a pain.

        Chris

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

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

          
          def nestedfacematerial(face)
           ### face is the face being looked at...
           model=Sketchup.active_model
           mat=face.material
           if face.parent!=model and not mat
            parent=face.parent.instances[0]
            if not parent.class==Sketchup;;Group
              puts "Face.parent... is not a Group - can't continue."
              return nil
            end#if
            ### It can't work on Components as each Instance could have a different
            ### Material and we can't tell which Instance the Face is in as it's 
            ### in the Definition's Entities - but a Group should be unique ?
            while not mat=parent.material
              parent=parent.parent.instances[0]
              if parent==model
                mat=nil
                break
              end#if
            end#while
           end#if
          ### mat = material
           if mat
             if face.parent!=model
               puts "Face.parent...material.name = "+mat.name
             else
               puts "Face.material.name = "+mat.name
             end#if
           else
             puts "Face.material = nil"
           end#if
           return mat
          end#def
          
          

          It's limited to a Face in (nested) Groups, which should be unique; a Face in a Definition will fail because it is different - each Instance could have a different Material but we can't tell which particular Instance the Face in question is in as that Face actually resides in the Definition and not the Instance that has the Material.

          TIG

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            Groups have instances like Components. If you make a group and copy it around, they all share the same definition, but each group instance can have different colour. So the problem is the same.
            Also - groups some times get their .parent reference wrong. Need extra check to make sure you have the right one.

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

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

              @thomthom said:

              Groups have instances like Components. If you make a group and copy it around, they all share the same definition, but each group instance can have different colour. So the problem is the same.
              Also - groups some times get their .parent reference wrong. Need extra check to make sure you have the right one.

              I agree... that's why I said Group 'should' be unique ! It could use 'make_unique' on it ? This is another right mess...

              TIG

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                It could, but I wouldn't do that. Some people might rely on the group copies.

                Really wish they'd cleared up the all the problems with the API and groups...

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

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

                  The whole ideas is that Groups are unique but Components can have multiple Instances either by Copy or Inserted from a Browser etc...

                  You cannot Insert a Group from a Browser and the Copy of a Group should be made unique in the process of making that Copy - there should never be group.definition.instances[1] - though I know there can be !!!

                  It is a bad habit to use Copies of a Group to allow editing of multiple versions later - that is what Components are for !

                  Groups shouldbe a collection of things that separates those things from others - like Geometry - nothing more...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    None the less, I all too often come across models where groups have been copied multiple times across a model. As long as they retain their definition to be the same I can use my Selection Toys plugin to convert them into components.

                    Thomas Thomassen — SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • F Offline
                      fizgig
                      last edited by

                      😄

                      You guys are illustrating why I was looking for a shortcut. The face in question that I want to see the material of can possibly be inside a group inside a component instance inside a group and so forth. This makes it challenging to do what I want to do.

                      Not a big deal for me, I can solve my particular problem by going another route that doesn't require my knowing the inherited face material. It wont be as elegant but it will solve the problem I'm working on.

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

                        Why not have a method that picks a face and returns its material. If it's nil and it's not in the model then the picked point could also return the 'container' - i.e. group or component and it's material - if it's not nil then that's the nil face's material too... Your 'pick-helper' can return two values ?

                        TIG

                        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