I have a number of dynamic components all with a custom attribute name Y10_PartNumber. I would like to have a ruby script that would take all the instances and assign a sequential number to them. For example if there 30 different components or instances I would like to assign numbers 1-30 to that Y10_PartNumber attribute in the dynamic component. Any help is greatly appreciated!
Hey, try this:
model = Sketchup.active_model
sel = model.selection
dcs = sel.grep(Sketchup::Group).concat(sel.grep(Sketchup::ComponentInstance))
num = 1
dcs.each do |dc|
if dc.attribute_dictionary( 'dynamic_attributes', 'Y10_PartNumber')
dc.set_attribute( 'dynamic_attributes', 'y10_partnumber', num)
num += 1
end
end
Worked great! Thanks for taking the time to help me out on this!
1 Like
Glad it worked for you.