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:inredraw'
(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!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement