Ruby automatic proces

Hello,

I want to create a tool that can draw a simple construction with columns and beams. This have to be components. I want an option that you can give in height, width, length and how many fields. So you have an automatic proces. I can do some simple ruby things but I don’t know if my idea is possible? Or can this better been done with dynamic components?

Thanks for the help

It can be done with dynamic components or Ruby, just as you like to do it.

Anssi

Oké thanks

I only don’t know how to call a component with ruby and how a length or height can be dynamic?

Can’t find some good tutorial on YouTube.

Let’s assume you have a simple SKP component made manually - let’s say it’s named ‘box.skp’.
It’s a 1x1x1" cube, with its base centered on the ORIGIN.

You can make it within the model using Ruby BUT I think this approach is simpler…

Now in Ruby code you need to add it into the model’s definitions.

model = Sketchup.active_model defn = model.definitions.load( full_path_to_box.skp )

Now you need to add the ‘defn’ as an instance [for now we’ll put it at the ORIGIN, then transform it].

inst = model.active_entities.add_instance( defn, ORIGIN )

Now let’s transform it…

  • first its location

inst.transform!( Geom::Transformation.new( some_new_location_point ) )

and assuming it’s a column… let’s scale its height etc [remember it’s 1" in all axes at the moment], leaving its insertion-point where we just specified it…

inst.transform!( Geom::Transformation.scaling( inst.transformation.origin, x_size, y_size, z_size ) )

The sizes should be in inches as it starts off as 1x1x1", so it it is to be 12" x 6" x 96" use:
inst.transform!( Geom::Transformation.scaling( inst.transformation.origin, 12.0, 6.0, 96.0) )

Read up on the API:
http://www.sketchup.com/intl/en/developer/docs/ourdoc/definitionlist
http://www.sketchup.com/intl/en/developer/docs/ourdoc/entities
http://www.sketchup.com/intl/en/developer/docs/ourdoc/transformation

2 Likes

Thank you Tig.

Going to try this with ruby to see if I can build a simple floor and also to see if I can make a message box that can appear to input sizes