API Ruby ....face problem...help me

Hi, I wrote a simple Ruby Api file, I have a face problem
looking at the attached png files, you understand better
you can help me…Thank you
Health

Joseph

Maybe an easiest way is to use 2 Groups and #outer_shell

Hello, I would need some more specific help, I’m just beginning
to understand the Ruby Api language…I read the manual online, but for me
it is difficult to understand without some help…Thank you.

Health

Joseph

model = Sketchup.active_model



g1 = model.entities.add_group

f = g1.entities.add_face(
  [0, 0],
  [50.cm, 0],
  [50.cm, 50.cm],
  [0, 50.cm]
)

f.pushpull -150.cm



g2 = model.entities.add_group

f = g2.entities.add_face(
  [0, 0, 150.cm],
  [30.cm, 0, 150.cm],
  [30.cm, 30.cm, 150.cm],
  [0, 30.cm, 150.cm]
)

f.pushpull 100.cm



g3 = g1.outer_shell g2

I think the problem is that after pushpull face, top face touched face_1 and SketchUp deleted the new face. Like when using the Push/Pull tool to create a hole on the wall.
Try creating face_1 after pushpull face!

Thank you very much, Mr. Jim I tried and it works, still a million thanks…

Health

Joseph

Thank you very much, Mr. Voquochai, I tried and it works, still a million thanks…

Health

Joseph

Also another tip.
Don’t start variables with a capital letter.
Ruby assumes these are Constants.
If you try and change one later on you can BUT you’ll get an error message too.
So use latoX or lato_X or latox etc… but never Lato_ X - unless you really want a Constant !

PS:
Make the geometry inside a newly made group = ent.add_group() context, so it’s easy to find faces/edges etc.
You can always explode that group at the end…
Replace your later ent.add… with group.entities.add…
After adding all of your geometry, iterate through all of the edges with edges = group.grep(Sketchup::Edge).
Any with if edge.faces.length == 1 use edge.find_faces to fix “holes”, after that any with if edge.faces.length > 2 you can erase [so that the two boxes join].

Hi TIG, many thanks for the advice…is it true you have to avoid capital letters
to indicate a variable…
for the PS:…I didn’t understand much, if you could find some time
to explain to me with specific examples, you would do me a big favor…
but I don’t want to take your precious time…

Health

Joseph.

@Beppe64 & @voquochai Please post code correctly for forum instead of images of code …

@Beppe64 Please just post your question in the forum properly. Do not double post by sending me a private message of the public post. (It is against the forum rules to double post.) I’ll see any posts in the Developers categories.

Please take advantage of the resources …

2 Likes

Dear Sir Dan…I humbly apologize for doing this…

Health

Joseph.

1 Like

Well since you’re humble, I’ll forgive ya’ :wink:

1 Like

:+1::+1::+1::+1::+1::+1:

d1 = 1000.mm
d2 = 600.mm
h = 2000.mm

rect1 = [
  [0,0,0],  
  [d1,0,0],  
  [d1,d1,0],  
  [0,d1,0]  
]

rect2 = [
  [0,0,h],  
  [d2,0,h],  
  [d2,d2,h],  
  [0,d2,h]  
]

m = Sketchup.active_model
es = m.entities

m.start_operation("add faces", true)

face1 = es.add_face rect1
face1.reverse! unless face1.normal.samedirection?(Z_AXIS)
face1.pushpull(h)

face2 = es.add_face rect2
face2.reverse! unless face2.normal.samedirection?(Z_AXIS)
face2.pushpull(h)

m.commit_operation