Changing the dynamic components attributes using SU API
-
Hi All,
Can some one shed some light on what I am missing here to get this to work. What I am trying accomplish is very simple, I getting a component instance based on the name and change that component instance "lenz" value to a user specified value.
Following is my function that is supposed to do all the heavy lifting. I can see that the attribute dictionary is having right value in it but component instance is not updating in the Sketch Up UI. After lot of google searching I came across the $dc.observers and on using it I am getting the following message and error is outside the scope of my code.
setting lenght to 46' 11 1/8"
lenz value 46' 11 1/8"
Error: #<NoMethodError: undefined methodtransform!' for #<Sketchup::ComponentDefinition:0xa0ae90c>> (eval):465:in
redraw'
(eval):417:in `redraw_with_undo'#componentName ---> Name of the component #component_length ----> new length for the component instance. #aqx_get_component_instance ---> is a different fuction that return the instance based on #the name def self.aqx_set_component_length(componentName,component_length) componentInstance = aqx_get_component_instance(componentName) attribDictlist = componentInstance.attribute_dictionary "dynamic_attributes" puts("setting length to #{component_length}") attribDictlist["lenz"] = component_length value = componentInstance.get_attribute "dynamic_attributes", "lenz" puts("lenz value #{value}") # Redraw the DC using the $dc_observers global variable. $dc_observers.get_latest_class.redraw_with_undo(componentInstance) end
-
Regarding your errormessage, have you tried ?
component_definition.entities.transform_entities(tr, component_definition.entities.to_a)
It will affect instances of course..
-
Thanks for responding to my post. I figured out what the mistake was. Error is kind of misleading because in my code sample at the following code
@unknownuser said:
componentInstance = aqx_get_component_instance(componentName)
"ComponentInstance" is coming back as nil because I am looking for instance in a wrong way i.e. instead of looking for Definition name I was looking at the instance name which is empty string. After bunch of puts statements I finally figured out the issue and finally got it work.
-
Ok, I was focusing to much on the NoMethodError. Glad you sorted it out!
Advertisement