Layer structure/tree for a given entity(s) in a model?

Hi guys! How do I access the Layer structure for a given entity(s) in a model?

–>Layer0 has LayerWalls and LayerRoofs
–>LayerWalls has LayerWindows,LayerDoors and LayerVentilator
–>LayerWindows has LayerWindowFrame and LayerWindowPanes

How can I access a tree of the Layers for layer WindowFrames , as in when the user selects a window frame it should show its parent layers in a structured way as:


Thanks in advance.

SketchUp has no nested layers / layer tree hierarchy. Because of that an entity has exactly one layer and no parent layers.

Can you explain what exactly you have in mind? If you refer to a certain extension, could you mention which?
Or have you “emulated” a layer hierarchy by using a strict naming convention (child layer name = parent layer name + suffix)?
Or are you thinking of the component hierarchy, and want to get the layers of the entity and the layers of all its parent components?

Your wording also suggests you may be thinking of “layers” the way other CAD programs use the term, as content separators, rather than the way SketchUp uses it, as visibility controls.

Sorry, I should have known better. I though layers followed the similar structure as they do in other modelling tools.

so as you pointed

Could you give me a pointer as to how could I achieve this?

All I can think of currently is


but that would print out all the layers. Right?
How could I print only the selected entity(s) layers and also its parent’s layer using the SelectionObserver?

Thanks for your help! :smile:

@slbaumgartner My mistake, thats exactly what was was thinking. So what I can do now is get the entity(s) layer and all the layer of its parents components.

An entity (which may be a component instance) is contained either in the model or in a component definition. This results in a hierarchy of containment. (As mentioned earlier, SketchUp layers have neither a hierarchy nor an order).

If an entity is contained in a component, you can encounter it in many instances of that component. So the way from an ‘entity’ to its containing component instance is ambiguous. If you use a selection observer, it will select only in the active entities anyways, so we could take this as reference.

layers = (entity.model.active_path.nil?) ? [] :{ |component_instance| component_instance.layer }
layers << entity.layer

(You may also want to make this array .uniq and get the layer names .map{ |layer| } ).

If you just want to print:

unless entity.model.active_path.nil?
  entity.model.active_path.each{ |component_instance|
    puts "#{component_instance} is on layer '#{component_instance.layer}'"
puts "#{entity} is on layer '#{entity.layer}'"

This does not mean that the entity is on all these layers, the entity is exactly on one layer. It just means that all these layers must be visible, so that all containing component instances are visible, so that the entity can be seen.