Add_group ( how to do )

Hello, i’m starting ruby on sketchup
just tring to make a simple volume and convert it into a group

it doesn’t work… how to do? thanks for your help

def panne_delard(largeur,hauteur,pente,plat)

pt1 =,0,0)
pt3 =,0,0)
pt4 =,,0)
pt5 =,hauteur,0)
pt6 =,hauteur,0)

entities.add_cpoint pt1
entities.add_cpoint pt3
entities.add_cpoint pt4
entities.add_cpoint pt5
entities.add_cpoint pt6
section_panne = entities.add_face pt1,pt3,pt4,pt5,pt6
panne=section_panne.pushpull 1.m



The following should do what you want.

entities = model.active_entities
group = entities.add_group panne

doesn’t work

here is my ruby console

here is my code

There are several problems:

  • pushpull returns a status indicator for the operation, not the entities created by the operation, so panne is nothing you can add to a group. That’s the cause of the error message.
  • you should create the group first then add and manipulate your geometry within the group’s entities collection (this order of operations is recommended in the API docs).
  • the line entities=model.active_entities likely doesn’t do what you expect. It returns the edit context (model, group’s entities, or component’s entities) currently open for edit in the model. So, the group you are creating will be nested in whatever context is open at the time you invoke your method.
1 Like

thank you for your answer
it’s true i’ve read in the API to create an empty group and then to add the geometry inside.

the point is : i don’t find in the API or in samples how to add my geometry inside a group.

i will investigate

To consolidate the replies…

 def panne_delard(largeur, hauteur, pente, plat)
        pt1 =,0,0)
        # why no pt2 ??
        pt3 =,0,0)
        pt4 =,,0)
        pt5 =,hauteur,0)
        pt6 =,hauteur,0)
        section_panne = entities.add_face(pt1, pt3, pt4, pt5, pt6)
        # rest of the code...

thanks @TIG

here is what i’ve just tried while you were writing your reply

and it works!

going further…
is there somewhere a simple tutorial for creating an icon to call my panne_delard function with a window in which i can fill for the parameters ( without opening the ruby console ) ?

i initially used pt2 but i deleted it because it wasn’t usefull.
but as it was on my paper sheet, i decided not to renumber the others points

my way of working… to avoid changes that can introduce bugs hard to fix ( in my experience )

See inputbox:

In your case something like:

prompts=['largeur', 'hauter', 'pente', 'plat']
values=[,, 0.0, 0.0] # default values - you choose
pops=['', '', '', '']
results=inputbox(prompts, values, pops, title)
return nil unless results # if user cancels
largeur, hauteur, pente, plat = results

I assume largeur and hauter are dimensions [aka ‘lengths’] ?
And if pente is an angle in degrees - to use that = pente.degrees, which turns it into radians for coding use…
Not sure what ‘plat’ represents ? If it’s Z ‘level’ use a ‘length’ like ??

Here is the result. pente is in percentage not in degrees ( wood carpentry usage )

A subtle “gotcha” for future reference:

SketchUp’s Ruby API is very aggressive about deleting empty groups. So, you should have something (typically a cpoint) ready before you create the group and add that something to the group’s entities immediately after creating the group. If it was purely a temporary for this purpose, you can erase the something later after you have added the real content. Doing it that way avoids any possibility that SU will kill the group before you get around to adding content.

So it’s:
values=[,, 0.0,] # default values - you choose
The 3rd value % needs to be a ‘float’, the rest are ‘lengths’.

inputbox works perfectly for my use

thank you very much

and finally, i’ve just created my own toolbar with Extension | SketchUp Extension Warehouse
for calling my ruby functions