API problems with using dynamic components with scale tool


to reproduce my problem in SU2017 do the following:

  1. Open a new Sketchup model (with Chris or create a box and transform it to Component)
  2. Paste the code in the console
inst = Sketchup.active_model.entities.grep(Sketchup::ComponentInstance)[0]

# Add the ScaleTool behavior and enable only scaling along z axis
inst.definition.set_attribute 'dynamic_attributes', 'scaletool', "123"

# Change the z-length to 200
inst.definition.set_attribute 'dynamic_attributes', 'lenz', 200.to_f

# Trigger a redraw 
$dc_observers.get_latest_class.redraw_with_undo inst

Nothing happens. I can see with the Attribute Visualizer Plugin (or inst.definition.set_attribute 'dynamic_attributes', 'lenz') that the value of lenz is indeed set to 200, but the component isn’t scaled up, even after manually triggering a redraw…

When I edit the lenz value manually with the Dynamic Component Attributes window it does scale the component correctly.

What am I doing wrong?

I believe that when an instance’s geometric (len, scale, etc.) parameters will vary from the definition defaults, that you need to make the change to the instance’s “dynamic_attributes” dictionary. (Limiting scaling to certain axes should be okay in the definition’s dictionary.)

I tried using/adding

inst.set_attribute 'dynamic_attributes', 'scaletool', "123"
inst.set_attribute 'dynamic_attributes', 'lenz', 200.to_f

before, but that didn’t change any behavior. I tried different attributes, number formats, different components and orders, but I can’t get the component to change with using the API.

Did anyone successfully recreate the problem or is this on my end only?

No time. I’d suggest examining the “Dynamic Components Training” examples.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.