How to make from an object into a group

sketchup

#1

Hi there,
i am new with Sketchup in combination with Ruby.
i try to make an block with an square hole in it.
see script below.

the script is working, but i will all the entities together to an group.
how do you do that…
who can help me further with this…?

mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection

f1 = []
f1[0] = [0,0,0]
f1[1] = [50,0,0]
f1[2] = [50,50,0]
f1[3] = [0,50,0]

f2 = []
f2[0] = [10,10,0]
f2[1] = [40,10,0]
f2[2] = [40,40,0]
f2[3] = [10,40,0]

face_outer = ent.add_face f1
face_inner = ent.add_face f2
face_inner.erase!
face_outer.reverse!
face_outer.pushpull 10


#2

You need to put the horse in front of the cart: Instead of adding your entities to the active model’s Entities, start by adding a new group there and then add your content to the group’s Entities. It is much harder to move existing entities into a Group or Component than to create them there in the first place.


#3

how to make an group
and how to put the entiies in it…?
please explane more… i am new with ruby and need some samples


#4
group = Sketchup.active_model.entities.add_group
ents = group.entities
# now use Entities methods to add stuff to ents just as you did in your example

#5

oké i have made an group and put the entities f1 and f2 in the group
ents.add_face f1
ents.add_face f2
but now i will explode the face and erease f2 and then pushpull f1 after that make it an group again
can you tell me , how to do that…?


#6

You don’t need to explode anything. You can do the same manipulations within a Group’s Entities collection as within the Model’s Entities collection.


#7

oké can you let me see how i can pushpull in an group entities collection…?


#8

Exactly as you did in your original example code, which except for not being in a group you said worked. Having the entities in a group does nothing to change how pushpull works. In other words:

mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection

f1 = []
f1[0] = [0,0,0]
f1[1] = [50,0,0]
f1[2] = [50,50,0]
f1[3] = [0,50,0]

f2 = []
f2[0] = [10,10,0]
f2[1] = [40,10,0]
f2[2] = [40,40,0]
f2[3] = [10,40,0]

gp=ent.add_group
group_ent=gp.entities

face_outer = group_ent.add_face f1
face_inner = group_ent.add_face f2
face_inner.erase!
face_outer.reverse!
face_outer.pushpull 10

#9

thanks for your responce.

i have made the following script and this works.
group = Sketchup.active_model.entities.add_group
ents = group.entities

f1 = []
f1[0] = [0,0,0]
f1[1] = [50,0,0]
f1[2] = [50,50,0]
f1[3] = [0,50,0]

f2 = []
f2[0] = [10,10,0]
f2[1] = [40,10,0]
f2[2] = [40,40,0]
f2[3] = [10,40,0]

face1 = ents.add_face f1
face2 = ents.add_face f2
face2.erase!
face1.pushpull -10