Bonjour à tous
When i make copy of my component, i change the name in the title.
All the formulas containing the old name turn in red.
Is there a way to change the name into a single operation ?
Thanks
Bonjour à tous
When i make copy of my component, i change the name in the title.
All the formulas containing the old name turn in red.
Is there a way to change the name into a single operation ?
Thanks
This is a very specialized operation for which I don’t think there exist tools.
You could manually change each attribute using the dynamic component editor or an attribute editor/inspector extension.
If you want to do it faster, you can do such specialized operations using SketchUp’s scripting API. This could be a start (untested):
def replace_attribute_values(entity, dict_name, pattern, replacement)
entity.attribute_dictionay[dict_name].each{ |key, value|
if value[pattern]
new_value = value.gsub(pattern, replacement)
entity.set_attribute(dict_name, key, new_value)
end
}
end
selected_component = Sketchup.active_model.selection.first
dict_name = "dynamic_attributes"
old_name = "old_name"
new_name = "new_name" # selected_component.name or selected_component.definition.name
replace_attribute_values(selected_component, dict_name, /\b#{old_name}\b/, new_name)
Also consider that many dynamic attributes are saved in the component definition, not in the component instance.
Be aware that batch operations not only do more work faster, but can also create more damage faster. Verify if the pattern that you want to replace is correctly replaced, and nothing else is replaced that you don’t want to change. Dynamic component equations can become invalid!
Thanks
It seems difficult for me. I have to begin to understand how to use sketchup API.
Are you aware you can change all the references to the title name with the generic term ‘parent’ (quote for emphasis only) before creating and renaming copies? Copy the text …parent…, double click the reference and paste. Then whatever the parent title is, it does not matter.
Wouldn’t it be needing an redraw at the end?
$dc_observers.get_latest_class.redraw_with_undo(inst)
Thank you very much.