I’m having trouble setting the X Y Z position attributes of a selected DC.
I’m trying for example to set a Y position attribute to ‘5000’. or to refer to some other attribute…
get_attribute
works fine.
set_attribute
gives me a silent error - does nothing.
The outcome I eventually want is to change the formulas within the X Y Z of the selected DC to some other ones.
I’ve tried using .to_s, .to_f … doesn’t seem to help.
Am I referring to the wrong attributes? Wrong definition!?
(With setting LenX LenY LenZ I have no problems - it’s with the positions it doesn’t work).
def set_att_test
# begining of undo
model = Sketchup.active_model
model.start_operation("set_att_test")
# select only DCs
model.selection.grep(Sketchup::ComponentInstance) { |entity|
next unless entity.definition.attribute_dictionary('dynamic_attributes', false)
# apply the following on selected DCs
# get attribute
y_formula = entity.definition.get_attribute('dynamic_attributes', '_inst__y_formula')
puts y_formula #<= this works
entity.definition.set_attribute('dynamic_attributes', '_inst__y_formula', '5000') #<= does not work
entity.definition.set_attribute('dynamic_attributes', '_y_formula', '5000') #<= does not work
# redraw
dcs = $dc_observers.get_latest_class
dcs.redraw_with_undo(entity)
}
model.commit_operation # end of undo
end
set_att_test