by chrisglasier » Wed Jul 29, 2009 9:40 am
I tried using this code to transfer all groups and component layers to layer0 and then purge all unused leaving dimension and label layers. (Loose geometry is dealt with separately). The problem is that some layer names remain in the inspector even though empty. - Code: Select all
model = Sketchup.active_model layers = model.layers entities = model.entities
entities.each do |entity|
if entity.class == Sketchup::Group || entity.class == Sketchup::ComponentInstance
entity.layer = layers[0]
end end
layers.purge_unused
UI.show_inspector("Layers")
Have I done something silly?
With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.
-

chrisglasier
- PluginStore Author

-
- Posts: 1055
- Joined: Tue Jun 03, 2008 9:11 am
- Location: Sri Lanka
- Name: chrisglasier
- Operating system: Windows
- SketchUp version: 2017
- License type: Free/Make
- SketchUp use: architecture
- Level of SketchUp: Intermediate
-
by tomasz » Wed Jul 29, 2009 10:06 am
It works with groups for me. I suspect that the bug is in the way you deal with loose geometry. Do you change layer of all entities in component definitions and inside groups?
-
tomasz
- SU2TH & SU2KT Developer
-
- Posts: 886
- Joined: Fri Nov 16, 2007 8:46 pm
- Location: Poland
- Name: Tomasz Marek
- Operating system: Windows
- SketchUp version: 2022
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by chrisglasier » Wed Jul 29, 2009 10:45 am
Tomasz wrote:It works with groups for me.
It doesn't seem to discriminate. Layers generally comprise components and groups. Each entity and its layer is sent to a javascript array and that seems an OK mixture Tomasz wrote:I suspect that the bug is in the way you deal with loose geometry. I think my comment about loose geometry is a bit of a red herring as I did not do anything with it before the purge. Anyway, any loose geometry is in layer0 as Gaieus' dictum. Tomasz wrote:Do you change layer of all entities in component definitions and inside groups?
No just top level as above. I did try active_entities but that did not make any difference (I never really understood the active bit). Perhaps you could expand a little on what you had in mind about this. Many thanks Chris
With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.
-

chrisglasier
- PluginStore Author

-
- Posts: 1055
- Joined: Tue Jun 03, 2008 9:11 am
- Location: Sri Lanka
- Name: chrisglasier
- Operating system: Windows
- SketchUp version: 2017
- License type: Free/Make
- SketchUp use: architecture
- Level of SketchUp: Intermediate
-
by thomthom » Wed Jul 29, 2009 11:01 am
chrisglasier wrote:No just top level as above. I did try active_entities but that did not make any difference (I never really understood the active bit). Perhaps you could expand a little on what you had in mind about this. model.entities - is always the top level - regardless. model.active_entities - is the entities of the open group/component. After you run your script, and some layers remain - do they disappear when you do a purge from SU?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by chrisglasier » Wed Jul 29, 2009 11:11 am
thomthom wrote: model.entities - is always the top level - regardless. model.active_entities - is the entities of the open group/component.
OK goddit thanks thomthom wrote:After you run your script, and some layers remain - do they disappear when you do a purge from SU?
No. I also tried saving the file and opening it again (in case something got stuck!!). Perhaps ... ? Chris
With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.
-

chrisglasier
- PluginStore Author

-
- Posts: 1055
- Joined: Tue Jun 03, 2008 9:11 am
- Location: Sri Lanka
- Name: chrisglasier
- Operating system: Windows
- SketchUp version: 2017
- License type: Free/Make
- SketchUp use: architecture
- Level of SketchUp: Intermediate
-
by Didier Bur » Wed Jul 29, 2009 11:24 am
Hi, Just an  : as groups are stored like components, maybe that changing the layer of a group doesn't change it's internal definition ? Check for internal compos definitions and scan their entities to see if they are on their original layer. In such a case, SU doesn't allow to delete the layer.
Didier Bur
-

