module SUForum
module FaceVisibility
extend self
VERSION ||= "0.0.3"
MENU ||= "View"
#based on: https://community.sketchucation.com/post/1323194
def tigs_facevisibility()
model=Sketchup.active_model
ants=model.active_entities
unless @visible and @visible[0] ### hide and remember
@visible=[]
ants.each{|e|@visible << e if e.is_a? Sketchup::Face and e.visible?}
@visible.each{|e|e.visible=false} if @visible[0]
return 'invisible'
else ### show and forget
@visible.each{|e|e.visible=true if e.valid?}
@visible=[]
return 'visible'
end
end
unless defined?(@ui_loaded)
add_separator_to_menu(MENU)
menu = UI.menu(MENU).add_item("Toggle Faces") { tigs_facevisibility() }
@ui_loaded = true
end
end
end
And this gathers an array of ‘entity’s’:
def a_a( entity )
a = []
entity.each { |e|
if e.is_a?( Sketchup::Face )
a << e
elsif e.is_a?( Sketchup::ComponentInstance ) || e.is_a?( Sketchup::Group )
a.concat( a_a( e.definition.entities ))
end
}
return a
end
puts a_a( Sketchup.active_model.selection )
The problem seems to me that the method of TIG doesn’t respond to this last method, because it responds to a collection of entities but does not to an array of entities such as the last method returns.
Are there any experienced coders who could give me a clue as to how I could gather this collection of entities within a set of nested groups, to which the first mentioned method would respond.
module SUForum
module FaceVisibility
extend self
VERSION ||= "0.0.4"
MENU ||= "View"
#based on: https://community.sketchucation.com/post/1323194
def tigs_facevisibility()
model = Sketchup.active_model
selection = model.selection
faces = collect_faces( selection )
model.start_operation("Toggle Faces", false)
unless @visible and @visible[0] ### hide and remember
@visible=[]
faces.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
model.commit_operation
puts state
end
def collect_faces( ents )
a = []
ents.each { |e|
if e.is_a?( Sketchup::Face )
a << e
elsif e.is_a?( Sketchup::ComponentInstance ) || e.is_a?( Sketchup::Group )
a.concat( collect_faces( e.definition.entities ))
end
}
a
end
unless defined?(@ui_loaded)
add_separator_to_menu(MENU)
menu = UI.menu(MENU).add_item("Toggle Faces") { tigs_facevisibility() }
@ui_loaded = true
end
end
end
We so far managed to hide faces, creating a wire frame structure locally. So a difficult object of choice could be selected. Next we would like to hide all, until the object is placed in its new position, as the OP is asking here: