I’m trying to understand what can be done with Section Styles, mainly with a view to automate the update of section style’s parameters.
As I understand from the RhinoCommon documentation, it is possible to create a SectionStyle object, that can then receive properties.
I get into trouble when trying to apply this SectionStyle to a layer. I’m trying to use the SetCustomSectionStyle method, but I think I’m missing something here.
What is the right way to do this? Thank you,
import Rhino
import scriptcontext as sc
# Creating the Section Style
section_style = Rhino.DocObjects.SectionStyle()
section_style.Name = "TestSectionStyle"
section_style.BoundaryVisible = False
# Applying the SectionStyle to a layer
layer = sc.doc.Layers.FindName("Layer 01")
layer.SetCustomSectionStyle(section_style)
I would ensure that you’re duplicating the attributes, setting the attribution source and then calling the doc.Objects.ModifyAttributes. This will sure ensure the attribute source actually gets updated to use your layer changes. The object properties panel should also show those selected objects as having their Section Style source as By Layer once updated.
I’m not sure I understand your question. I thought once I updated the layer with a custom SectionStyle, it would apply this newly received SectionStyle to all objects in that layer. However, for now, the layer’s section style is not even modified.
For example, in the first code snippet I posted, I set the SectionStyle Boundary Visible to False, and when I run the script, the “Layer 01” still has a “None” SectionStyle applied, and when I click on it the Boundary visibility is set to True.
It is the first time I’m handling stuff using RhinoCommon. Usually I only use rhinoscriptsyntax, so I may be missing some knowledge about what is happening here.
You need to make sure the layer section style changes are being applied to layer correctly. That process should go like this.
var new_settings = new Layer();
new_settings.CopyAttributesFrom(selected_layer);
new_settings.SetCustomSectionStyle(new_section_style);
doc.Layers.Modify(new_settings, selected_layer.Id, true);
Then make sure the objects you expect to be affected have their section sources set to “By Layer” as mentioned in my previous post.