How to set x,y dimensions for component?

I wante to add some tree textures around my model to create forest. I decided to add the texture to cylinders or pipes 10m high.

Normally when the cylinder is not in component and I need to copy it I duplicate it using move tool and move it up +20m. Then I rescale every circle of the cylinder down by 0.98. Then I move the cylinder down -20m. This way I copy the cylinders to be a bit smaller than the previous one. But now I decided to add the cylinder to component.

When it is in component, I cannot rescale it as in the previous example. If I would rescale so the height of the cylinder would be samaller (0.98*10). Hence the trees would be smaller. This is not what I want.

So I need to set the dimensions on horizontal plane to scale it, excluding z axis. Any idea how to do it?

Create a transform for scaling (i.e., scale = Geom::Transformation.scaling(0.98,0.98, 1)) and apply it to the instance of the component you’ve created (i.e., componentinstance.transform!(scale))

1 Like

IDK how to define componentinstance. Is it possible to start with selection? There are two components having the same definition name.

My code:

ss = Sketchup.active_model.selection;
scale = Geom::Transformation.scaling(0.98,0.98, 0)

That’s all I have

Assuming that just one instance is selected, use…


The transformation only affects the one instance.
Any other instances of the same definition are unaffected.

If you want to actually change the entire ‘contents’ of a component [or group] you can a similar transformation thus:

definition.entities(scale, definition.entities.to_a)

This will change the definition itself, so that all of its instances will then change to match…
Where you have set: definition=componentinstance.definition

1 Like

I tried this:

comp = ss.grep(Sketchup::ComponentInstance);

Error: ArgumentError: (eval):2536:in `transform!': wrong number of values in array

That was just try. Why did not work?

In your example comp will be an array.

So logically I’d rename it comps and then iterate its array…
comps = ss.grep(Sketchup::ComponentInstance)
comps.each{|comp| comp.transform!(scale) }

1 Like

It’s strange I had 3-4 tubes and now I see only 2. I cannot find out where the component tube disappeared.

This is what I see:

When I double click on the polygon it disappeared.

Also I did not want to change the content of the component but this changed it (erased the content) so both components disappeared.

Note: In the undo menu there is: Undo Move. Not Undo scale.

All actions result to the same behaviour.

I upload the sketchup test.skp (88.9 KB)

@jimhami42 Could you please correct your answer?

not 0.98, 0,98, 0 but
scale = Geom::Transformation.scaling(0.98,0.98, 1)

Because 0 erases the object.

This does the right job:

ss = Sketchup.active_model.selection;
scale = Geom::Transformation.scaling(0.98,0.98, 1)
comps = ss.grep(Sketchup::ComponentInstance)

Thank you

You are correct … I’ve corrected my entry. Sorry about the mis-info ;(

Thank you. I asked because I gonna confirm your answer as solution.

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