Change Dynamic Attribute value for selected model using Ruby

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.

image

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

Wrong category. This belongs in Ruby API. There are already examples.
https://forums.sketchup.com/search?q=dynamic%20category%3A13

Thanks @DanRathbun

Hi @DanRathbun,

I have one more doubts if any possible to disable the “Dynamic Components” menu from when right click on components. Please see the image I have marked the menu.

Please let know if have any solutions.

Thanks,
Siva S

NO. This is native feature and cannot be disabled.


After disabling or enabling you have to restart SU to take effect.
Keep in mind You may get an other strange behavior with the components and other extension in SU, beside the message above…

He said the DC context menu, not the whole DC extension. He needs the DC functionality.

Yes, you may right. It was not entirely clear, but with this method the menu disappears. Isn’t it ? :slight_smile:
But I would definitely not recommend to disable DC !

I am correct. He is using DCs and needs the extension active.

He is attempting to replace the native DC interfaces with his own. This is likely to anger users.