Transform multiple entities

The API example for Entities.transform_entities does not work.

The command say the entities to be transformed can be
“An array or series of entities to transform”

But the syntax:
entities.transform_entities(transform, ent1, ent2, ent3)
returns errors.

Are parens correct? Must multiple entities be in an array?
It works without parens but only with a single entity.

Meanwhile I’m transforming one entity at a time.

It should work with a list OR with an Array*.
I just tested it and it does !

But you can just add a pair of [ ] around the ‘list’ of items to make an Array

entities.transform_entities( transform, [ ent1, ent2, ent3 ] )

The use of the array makes it easier if you are moving say a selection [array = selection.to_a] or collecting just some things e.g. array = selection.grep(Sketchup::Group) - to just transform selected groups…

It is good practice to parenthesize arguments, do NOT have a space between the method and the opening (

The listed-entities/Array-entities must all be in the same ‘entities’ context, and must also be ‘valid?’.

What kind of Transformation are you using ?
What kind of ‘Entities’ are you listing ?

Thanks. I’m drawing clines to represent the bounding box of a component definition, then transforming them to position of a given component instance.

The brackets and NO space before ( are key. It’s just frustrating that the API has so many syntax errors. It’s easy to copy the samples to test them, but the author never bothered to do it.

The particular example of transform_entities has multiple errors and undefined variables.

He possibly did, on most, if you start at the top it often has the context variables, but there’s no mention of them after that…
also, if somethings been added in a later version by someone else, the variables may differ…
you need to have a good trawl around the SketchUcation Developers Forum to see the historical context…
and Trimble need to fix the API doc…

Been complaining about this for years. Ever since I came to SketchUp in v7.
There was an “New API Errors” thread started at SketchUcation back in those days (2009.) (And there was one that even preceded that covering an older API website.)

Some of those errors have been fixed.

1 Like