@rossthompson said:
TIG - thanks so much for that.
Would it be possible to revise the code to ignore any nested components? I guess this could be done with a simple change to the definition?
Also could the layer colour be fixed to black?
Thanks so much for your help
Ross
When you say 'nested' I assume you mean you want to re-layer only instances within the 'model.entities'... This new version does that - but actually it re-layers all instances in the 'active_entities' context, so if you run it whilst editing a group etc only instances inside that group are affected, to affect only instances in the model.entities ensure that you are in the model.entities context before running it - this allows you the fullest flexibility, with the opportunity to edit certain nested instances separately, if so desired...
m=Sketchup.active_model;m.start_operation('c');m.active_entities.each{|e|next unless e.is_a?(Sketchup;;ComponentInstance);n=e.definition.name;l=m.layers.add(n);e.layer=l};m.commit_operation
Layer colors cannot currently be accessed/changed by the API, you'll have to do that change to 'black' manually. There are some convoluted workarounds [e.g. make layer.color= developers' method hack], but it'll be just as fast to do it manually in the Layer Browser...