Using Component.hidden?


#1
ComponentDefinition.hidden?SketchUp 6.0+
The hidden method is used to determine if this component definition should be hidden on the component browser.

Returns:

status
true if the definition should be hidden, false if the definition should not be hidden
 componentdefinition = Sketchup.active_model.definitions[0]
 status = componentdefinition.hidden?

How do you set the component.hidden to true?
I tried component.hidden = true, but when I check component.hidden? it returns false.


#2

ComponentDefinition#hidden= is inherited from Drawingelement. This inheritance is somewhat quirky in several ways. First, a ComonentDefinition can not be drawn per-se, only instanced. Second, the hidden flag on a Drawingelement affects visiblity in the view, which is an entirely different concept than visibility in the Component Browser window. I suspect that the developers overrode #hidden? to query the browser visibility flag (an unfortunate naming, as they are different concepts) and forgot to override the #hidden= method.


#3

If you make component1 and component2 and then combine them into component3 [i.e. they are ‘nested’], then all three show in the Component-Browser.
Using:

Sketchup.active_model.definitions.each{|d| puts "#{d.name} = #{d.hidden?}" }

Will show each of the three definition’s ‘hidden?’ state as ‘false’.
If you do a Save_As on component3 to make an external SKP… and then import that into a new empty Model, then only component3 shows in the Components-Browser.
Although running that above code again will show the three definitions, it now shows ‘true’ as the ‘hidden?’ state of the two nested components…
Even if you choose to ‘Expand’ the listing in the Components-Browser the nested ones remain hidden?==true unless you actually insert one of those nested definitions [now pick-able under the Expanded listing], at which point its ‘hidden?’ state becomes ‘false’ - as it is used in the Model as a standalone definition in its own right.
It would have been better if instead of calling it definition.hidden? the early API writers had chosen something more obvious, like definition.is_only_nested? - but unfortunately they did not, so we have to make do with the oddly named hidden? test…
The definition.hidden? does not need a matching definition.hidden= because it is reporting a state that relies on information beyond the ability of the user to change - i.e. a definition is either is_only_nested?==true or it is ==false - it’s not ever going to be something you would ever want to affect by the API - any more than you do with other similar tests like definition.image? - which is either true or false, but which you’d never expect to convert some definition into an image - it just wouldn’t work ! Other tests that the user could influence like entity.hidden? can [and do] have a matching entity.hidden= method, simply because that is within there ability to affect - manually or in code…