component_def = Sketchup.active_model.selection[0].definition
custom_attr = {
"_formatversion" => 1.0,
"_has_movetool_behaviors" => 0.0,
"_hasbehaviors" => 1.0,
"_inst___iscollapsed_access" => nil,
"_inst___iscollapsed_formlabel" => nil,
"_inst___iscollapsed_formula" => nil,
"_inst___iscollapsed_formulaunits" => nil,
"_inst___iscollapsed_label" => nil,
"_inst___iscollapsed_options" => nil,
"_inst___iscollapsed_units" => nil,
"_inst__copies_access" => nil,
"_inst__copies_formlabel" => nil,
"_inst__copies_formula" => "1+2",
"_inst__copies_formulaunits" => nil,
"_inst__copies_label" => "Copies",
"_inst__copies_options" => nil,
"_inst__copies_units" => nil,
"_inst__iscollapsed" => "false",
"_inst_copies" => 0.5333333333333258,
"_lastmodified" => "2017-10-12 23:54",
"_lengthunits" => "CENTIMETERS",
"_name" => "Component#2",
}
custom_attr.each { |k, v|
component_def.set_attribute("dynamic_attributes", k, v)
}
when i set copy attribute, but i can’t see the “Copies” attribute
You are missing some/adding the wrong…:
check with attribute inspector what attributes are being used when adding an attribute in DC.
i set the copy attribute as the “inspector attributes” tools but the "Copies " still not appear.
UI.menu("Plugins").add_item("step3") do
component_def = Sketchup.active_model.selection[0].definition
component_attr = component_def.attribute_dictionaries["dynamic_attributes"]
custom_attr = {
"_formatversion" => 1,
"_has_movetool_behaviors" => 0,
"_lastmodified" => "2017-10-14 15:46",
"_lengthunits" => "CENTIMETERS",
"_hasbehaviors" => 1,
"_inst___iscollapsed_access" => "null",
"_inst___iscollapsed_formlabel" => "null",
"_inst___iscollapsed_formula" => "null",
"_inst___iscollapsed_formulaunits" => "null",
"_inst___iscollapsed_label" => "null",
"_inst___iscollapsed_options" => "null",
"_inst___iscollapsed_units" => "null",
"_inst__copies_access" => "null",
"_inst__copies_formlabel" => "null",
"_inst__copies_formula" => "1+2",
"_inst__copies_formulaunits" => "null",
"_inst__copies_label" => "Copies",
"_inst__copies_options" => "null",
"_inst__copies_units" => "null",
"_inst__iscollapsed" => "false",
"_inst_copies" => 0.5333333333333324,
"_lastmodified" => "2017-10-14 15:59",
"_lengthunits" => "CENTIMETERS",
"_name" => "Component#2",
}
custom_attr.each { |k, v|
component_def.set_attribute("dynamic_attributes", k, v)
}
end
Try to first make component. Only add copies attributes with formula in Dynamic Components Attributes dialog, you would get these attributes in the dynamic_library :
Attributes
"_copies_error" => "1+2",
"_copies_formula" => "1+2",
"_copies_label" => "Copies",
"_formatversion" => 1,
"_has_movetool_behaviors" => 0,
"_hasbehaviors" => 1,
"_inst__copies_access" => "null",
"_inst__copies_formlabel" => "null",
"_inst__copies_formula" => "1+2",
"_inst__copies_formulaunits" => "null",
"_inst__copies_label" => "Copies",
"_inst__copies_options" => "null",
"_inst__copies_units" => "null",
"_inst__copy_access" => "null",
"_inst__copy_formlabel" => "null",
"_inst__copy_formula" => "null",
"_inst__copy_formulaunits" => "null",
"_inst__copy_label" => "null",
"_inst__copy_options" => "null",
"_inst__copy_units" => "null",
"_inst_copies" => 3,
"_inst_copy" => 3,
"_lastmodified" => "2017-10-14 15:00",
"_lengthunits" => "CENTIMETERS",
"_name" => "MyNamedComponent",
Try it with a newly made component. To work properly, you would have to redraw the DC, first get the proper observer, then do a redraw on selection.
sel=Sketchup.active_model.selection[0]
dcs = $dc_observers.get_latest_class
dcs.redraw_with_undo(sel)
system
Closed
January 14, 2018, 5:39am
5
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.