Animating movement of one dynamic component by clicking (onClick) on another

Hi -

Can anyone explain (preferably with scripting examples) how I might control one component by clicking on another? For example: make a simple model of car move from one position to another by clicking on a ‘button’ component. Do these to components need to be ‘nested’, or have a ‘parent & child’ relation? I’ve found related posts on the forum, but nothing that explains in simple enough terms how I might do this. I am a very long term Sketchup user, but very new to dynamic components.

Thanks in advance!

In short, yes,they would have to be in the same context.
This context preferably would be a component, with an attribute (DistanceX, for instance) at the highest level. This attribute can be changed by the ‘button’ components ‘onclick’ behavior and the moving object ( the car) can derive its position from it.
That said, if the context is the Model, you would have to add another component with a DistanceX attribute, since you cannot add DC attributes to the Model directly. The button components can alter the new component, but you would need a ‘redraw’ on the car to implement the changes.

Thanks for taking the time MikeWayzovski - unfortunately your reply was a bit jargon heavy for my feeble mind… I’m not really any the wiser.

Within any model, you can reference any group or component by its Component Attributes name. So you can create a car and a button or more, then link them
So the first context, Jack is referring to is level one, the model, in other words in answer to your question,
actions are triggered on the same level
All onClick functions must be on the same level of nesting, otherwise the parent or closest level to it, will always active before any lower one does.
you can effect other higher or nested parts by having an attribute value pass through the levels

It is easier to initially place your objects in a group or component so one can click in the references like with an excel spreadsheet, rather than manually writing them out, then explode the group afterwards if you want. But generally such container (group or component) are used permanently.

The attached files:
example1.skp (37.6 KB)

example one: is two buttons, each reference the car object attributes, one to add a distance, the other to minus the same

example2.skp (29.1 KB)

example two: is same but a extra onClick action on the right arrow, to set the size of the cars lenX, an attribute carSize reports this change, however although the car lenX changes, the carSize attribute does not update, unless a redraw via right click menu is made on the right arrow control, thus explaining Jack’s other concern

So some points, attribute references are not case sensitive, as you will note in the “set” function.
extra actions can be placed after a semicolon.

Please feel free to continue with your questions after viewing and experimenting with the said
will then attach further examples

1 Like

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