Very interesting. My minds eye sees a toolbar full of tools to hide and show folders. Meanwhile I’m studying to find out more about iterative and recurring functions to only hide the necessary folders to isolate a layer, oops tag.
This doesn’t work in Sketchup 2023. Meanwhile this:
` # Method to find the hierarchy path to the active folder
def find_hierarchy_path(active_folder)
path = []
current_folder = active_folder
while current_folder
path.unshift(current_folder)
current_folder = current_folder.folder if current_folder.respond_to?(:folder)
end
path
end`
…is sheer poetry.
Very similar to Dezmo’s method:
def parents(l_f)
parents = []
while l_f.folder
parents<<l_f.folder
l_f = l_f.folder
end
parents
end
What I don’t understand though is the method active_folder in your method. Where does this come from? This method does exactly the same:
#parents_path(Sketchup.active_model.layers["Tag1"])
def parents_path(active_layer)
path = []
current_folder = active_layer
while current_folder
path.unshift(current_folder)
current_folder = current_folder.folder if current_folder.respond_to?(:folder)
end
path
end
parents_path(Sketchup.active_model.layers["Tag1"])
#works
So what is this active_folder method? Is it just a synonym for active_layer, or has it got a bug? Doing this does return the active folders :
#parents_path(Sketchup.active_model.layers["Tag1"])
def parents_path(active_folder)
path = []
current_folder = active_layer.folder
while current_folder
path.unshift(current_folder)
current_folder = current_folder.folder if current_folder.respond_to?(:folder)
end
path
end
parents_path(Sketchup.active_model.layers["Tag1"])
#works
active_folder is a parameter, not a method. active_model and active_layer are methods. active_folder is not a synonym for active_layer. I think it was long-winded and poor form on my part.
I think it is interesting because of the following reason. When you can isolate the parent folder of the active layer, one might find a way to hide the hyrarchy path, without hiding anything (neither layers nor folders) within the parent folder. When you extend your method with the following, the parent folder isn’t selected:
#parents_path(Sketchup.active_model.layers["Tag1"])
def parents_path(active_folder)
path = []
folder_parent = active_folder.folder
current_folder = folder_parent.folder
while current_folder
path.unshift(current_folder)
current_folder = current_folder.folder if current_folder.respond_to?(:folder)
end
path
end
parents_path(Sketchup.active_model.layers["Tag1"])#works
The array of folders in the parent folder one can hide like this:
module SUForum
module FolderVisibility
extend self
VERSION ||= "0.0.91"
MENU ||= "View"
def hide
model = Sketchup.active_model
active_folder = model.active_layer.folder
folders_below = active_folder.folders
if folders_below.any? {|l| l.visible? == true }
folders_below.each {|l| l.visible = false }
end
end
if !defined?(@ui_loaded)
add_separator_to_menu(MENU)
menu = UI.menu(MENU).add_submenu("Folder Visibility")
menu.add_item("Hide") { hide() }
menu.add_item("Show") { show() }
@ui_loaded = true
end
end
end
If we could now separately hide the arrays of folders in the parents path, we’d have two more methods, namely 'Hide folders above" and 'Hide folders below".
I don’t think you can hide any folder that is a parent of the current tag. You’d get the “You can not hide the current tag” warning, or, I guess, the current tag would be reset to the default (layer 0). I think you could hide any sibling of the parent, any children of those, and any sibling and their children in the active path, or any children of the active layer.
One could drill their nose down into this, but what’s the big picture?
I think it’s interesting, say when one has a small element hidden within a model, deep down in the folders hyrarchy, to be able to instantly find it by hidding the folders above. I realise this is all very experimental. And maybe if you would acheive to hide al siblings ‘above’ one would still have to adopt to a certain workflow.
Similarly for instance Claris Cad used to have the option to hide layers above, albeit in 2D. I guess in a way you can compare it with that.
Meanwhile I’m trying to figure out how to find all the parent_folders recursively, as an array x times the parent folder. Next one could maybe select and hide those siblings.
Here’s some more speudo coding to select parent folders recursively, I haven’t tested it yet:
def folder_n
n=[1..1/0]
while
folder_n == folder_n.folder
end
end
Not that you aren’t aware of this, but you can find components by hiding similar components/groups or the rest of the model (in Model → Info → Components) using the Outliner.
Or you can use Select All, and Deselect the Tag you want to remain visible. Even if you deselect the Untagged to avoid the warning prompt this is simpler than selecting an active layer and then going into the View → Folder Visibility → Hide (and simpler still considering not including moving the pencil selection back to Untagged, or whichever other layer, to avoid drawing on anything but the untagged layer).
I think you need everything But the active layer. You can’t hide that path. Everything Else.
It seems that Select All, Deselect as needed is the way to go. For example, Select All, Deselect child folder.
The method of hiding folers and/or tags above or below has proven to be a very workable method. Albeit limiting, it provides a very pleasant structure to organise your model. Which helps you understand the stucture of the application.
I just don’t understand how to gather the simblings of this array of folders, that’s why I’m trying to work around it. Just give me some time
So what tools have we gathered so far?
module SUForum
module FolderVisibility
extend self
VERSION ||= "0.1.0"
MENU ||= "View"
def all_folders(folders = [], root_folder = Sketchup.active_model.layers)
root_folder.each_folder do |folder|
folders << folder
all_folders(folders, folder)
end
folders
end
def toggle_tags(state)
model = Sketchup.active_model
active_tag = model.active_layer
model.layers.each { |tag| tag.visible = state unless tag == active_tag }
end
def toggle(state)
all_folders.each { |f| f.visible = state }
end
unless defined?(@ui_loaded)
add_separator_to_menu(MENU)
menu = UI.menu(MENU).add_submenu("Folder Visibility")
menu.add_item("Hide Folders") { toggle(false) }
menu.add_item("Show Folders") { toggle(true) }
menu.add_item("Hide Tags") { toggle_tags(false) }
menu.add_item("Show Tags") { toggle_tags(true) }
@ui_loaded = true
end
end
end
@3DxJFD...this is simpler than selecting an active layer and then going into the View → Folder Visibility → Hide (and simpler still considering not including moving the pencil selection back to Untagged, or whichever other layer, to avoid drawing on anything but the untagged layer).
Of course all those tools would be much more convenient to have in a tool palette. Maybe something for later.
@dezmo Your fix to tigs_facevisibility method also works very nicely with your def all_folders over here. Now this method makes much more sense to me.
@3DxJFD Wouldn’t it be nice to also be able to toggle tags the same way?
module SUForum
module FolderVisibility
extend self
VERSION ||= "0.2.0"
MENU ||= "View"
def all_folders(folders = [], root_folder = Sketchup.active_model.layers)
root_folder.each_folder do |folder|
folders << folder
all_folders(folders, folder)
end
folders
end
def toggle_tags(state)
model = Sketchup.active_model
active_tag = model.active_layer
model.layers.each { |tag| tag.visible = state unless tag == active_tag }
end
#based on: https://community.sketchucation.com/post/1323194
def toggle_folders()
unless @visible and @visible[0] ### hide and remember
@visible=[]
all_folders.each{|e| @visible << e if e.visible?}
@visible.each{ |e| e.visible=false } if @visible[0]
state = @visible[0] ? 'invisible' : 'no previous selection'
else ### show and forget
@visible.each{ |e| e.visible=true if e.valid? }
@visible = []
state = 'visible'
end
puts state
end
unless defined?(@ui_loaded)
add_separator_to_menu(MENU)
menu = UI.menu(MENU).add_item("Toggle Folders") { toggle_folders() }
@ui_loaded = true
end
end
end
If you try to hide the parent folder of the active layer, e.g:: Sketchup.active_model.layers["Tag"].folder.visible = false
It will return false, but silentlyfail to set visibility to false.
But maybe that’s not only due to running ruby.
I can actually hide the folder of the active tag in the UI. Select a tag in a hidden folder, which unhides the parent folder. Then undo once, and the folder gets hidden again.
I don’t know. My brain is still looping on why I’d want to move the pencil from Untagged to make anything else the active layer.
I noticed that when the visibility is toggled (normally) and then “Toggle Folders” is selected from the View Menu, toggling doesn’t occur. On the second and subsequent attempts it works until toggled again in the Tags Panel. So, something’s off when the state is changed in Tags Panel…
I was thinking about visibility… setting Component/Group Editing to “Hide” in “Fade rest of model” does something like what you’re trying to achieve. I think it’s better because you don’t have to remember to move the pencil back to Untagged. It has the advantage of selecting the Group/Component in Outliner vs. Tags, which don’t select tagged Groups/Components (without going into a dropdown menu). The thing here is that Fade rest of model doesn’t hide by Tag or Toggle visibility in the Outliner. But toggling visibility by attributes (or in the Outliner itself) on Groups or Components does toggle visibility in the Outliner. Anyway, I think toggling visibility by Group/Component is better… but what visibility setting is toggling when Fade rest of model is used?
The most likely scenario would be inserting multiple components which you wish to be assigned to use a certain tag. It is tedious to insert many using “Untagged” then have to select them all and reassigned them with the Entity Info Tag picklist.