Clean Dynamic Components
-
Hello to all.
The code below removes all the attributes of all Dynamic Components.
m=Sketchup.active_model;m.start_operation("unDC");m.definitions.each{|d|d.attribute_dictionaries.delete("dynamic_attributes") if d.attribute_dictionaries and d.attribute_dictionaries["dynamic_attributes"];d.instances.each{|i|i.attribute_dictionaries.delete("dynamic_attributes") if i.attribute_dictionaries and i.attribute_dictionaries["dynamic_attributes"]}};m.commit_operation
How to adapt the code to remove only the component attribute with the definition "Steve"?
The aim is that all the definitions starting with "Steve" for example copy "Steve # 1", "Steve # 2",
"Steve # 3" are concerned.Do not worry, I do not want nothing wrong with Steve, it's just an example.
-
Another research topic, how to remove "sub-components" masked?
This removal should cover only those components with the definition "Steve" "Steve# 1", Steve#2 "," Steve#3 "...
Thank you in advance for your help.
Cordially
David Barros
-
See this thread in the official "Ruby API" forums:
-
Thank you Dan for the link.
Here is the method to select all instances that begins with the definition "Steve":
n="Steve";m=Sketchup.active_model;s=m.selection;s.clear;m.definitions.each{|d|s.add d.instances if d.name=~/#{n}/}
Note, Steve can be replaced by any other name.
How to combine these two codes, to remove all the dynamic attributes of steve component?
m=Sketchup.active_model;m.start_operation("unDC");m.definitions.each{|d|d.attribute_dictionaries.delete("dynamic_attributes") if d.attribute_dictionaries and d.attribute_dictionaries["dynamic_attributes"];d.instances.each{|i|i.attribute_dictionaries.delete("dynamic_attributes") if i.attribute_dictionaries and i.attribute_dictionaries["dynamic_attributes"]}};m.commit_operation
n="Steve";m=Sketchup.active_model;s=m.selection;s.clear;m.definitions.each{|d|s.add d.instances if d.name=~/#{n}/}
Thank you in advance for your help.
David
-
The formula still more simplified:
m=Sketchup.active_model;s=m.selection;m.definitions.each{|d|s.add d.instances if d.name=~/#{"Steve"}/}
It activates all the instances that start with "Steve" in Sketchup.
How to select only the "Steve" in an active component?
The answer to this question is very important to me!
Thank you to all those who will want to help me.
David
-
Don't use the selection. Use an array. Then use one of the Array class' iteration methods.
-
Learn to use regular expression matching...
Dan has provided many useful links to basic Ruby usage...d.name=~/Steve/
matches 'Steve', 'Some Steve', 'Steve#1' etc
BUT not 'steve' etcd.name=~/[Ss]teve/
matches 'Steve', 'steve' etc
To limit the match to a start position use
d.name=~/^Steve/
matches 'Steve', 'Steve#1' etc
BUT not 'Some Steve' etcTo limit the match to an and position use
d.name=~/Steve$/
matches 'Steve', 'Some Steve' etc
BUT not 'Steve#1' etcTo limit it to an exact match use
d.name=~/^Steve$/
matches 'Steve' only, nothing else
note that is actually equivalent to
d.name=="Steve"
Advertisement