Hello, everyone.
I’ve encountered an issue with setting an attribute value.
Originally, the attribute value is set as a formula. I’m trying to replace the formula with a static value.
You can see the result in the video at the following link.
Here is my code.
def name_change(guid, name)
model = Sketchup.active_model
view = model.active_view
component_definition = model.definitions.find { |e| e.guid == guid }
if component_definition
if component_definition.get_attribute("dynamic_attributes", "cut")
parent_component = component_definition.parent
puts "tmp 1 = #{component_definition.class}"
component_definition.delete_attribute("dynamic_attributes", "l1_component_102_article")
$dc_observers.get_latest_class.redraw_with_undo(component_definition)
else
component_definition.entities.each do |entity|
if entity.is_a?(Sketchup::ComponentInstance)
if entity.get_attribute("dynamic_attributes", "cut")
parent_component1 = entity.parent
SKETCHUP_CONSOLE.clear
puts "tmp 2 = #{entity.class}"
entity.set_attribute("dynamic_attributes", "l1_component_102_article", name)
entity.definition.invalidate_bounds
puts "attribute before = #{entity.get_attribute("dynamic_attributes", "l1_component_102_article", '')}"
model.commit_operation
puts "attribute after = #{entity.get_attribute("dynamic_attributes", "l1_component_102_article", '')}"
puts "oki "
end
end
end
end
end
end