[Req] Check for N-Gons
-
Your wish is my command. Give me 5 mins...
Version 3:
works over the entire model (in groups and components), thanks to TIGs handy little snippet.
Adds all N-gons to a new selection
Tells you how many N-Gons there are in the model
Added a Tri check which can be accessed by typingtri_check()
in to the ruby console
-
Here you go, copy and paste this in to jims/alexs web console and click run.
model = Sketchup.active_model entities = model.entities selection = model.selection n = 0 entities.each{|e| if e.is_a? Sketchup;;Face if e.edges.length > 4 n += 1 end end } if n > 0 UI.messagebox("Contains N-Gons (Faces with >4 sides)") else UI.messagebox("N-gon free!") end
-
-
thanks I owe you one
-
oops.... it's not working... everythings coming up as N-Gon free....
-
khai, i'm pretty sure it's not looking inside groups/components otherwise it appears to be working.
-
aah explode it first... I tried with just groups and selecting the group... did'nt think to explode it first..
-
Sorry i didnt reply, internet cut out.
As jeff pointed out its not gong through faces that are within groups/components for some reason. This version will go through all the faces in the current context, so a slight improvement but not much better. Not sure why it doesnt work on all the faces in the model straight off
-
Remus
Your current script finds all faces in the theactive_entities
- those in the current 'edit' session.
Perhaps do that ifselection.length==0
, but do it on selection if>0
?
You could also do it onentities
which would be all faces in the base model.
To get absolutely all faces in the model and its definitions [components and groups] usefaces=[] model=Sketchup.active_model model.entities.each{|e|faces<< e if e.class==Sketchup;;Face} model definitions.each{|d|d.entities.each{|e|faces<< e if e.class==Sketchup;;Face}} ### then test 'faces' array for 4-sidedness ones...
It depends which faces you want to list - i.e. all or all-active or all-selected ???
-
Wondering out aloud.... so what then? you find the N-gons what do you do with them? divide them into triangles?
-
@solo said:
Wondering out aloud.... so what then? you find the N-gons what do you do with them? divide them into triangles?
My
triangulateFaces
ortriangulateQuads
already does that ?
I expect he wants to find un-triangulated faces > quads for some other esoteric processing .................
-
actually to divide them into Quads (preferred) or Tris - I use Sketchup as a modeler for other programs you see, they prefer no N-Gons... (Mainly poser content)
-
TIG, i realise the current script only works in the current context (in a group etc.), it was on purpose as i thought it was more useful than only being able to check the faces in the highest context.
On another note, does
entities
not include faces, edges etc. that are within components? If so that would explain why khai was having trouble with it... -
@remus said:
TIG, i realise the current script only works in the current context (in a group etc.), it was on purpose as i thought it was more useful than only being able to check the faces in the highest context.
On another note, does
entities
not include faces, edges etc. that are within components? If so that would explain why khai was having trouble with it...active_entities
is everything in the current edit session - i.e. in the model or a group or component being edited.
entities
is everything in the model - as inmodel.entities
but stops short of nested stuff so it lists all geometry, groups, instances etc.
You also useentities
for other containers likegroups
orcomponent_definitions
- e.g.group.entities
anddefinition.entities
. again these stop short of listing nested stuff.
To find ALL entities you need to do my trick of iterating through themodel.definitions
and going through theentities
of eachdefinition
...
Remember too that if you are changing entities always use anarray
as inents.to_a
- changingentities
as you 'each
' loop through them leads to unpredictable results as theentities
list constantly changes and so it becomes confused... -
Cheers for the explanation
-
presto reserectus!
http://forums.sketchucation.com/viewtopic.php?f=169&t=24681&p=247955#p247955
I'm wondering if this can be expanded now to highlight the Ngons? we're finding with Sculptis it rejects any faces with more than 4 faces....
-
Try this in the webconsole. To be honest your probably better off using TIGs triangulate faces ruby, though...
model = Sketchup.active_model entities = model.active_entities selection = model.selection n = 0 entities.each{|e| if e.is_a? Sketchup;;Face if e.edges.length > 4 n += 1 selection.add(e) end end } if n > 0 UI.messagebox("Contains N-Gons (Faces with >4 sides)") else UI.messagebox("N-gon free!") end
-
webconsole?
and I explained back in this thread.. I can't tri the mesh. I'm moving from here (I love the modeler!) to app that don't like things being totally tri's... so that ruby's no good to me.
-
Webconsole is a handy little ruby that lets you run bits of ruby in SU without having to package it as a separate file. You can find it here: http://sketchuptips.blogspot.com/2007/08/plugin-webconsolerb.html
Just install it as usual, open SU, hit the appropriate menu item, copy and paste the code in and click run.
I'll get going on a normal version, but no promises. Its been a while since ive written a ruby.
-
Ok, here you go.
Several improvements in v.3:
works over the entire model (in groups and components), thanks to TIGs handy little snippet.
Adds all N-gons to a new selection
Tells you how many N-Gons there are in the model
Added a Tri check which can be accessed by typingtri_check()
in to the ruby console
Advertisement