Reverse faces after pushpull??
-
Drawing counter sunk holes with a rb script and all looks ok except the faces on the inside of the thru hole are reversed and I have not be able to alter the code to fix this. Any suggestions???
when "C_Sunk" #Calculate points for C_Bore points_ScrewHead(@xcl[i],ycl,0,(@h_dia/2),dir_y) #@pthd[ ] @pthd=@pthd.collect {|point| point.transform(backt)} points_Screw(@xcl[i],ycl,(@z1*-1),(@s_dia/2),dir_y) #@ptsc[ ] @ptsc=@ptsc.collect {|point| point.transform(backt)}#to component coord cface=codef.entities.add_face(@pthd) #Counter Sink Dia codef.entities.erase_entities cface #Erase face for CS large opening cface=codef.entities.add_face(@ptsc) # Screw shank Dia if @thruHole == "Yes" then cface.pushpull((@edge3L-@z1)*-1) end #Pushes scw dia thru component codef.entities.erase_entities cface # Added this because pushpull left face at bottom of CS for k in -1...11 cface=codef.entities.add_face(@pthd[k],@pthd[k+1],@ptsc[k+1],@ptsc[k]) # Adds bevel faces for CS end # for k
Keith
-
Why not try flipping the face:
cface.reverse!
immediately after you make it...
and then do something like:
cface.pushpull(@edge3L-@z1)
??? -
I have tried that and to make sure I tried again still reversed. I seem to need a way to identify the faces created with the pushpull and reverse each one. Or else just leave them red. I know the points on each end of the circle just the z value changes could I use face common to 2 edges to find each face and change it??
Keith
-
How about this...
In code...
Add a group to the entities holding the main face.
Add a circle inside group.entities.
Use face.pushpull on this new circular face to form the basis of the 3d hole.
You now have all of the faces inside that group so you can use .reverse! on them all, so it's turned "inside out".
Redraw the circle inside the group [the original will be lost during the pushpull so any earlier reference to it is useless]
Erase that newest face as the reference to it persists.
You now have a group containing a cylinder without a top [like an opened tin can].
Now cut a circular hole in the main face - add the circle onto it and use .erase!, as you have a reference to its face.
Now you have the main face with a circular hole in it and the rest of the cylindrical 'hole' in a group below it.
Use .explode! on that group and the things heals together as required... -
Here is what I have been trying but the code breaks some rule or rules. I am trying to capture the no of entities created with the push pull and search thru them for faces and reverse the faces I find. On the first hole the no of entities increase from 49 to 84 so I was trying to loop thru those to find faces. error message is #<NoMethodError: undefined method `[]' for #Sketchup::Edge:0x9f13ee4>
cface=codef.entities.add_face(@ptsc) orig_l=codef.entities.length #UI.messagebox("Orig no of enities = " + orig_l.to_s) if @thruHole == "Yes" then cface.pushpull((@edge3L-@z1)*-1) end codef.entities.erase_entities cface fin_l=codef.entities.length #UI.messagebox("Final no of enities = " + fin_l.to_s) for j in orig_l.to_i..fin_l.to_i ents = codef.entities[j] if ents[j].typename == "Face" then ents.reverse! end end # for j
Keith
-
Because your making changes to the C++ side entities collection from within a loop... the loop looses "it's way" (items get skipped, some get processed more than once.)
Items in a collection are not necessarily in order like an array.
You need to copy the orginal collection to an array
line 2:orig_ents = codef.entities.to_a
then the final to an array
line 6:fin_ents = codef.entities.to_a
then subtract:
added_ents = fin_ents - orig_ents
Then iterate that array:
added_ents.each {|e| e.reverse! if e.is_a?(Sketchup::Face) }
-
Thanks Dan worked like a charm. I can't tell you people on the forum how much I appreciate the help. Books and help files only go so far its help like I get here that makes any thing I come up with possible. I have ideas and I am sure there are ways of getting it done but it takes help like I get here to make it a reality.
Thanks All
Keith -
My idea of using a temporary group means that the faces in the group are all that's needed to consider for reversing - so it very quick; if you are making lists of all entities before and after a pushpull then there might be thousands of them to sift through, twice! ... So why not make a group, add a circular face, pushpull it, reverse the faces in the group, re-add a circular face to the group and erase it, then add a circular face to the main-face and erase it to leave a hole over the grouped 'recess', and finally explode the group? It will be much quicker in most circumstances... and 'safer' too...
Advertisement