sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Changing the dynamic components attributes using SU API

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 685 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V Offline
      vtikka
      last edited by

      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 method transform!' 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
      
      
      1 Reply Last reply Reply Quote 0
      • jolranJ Offline
        jolran
        last edited by

        Regarding your errormessage, have you tried ?

        component_definition.entities.transform_entities(tr, component_definition.entities.to_a)

        It will affect instances of course..

        1 Reply Last reply Reply Quote 0
        • V Offline
          vtikka
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • jolranJ Offline
            jolran
            last edited by

            Ok, I was focusing to much on the NoMethodError. Glad you sorted it out!

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement