Hi All,
I am facing a small problem with SketchUp.
if I have multiple models in a file. I select any one model and click on a toolbar icon, open a web dialog box and get some attribute values from Dynamic Components. When I change and update the values how to update the changes values for a selected model in a SketchUp file.
Here is my codes:
Get value code:
loadval = []
@proname = []
Sketchup.active_model.selection[0].definition.attribute_dictionaries["dynamic_attributes"].map{|dkey,dval|
if dkey == "lenx"
inches = dval.to_f
loadval.push(inches.to_cm)
elsif dkey == "leny"
inches = dval.to_f
loadval.push(inches.to_cm)
elsif dkey == "lenz"
inches = dval.to_f
loadval.push(inches.to_cm)
elsif dkey == "thickness"
inches = dval.to_f
loadval.push(inches.to_cm)
elsif dkey == "_name"
loadval.push(dval.to_s)
elsif dkey == "_product_name_options"
loadval.push(dval.to_s)
elsif dkey == "product_name"
@proname.push(dval.to_s)
end
}
js_command = "showDynamicValue("+loadval.to_s+','+@proname.to_s+")"
key.execute_script(js_command)
Update the values:
dialog.add_action_callback("changeapply"){|key, val|
puts val
val= val.split(",")
hashvalue = {}
sang = Sketchup.active_model.entities[0]
sang_def = sang.definition
puts sang_def.name
sang_def.set_attribute 'dynamic_attributes', '_lenx_formula', val[0]
sang_def.set_attribute 'dynamic_attributes', '_leny_formula', val[1]
sang_def.set_attribute 'dynamic_attributes', '_lenz_formula', val[2]
sang_def.set_attribute 'dynamic_attributes', 'thickness', val[3]
sang_def.set_attribute 'dynamic_attributes', 'product_name', val[4]
dcs = $dc_observers.get_latest_class
dcs.redraw_with_undo(sang)
}
Please help me to update values for the selected model.
Thanks,
Siva S