Remove dynamic attributes in ruby
-
**Hello everyone
edit:
To add a dynamic attribute to all instances in SketchUp, proceed as follows:
def add_attribute mod = Sketchup.active_model mod.definitions.each do |d| d.instances.each do |i| d.set_attribute 'dynamic_attributes', 'lola','10' i.set_attribute 'dynamic_attributes', 'lola','10' end end end add_attribute
To remove this attribute without affecting all the dictionary, you have to do like this:
def delete_attribute mod = Sketchup.active_model mod.definitions.each do |d| d.instances.each do |i| d.delete_attribute 'dynamic_attributes', 'lola' i.delete_attribute 'dynamic_attributes', 'lola' end end end delete_attribute
If I change the value of the attributes manually on SketchUp, the deletion will no longer be possible!
How to get around the problem?
Thank you**
-
-
**The opening of my TOPIC on the cleaning of dynamic components, motivated other developers to look into the problem.
The rb file is cripté thus impossible to read it.
In addition, this example does not answer the functions that I am currently looking for.
Thanks anyway juju**
-
**I did not take the time to re-read my code and I was wrong in my examples!
To add a dynamic attribute to a selected component:
def add_attribute_in_selection mod = Sketchup.active_model sel = mod.selection sel.each do |s| s.set_attribute 'dynamic_attributes', 'lola','1' end end add_attribute_in_selection
And to remove it:
def delete_attribute_in_selection mod = Sketchup.active_model sel = mod.selection sel.each do |s| s.delete_attribute 'dynamic_attributes', 'lola' end end delete_attribute_in_selection
My first example adds a dynamic attribute to all instances in SketchUp.
Sorry for this mistake for lack of attention!
ps: I still have not found how to remove a custom attribute created with SketchUp.**
-
David, why are using this crazy indentation ?
Ruby uses 2 space indents, and all code at the same level must be at the same indent:
def delete_attribute mod = Sketchup.active_model mod.definitions.each do |d| d.instances.each do |i| d.delete_attribute 'dynamic_attributes', 'lola' i.delete_attribute 'dynamic_attributes', 'lola' end end end
This way the beginning of blocks line up with the indent lines in code editors.
Advertisement