Didier Bur
-
- Posts: 1413
- Joined: Wed Nov 14, 2007 10:07 pm
- Location: Nancy, France
- Name: Didier Bur
- Operating system: Windows
- SketchUp version: 2020
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by thomthom » Wed Jul 29, 2009 11:41 am
Your code only modifies groups/components to be placed on layer 0. It assumes that all geometry is also placed on layer 0.
Seeing how Tomasz reports it working for him I'm guessing there is some entity that's not located on layer 0. If you turn on Color By Layer (ensuring edges are coloured by material as well) - see if you see anything with a colour other than what layer 0 is set to.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by thomthom » Wed Jul 29, 2009 11:43 am
Didier Bur wrote:Hi, Just an  : as groups are stored like components, maybe that changing the layer of a group doesn't change it's internal definition ? Check for internal compos definitions and scan their entities to see if they are on their original layer. In such a case, SU doesn't allow to delete the layer.
Ah yea! iterating over the top level entities won't do it. In addition all model.definitions has to be iterated. that's it!
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by thomthom » Wed Jul 29, 2009 11:44 am
In fact, since you only want to modify groups components you don't have to check the top level at all.
Just scan the definition array for Group/Component definitions (ignoring Image definitions) and loop over the instances for each definition.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by chrisglasier » Wed Jul 29, 2009 11:52 am
Thanks all ... some overnight sleuthing is required ...
With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.
-

chrisglasier
- PluginStore Author

-
- Posts: 1055
- Joined: Tue Jun 03, 2008 9:11 am
- Location: Sri Lanka
- Name: chrisglasier
- Operating system: Windows
- SketchUp version: 2017
- License type: Free/Make
- SketchUp use: architecture
- Level of SketchUp: Intermediate
-
by thomthom » Wed Jul 29, 2009 12:06 pm
I think this will work: - Code: Select all
model = Sketchup.active_model layers = model.layers
model.definitions.each { |d|
# Ignore Images and definitions with no instances next if d.image? || d.count_instances == 0 # Set Group/ComponentInstance to layer0 d.instances.each { |i| i.layer = layers[0] }
}
layers.purge_unused
UI.show_inspector("Layers")
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by chrisglasier » Wed Jul 29, 2009 12:35 pm
thomthom wrote:I think this will work: ...
Yes thanks it does reduce the layer count from 23 to 20, of which 12 are correctly retained for non real world replica dimensions and labels. But I have to do more sleuthing ... Chris
With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.
-

chrisglasier
- PluginStore Author

-
- Posts: 1055
- Joined: Tue Jun 03, 2008 9:11 am
- Location: Sri Lanka
- Name: chrisglasier
- Operating system: Windows
- SketchUp version: 2017
- License type: Free/Make
- SketchUp use: architecture
- Level of SketchUp: Intermediate
-
by chrisglasier » Thu Jul 30, 2009 1:36 am
chrisglasier wrote:But I have to do more sleuthing ...
Here are the results so far: I deleted all loose geometry The total number of groups and components matches the javascript array indicating all have been passed to layer0 using Thomas' definition loop (thanks again for that). Each entity and any children in the expanded outliner view returns layer0 in entity info. But see this: Layer.png The selected column shows in its original layer colour and can be turned on and off with the original layer checkbox - yet the entity info shows layer0. And if I make the columns layer active and hide layer0, nothing is displayed or indicated in th outliner. The same is true for the remaining seemingly "unpurgable" layers. What think? Chris
With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.
-

chrisglasier
- PluginStore Author

-
- Posts: 1055
- Joined: Tue Jun 03, 2008 9:11 am
- Location: Sri Lanka
- Name: chrisglasier
- Operating system: Windows
- SketchUp version: 2017
- License type: Free/Make
- SketchUp use: architecture
- Level of SketchUp: Intermediate
-
by chrisglasier » Thu Jul 30, 2009 2:01 am
I just noticed that there are 7 section planes - Layer02.png the same number as the unpurgable layers. I don't know much about these. Perhaps it is just coincidental? Chris
With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.
-

