Auto Populate Layers and Assign from Component Definitions?

Hi all,
I’m not sure which category this belongs. I’m not sure if it has been done or if/how it could be done. I’ve pondered a few times lately and think it might be useful, but haven’t seen anything that achieves it so far. But I’ll just ask anyway.

I finish a model using components and have given all the definitions names as I created them. I now create layers the same name as the definition names and then assign the components to the layers for the purpose of creating scenes.

Sometimes this can be tedious if there are lots of components. I realise that I could save Layers into a template but the parts I create often have very unique names from one model to the next, so the layer names will differ.

So, is/ would there be a way to auto populate layers from all the component definition names in the model and assign all the instances of the definition to the layers created automatically?

Appreciate any thoughts, thanks.

1 Like

I didn’t search to see whether an extension already exists, but this certainly sounds like a relatively straightforward exercise of the Ruby API. However, please clarify whether you are really talking about Component Definitions or Component Instances. If a definition has multiple instances and the instances also have names, would you want a single layer for the definition name and to associate all instances to it despite their individual names? Also, how would you want nested components handled? Any likelihood a component would already be associated with a layer?

Thanks for your interest.
I don’t usually bother with instance names, so without thinking about it too much I could stick to just the definition names.

I think nested could be created too, I don’t think there would be any harm in that, it would give options I suppose.

Nothing would already be associated with a layer.

I realise I may have to add in other layers manually depending on the model, but the majority would be done.

Try cut and paste the contents of this file into the Ruby Console (you may have to then press return to get it to run).

defs_to_layers.rb (416 Bytes)

1 Like

Good lord, thats fast and so generous of you!

I’m just out for a little while so I’ll report back later. Thanks.

A footnote: Component definitions are abstract things that don’t have associated layers; component instances are the real things in the model that can have layers. The snippet I provided creates a layer with the same name as each definition and associates each instance of the definition with that layer. If a component has no instances currently in the model, the code I sent will still create a layer but nothing will be associated with it. Re-running the code when there are instances will catch them with no penalty.

Edit: well, technically a ComponentDefinition inherits methods to assign a layer to it. But it is not clear why and I don’t know of any operation that is affected by this assignment!

Ah yes good point, I understood but didn’t use the right term! (corrected above)

But, yes this appears to be superb. Layers have been created from all component definition names in the model and all the instances have been assigned to the Layer…

Thanks a lot, I owe you a beer!

1 Like

They also inherit methods to assign a material which you’d think is weird, (and it is) ,
see my detailed report in the issue tracker …

So, if they implement the ideas I put forth (in the issue cited,) perhaps the definition’s layer setting could become the auto-generated default layer for any of it’s new instances.