I am trying to change section_plane settings from activate to deactivate or the other way from different scene.
Here are my code
model = Sketchup.active_model
# With three params, it shows all text boxes:
prompts = ["What is the building name?", "When was this building built?"]
defaults = ["Enter name", "Example: 1972"]
input = UI.inputbox(prompts, defaults, "Tell me about This building.")
pages = model.pages
pages.each {|page|
if page.name.to_i<input[1].to_i
entities = Sketchup.active_model.entities
puts "#{page.name} is smaller than #{input[1]}"
all_groups = entities.grep(Sketchup::Group)
my_group = all_groups.find { |g| g.name == input[0] } # nil if not found
my_entities = my_group.entities
section_plane = my_entities.grep(Sketchup::SectionPlane).first
puts "#{section_plane}"
section_plane.activate if my_group
#page.update
elsif page.name.to_i>=input[1].to_i
entities = Sketchup.active_model.entities
puts "#{page.name} is equal or greater than #{input[1]}"
all_groups = entities.grep(Sketchup::Group)
my_group = all_groups.find { |g| g.name == input[0] } # nil if not found
my_group.entities.active_section_plane= nil if my_group
#page.update
else
break
end
#page.update
UI.messagebox page}
this code works perfectly fine to change section plane settings without the page.update function. However, when I try to use page.update. I think the command my_group.entities.active_section_plane= nil if my_group overwrites all of the section_plane settings which should just overwrite the section_plane it belongs to.
Moreover, I am wondering how section_plane is stored? Because we could find the section_plane under its parent group. However, it interact with pages somehow. Is there a way to find section_plane in pages entities?
It might be the break keyword ? This would break out of the iteration block.
I would instead suggest that you should use the keyword next so as to continue the iteration with the next page in the pages collection.
The Sketchup::Page class does not have an entities collection. A Scene Page is a view of the model with specific settings set a certain way. A scene page is not a geometric object.
A section plane is a Sketchup::Drawingelement subclass object, just as a dimension is, etc. So it can be a member of a Sketchup::Entities collection (of a group, component or the model itself.)
Not quite correct. It does not really overwrite all. Setting the active section plane for an entities object to nil, only applies to that specific entities object. But, each entities object can have multiple section planes, yet only one section plane can be active within each entities collection at a time.
So setting an entities collection’s active_section_plane to nil will switch off ALL of that entities collection’s section planes. Setting an entities collection’s active section plane to a section plane different from the previous setting, deactivates the previous section plane and actives the latter one.
However, a page update saves the settings for ALL of the entities objects that have section planes.
The scene page should also have the use_section_planes= true flag set.