Best Strategy for Clean Geometry
-
I have a
box
method that Rectangles from one corner to a second corner, then PushPulls the rectangle to create a box. It works well if it doesn't mingle with other geometry. I want a nice, clean box not touching other geometry so I can group or component it, then let it go play with the other geometry. So far I've thought ofa) Push the current model onto a stack. File/New. Draw box. Save. Pop model. Import. (Can you File/Import in Ruby?)
b) Same as a) but use fresh layer, not model. Group/Component before moving to existing layer.
c) Code my own PushPull so I can keep references to rectangle's face and edges and all eight new edges and 5 new faces.
-
Why not group it first ?
group=model.active.entities.add_group() group.entities.add_edges(...) ### etc ### Why wait till afterwards to group it ? ### You can always explode at at the end !
This also lets you find faces, edges etc more easily...
-
@tig said:
Why not group it first ?
> group=model.active.entities.add_group() > group.entities.add_edges(...) > ... >
This also lets you find faces, edges etc more easily...
The implication is abandoning face.pushpull in favor of writing my own pushpull?
Be careful how you advise me, TIG. I have enough respect for you to actually take your advice.
-
Separating your new geometry inside a new group's entities [or component definitions entities] and then pushpulling it [or whatever you want to do to it] inside the group quite safely, and away from other geometry clashes is a good [English understatement for 'the correct'] way to make new stuff like this.
When you are done then you can explode the group and the geometry can intermingle with other stuff, if desired...
Personally I prefer to leave my new geometry grouped for the user to decide on the explode - see ExtrudeEdgesByRails et al...
-
@tig said:
Personally I prefer to leave my new geometry grouped for the user to decide on the explode
# /r/t.rb # Work in progress. Do not put into service. # Finished version will be in my tutorial, Chapter 14. def pp_add( pt, vec ) return [ pt[0]+vec[0], pt[1]+vec[1], pt[2]+vec[2] ] end def pp( face, distance ) # the full vector is the face's normal times the pushpull distance norm = face.normal.to_a() vec = [ norm[0]*distance, norm[1]*distance, norm[2]*distance ] # create a new set of vertices 'vec' away from the original vs = face.vertices() new_vs = [] for i in 0..vs.length-1 new_vs[i] = pp_add( vs[i].position, vec ) end # TIG's idea; ents1 = Sketchup.active_model.entities grp = ents1.add_group() inst = grp.to_component() defi = inst.definition() ents2 = defi.entities() a = [] for v in face.vertices a.push( v.position ) end old_face = ents2.add_face( a ) ents1.erase_entities( face ) # add a face with the new vertices new_face = ents2.add_face( new_vs ) # draw faces around the outside for i in 0..(vs.length-1) f = ents2.add_face( new_vs[ i%vs.length ], new_vs[ (i+1)%vs.length ], vs[ (i+1)%vs.length ], vs[ i % vs.length ] ) f.reverse! if distance < 0 end # loop over vertices # flip a face so they all face outside new_face.reverse! if distance < 0 old_face.reverse! if distance > 0 return inst end # of pp()
-
I'm not understanding. This draws a box within the context of a Group.
pts = [ [0, 0], [0, 10], [10, 10], [10, 0] ] group = Sketchup.active_model.entities.add_group() face = group.entities.add_face(pts) face.pushpull(10)
-
Martin is/was making it far too complex... it even converted the group to a pointless component ?
KISS...
Jim's example is the better way to do it... Explode the group at the end if desired...
Advertisement