chrisglasier
- PluginStore Author

-
- Posts: 1055
- Joined: Tue Jun 03, 2008 9:11 am
- Location: Sri Lanka
- Name: chrisglasier
- Operating system: Windows
- SketchUp version: 2017
- License type: Free/Make
- SketchUp use: architecture
- Level of SketchUp: Intermediate
-
by chrisglasier » Thu Jul 30, 2009 8:12 am
chrisglasier wrote:I just noticed that there are 7 section planes - Perhaps it is just coincidental?
Yes it is - all section planes are on layer0 (obvious to me now). Here is the current code: - Code: Select all
@dlg.add_action_callback("sceneLayersPurge") {|d, p|
model = Sketchup.active_model layers = model.layers entities = model.entities
array = [] a = 0
model.definitions.each { |d|
# Ignore Images and definitions with no instances next if d.image? || d.count_instances == 0 # Set Group/ComponentInstance to layer0 d.instances.each { |i|
if i.class == Sketchup::Group
name = i.name
end
if i.class == Sketchup::ComponentInstance
name = i.definition.name
end
original = i.layer.name
i.layer = layers[0]
array[a] = [name,original,i.layer.name] array[a] = array[a].join(",") a = a + 1 } }
layers.purge_unused
UI.show_inspector("Layers")
array = array.join(";")
cmd = "sceneLayersPurgeReceive('#{array}');" @dlg.execute_script (cmd) }
and here are samples from the js report showing name, original layer, final layer Layers034.png I'm running out of sleuthing ideas! Chris
With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.
-

chrisglasier
- PluginStore Author

-
- Posts: 1055
- Joined: Tue Jun 03, 2008 9:11 am
- Location: Sri Lanka
- Name: chrisglasier
- Operating system: Windows
- SketchUp version: 2017
- License type: Free/Make
- SketchUp use: architecture
- Level of SketchUp: Intermediate
-
by daiku » Thu Jul 30, 2009 2:22 pm
Have you tried manually making the problem layers invisible? If so, does anything disappear? Also, try manually deleting the layer. If it's truly empty, SU will quietly remove it. If it's not empty, SU will warn you, and ask where you want to move the things. CB.
-

daiku
- PluginStore Author

-
- Posts: 216
- Joined: Mon Nov 12, 2007 2:54 pm
- Location: Minneapolis
- Name: Clark Bremer
-
by Chris Fullmer » Thu Jul 30, 2009 5:37 pm
Can you supply the model you are working with? It might help figure it out faster.
Chris
-

Chris Fullmer
- SketchUp Team

-
- Posts: 6916
- Joined: Wed Nov 21, 2007 3:21 am
- Location: Boulder, CO
- Name: Chris Fullmer
- Operating system: Windows
- SketchUp version: 2013
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by chrisglasier » Fri Jul 31, 2009 4:10 am
Thanks all. I need to rethink this before asking people to venture further down a blind alley. I can reduce a Sketchup up model to two plain text lists. One lists components and groups and the other lists scenes. Both lists are turned into javascript multi-level arrays. But I don't want to wipe out any established relationships between components and layers, layers and scenes, scenes and styles and scenes and property settings. I thought I could do that by manipulating the model but I am thinking it is probably better to capture the data and regenerate the whole thing. If you are interested in why I want to do this please see the discussion in the Modelur thread. Thanks and regards Chris
With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.
-

chrisglasier
- PluginStore Author

-
- Posts: 1055
- Joined: Tue Jun 03, 2008 9:11 am
- Location: Sri Lanka
- Name: chrisglasier
- Operating system: Windows
- SketchUp version: 2017
- License type: Free/Make
- SketchUp use: architecture
- Level of SketchUp: Intermediate
-
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|