Getting the material of a face not directly assigned...
-
You can detect if there is a material applied to the group/component. Then if a face material is "nil", you know that it has the group.component material applied to it.
group_mat = my_group.material.name
That should do the trick!
Chris
-
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.
-
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
-
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.
-
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. -
@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...
-
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...
-
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...
-
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.
-
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.
-
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 ?
Advertisement