Redraw should work on groups or components. Can you post your code?
EDIT: Group attributes are kept in the definition instance, where components have attributes at the instance and definition level, this is likely probably not your issue… You have to set the group attribute at the definition instance.
EDIT2: I had it backwards, corrected above. Thanks @DanRathbun!
Dynamic groups must be nested within a dynamic component. I.e., the dynamic group cannot be the progenitor dynamic object.
Secondly, … if there is only one instance of a dynamic component, then all dynamic attributes will be on the definition and the instance will use it’s definition’s attributes.
The only way I was able to do this was to add a formula attribute to the component instance and definition, and then remove it from the attribute dictionary.
I also had to do a redraw before removing it from the dictionary.
DYDICT ||= 'dynamic_attributes'
model = Sketchup.active_model
sel = model.selection
# Removes an attribute from a dictionary.
# @param [AttributeDictionary] dictionary - The dictionary to remove attribute.
# @param [Array<String>] attributes - Array of attributes to remove.
def self.remove_dynamic_attribute(dict, attributes = [])
return if attributes.empty?
attributes.each do |attribute|
dict&.delete_key(attribute)
end
end
def self.set_instance_or_definition_attributes(instance, key, value)
definition = instance.definition
formula = "_#{key}_formula"
instance.set_attribute(DYDICT, formula, value)
definition.set_attribute(DYDICT, formula, value)
$dc_observers.get_latest_class.redraw_with_undo(instance)
dict = instance.attribute_dictionary(DYDICT) # instance dictionary
definition_dict = definition.attribute_dictionary(DYDICT) # definition dictionary
remove_dynamic_attribute(dict, [formula, "_#{key}_error"])
remove_dynamic_attribute(definition_dict, [formula, "_#{key}_error"])
end
def self.set_instance_attributes(entities)
entities.grep(Sketchup::ComponentInstance).concat(entities.grep(Sketchup::Group)).each do |instance|
key = 'lenx'
value = (800 / 10).to_s
set_instance_or_definition_attributes(instance, key, value)
end
rescue StandardError => error
puts error.backtrace
raise
end
set_instance_attributes(sel)