Offset top face only...need help!
-
Hi, bellow is an attempt to offset the top face lines but I am running into some issues.
model = Sketchup.active_model ents = model.active_entities faces = ents.grep(Sketchup;;Face) sel = model.selection faces.each do |face| if face.normal.z == 1 edges = face.edges edges.to_a.each do |e| p1 = e.start.position p2 = e.end.position x1 = p1.x x2 = p2.x y1 = p1.y y2 = p2.y length = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) offset = 10.0 x1p = x1 + offset * (y2-y1)/length #/ x2p = x2 + offset * (y2-y1)/length #/ y1p = y1 + offset * (x1-x2)/length #/ y2p = y2 + offset * (x1-x2)/length #/ newedges = ents.add_line([x1p,y1p,p1.z+5],[x2p,y2p,p2.z+5]) sel.add newedges end end endWhere do I start
...Notice that when I add the line, the z coordinates have +5 added because if I make it same height as face the new edges break the next edge that it will offset and mess the result.
You can see what I mean if you replace "p1.z+5" to "p1.z" & "p2.z+5" to "p2.z". You need to have a face that where z axis = 1.
What I had in mind was to elevate the edges by 5 and somehow abstract the vertex position where the new edges intersect. Problem is they don't produce any vertex.
Not sure if I am explaining myself but all I want is to offset the top face. Any help will be appreciated as always.
Thanks!
-
Read my SmartOffset code to see how I offset the edges of a given face...
-
Side note - Ruby is very slow. You'll find using the SketchUp API's .distance method much faster than doing your own length calculation. At least if you do this for a somewhat large set of entities.
-
@tig said:
Read my SmartOffset code to see how I offset the edges of a given face...

That is by no means an easy task but I will try to understand what you wrote. Isn't there a 1st grader version?
@tt_su said:
Side note - Ruby is very slow. You'll find using the SketchUp API's .distance method much faster than doing your own length calculation. At least if you do this for a somewhat large set of entities.
That is good to know thanks!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better ๐
Register LoginAdvertisement