How to find loops edges from selection
-
Hi, everyone
I got a problem in trying to get loops edges from a set of selection which may have more than one loops
, and the loops may share common edge.My target is adding a face for each loops,it is a challenge for me,I worked for some time without no progress.
Can anyone give some advice?Thanks in advance
-
Temporarily group the selected edges using
group=model.active_entities.add_group(model.selection.to_a)
.
Usegroup.entities.to_a.each{|e|e.find_faces}
This will make the needed faces.
You might now wish to check the faces' normal is the expected direction and use face.reverse if not.
Usegroup.explode!
to return the edges and their new faces back into their original context.The reason you group the edges temporarily is that other unselected edges might also form faces with the selected edges and you don't want those faces... This way only selected edges that can form faces will form faces.
-
Or, run find_faces only on the edges that are connected only to other edges selected. ?
-
@thomthom said:
Or, run find_faces only on the edges that are connected only to other edges selected. ?
That works... BUT it assumes that at least one of the selected edges is only connected to other selected edges [admittedly as shown in the OP's example illustration!]... BUT that method won't always work.... If the selected loop of edges contains no edges at all that are themselves only connected to the selected edges, then there'll be no edges to iterate and then no face will be formed at all. Conversely, unning find_faces on any of the edges in such a selection might form extraneous faces outside the loop, if there are other loops available to take faces.
I was trying to offer a general solution.
My 'temp-grouping' method ensures that if the selected edges do form a loop then a face will be made using that - irrespective of what other non-selected-edges those edges might be connected to - and no with extraneous faces resulting either. -
Thank you very much,TIG
It works just like what I want,I don't find any problem up to now in my application
The "temp grouping " method is very useful trick which avoiding unwanted face being created.I pull each face a height, and group it, then I run into another problem, I try to delete the overlap face of each group,but failed.
I try to use raytest method, but it only work when then two loops don't connect to each othergrps.each{|grp| killfaces=[] grp.entities.each{|fa| if fa.is_a? Sketchup;;Face basept=fa.bounds.center.transform! grp.transformation ray = [basept, fa.normal] item = model.raytest ray if item!=nil dist=basept.distance item[0] if dist < mingap killfaces.push fa item[1][1].parent.entities. erase_entities item[1][1] if item[1][1].is_a? Sketchup;;Face end end end } grp.entities.erase_entities killfaces }
any good idea?
-
If you just want to remove internal partition faces [when the forms are merged into one] then make a collection of all of the 'flat' edges in the extrusions [ edge.start.position.z==edge.end.position.z ] and collect any of those with edge.faces.length > 2, then you can erase them if two of that edges faces have face.normal.parallel?(Z_AXIS). This keeps any vertical edges perhaps needed at changes of direction in plan... An inner face can't survive without all of its edges, and we are removing any 'flat' ones...
Otherwise you'll need some very convoluted face.classify_point() combined with some raytest methods [and transformations] to work out which of the edges' faces are the internal ones and then erase them - see tools like my SolidSolver...
-
thanks TIG, I worked it out by classify_point and raytest
Advertisement