Recommendations for animation code?

just a momentary, possibly meaningless thought…

does the grp position need updating between each call to rotate?

john

1 Like

It works fine with transform!() or entities.transform_entities(), just not with move!().
And in either case, my puts statements prove the loop is called n times.

And, following your line of thought, since move!() is hiding what it has done from the undo stack, then it itself is hiding it’s previous machinations from itself, so then actually the method is really succeeding n times, but from the original position (or orientation whatever the transform case may be.)

So that would mean, we’d have to modify the applied transform each time through the loop.

Ie, for a rotational transform, @count * @degrees (or similar.)

1 Like

John, I don’t think the “move!” method is documented correctly in the API. It does not seem to behave like “transform!”, but instead like “transformation=” (but without edit…undo logging). Try:

  90.times do
    grp.move! rot * grp.transformation
    view.refresh
  end

You also asked:

I’m not sure what you mean. “move!” does not update the transformation. It replaces it.

2 Likes

yes,

rot * grp.transformation

works…

and does what I meant by updating our position of ‘grp’ i.e. updating the transform that move! applied previously…

I’ll need to see if it improves performance on those nasty models I;m testing against…

john

That’s the ticket! This was mentioned a few weeks ago, but I had forgotten.

And it has been documented in the API documentation-errors-suggestions.

2 Likes

move! seems to improve performance in my test models…

continuing on needing animation code advice…

now I’ve written some ‘animated’ test code to try and understand the whole transformation business…

it helping, but I still don’t get it…

I’m trying to sel.add the 4 sub-groups from inside the 2 parent groups that are 3 way flipped copies…

I only get two items from the intersection and they highlight in both parent groups?

the model >> test_selector_2.skp (110.7 KB)

and the test code…

model = Sketchup.active_model
defs  = model.definitions
ents  = model.active_entities
sel   = model.selection
title = model.title
selector = defs['selector'].instances[0]
sbb = selector.bounds
view = model.active_view
begin
model.start_operation('move')
defs.to_a.map do |defn|
  next if defn == selector
  defn.instances.map do |inst|
   next if inst.parent == model
 #  ptr = inst.parent.transformation
   itr = inst.transformation
   tr = itr # ptr * itr
   model.active_entities.transform_entities(tr, inst)
   view.refresh
sleep 0.2
   model.active_entities.transform_entities(tr, selector)
   sel.add(inst) if selector.bounds.intersect(inst.bounds).valid? 
   view.refresh
sleep 0.2
   model.active_entities.transform_entities(tr.inverse, inst)
   view.refresh
sleep 0.2
   model.active_entities.transform_entities(tr.inverse, selector)
   view.refresh
sleep 0.2
   sel.to_a
  end
end.flatten.compact.uniq
ensure model.commit_operation
end

I’ve been changing the transformation used, I’ve tried the ent.move!, ent.transform! and model.active_entities.transform_entities(tr, ent) but the only close results I ever get have this selection…

ptr = inst.parent.transformation give a no method error and I don’t fully understand why…

I can see it’s because the instance parent is it’s definition and not it’s containing group…

but how do I get the containing group transformation?

and how could I then use move! which currently creates strange results…

john

The API documentation for parent says that the return value is an “object”. I have noticed that this object is either the main model or the “definition” that the drawing element is in. Definitions (and the main model) don’t have associated transformations, instances do.

If there were a method for a parent instance, to be meaningful, its name should be pluralized (e.g. parent_instances) and it would return an array (or collection of some sort). Drawing elements can be reused and therefore can have multiple parent instances.

You can obtain a reference to a drawing element by selecting it with Sketchup’s select tool and performing a method call. If your search the entire entities collection for an object that is nested inside of a grouped object, you may encounter multiple occurrences of the same object inside of other entities.

That question gets asked alot. As a hobbiest animator, I use a pick helper tool to give me the fixed path to an entity that I want to animate, but usually I configure the model so that the entity being animated is a grouped object in the outer most entities collection.

That was recently responded to by:

I like that @Aerilius used the term “occurrences” in the description and code. Quite appropriate. I should have clicked “like” to the response, but I haven’t run the code and tested it out.

1 Like