Skip to content

Instantly share code, notes, and snippets.

@5263
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5263/2a980824adae2f8b2d53 to your computer and use it in GitHub Desktop.
Save 5263/2a980824adae2f8b2d53 to your computer and use it in GitHub Desktop.
check if a FreeCAD wire can be traversed
import FreeCAD
def checkwire(w):
"""steps through every edge of a wire and checks the orientation"""
pos=w.Vertexes[0].Point
for i,e in enumerate(w.Edges):
if e.Orientation == "Forward":
vs=e.Vertexes
else:
vs=e.Vertexes[::-1]
if (pos-vs[0].Point).Length<10E-6:
pos = vs[-1].Point
else:
#print "discontinuity at start of Edge%d" % (i+1)
#print e.Orientation,e.Curve
#print [v.Point for v in e.Vertexes]
#print e.Curve.value(e.FirstParameter),e.Curve.value(e.LastParameter)
return False
return True
if __name__ == '__main__':
import FreeCADGui
for obj in FreeCADGui.Selection.getSelection():
for i,w in enumerate(obj.Shape.Wires):
cont = checkwire(w)
print '%s Wire%d %s' % (obj.Label, i+1,cont )
if not cont:
#retry sorted
import Part
import DraftGeomUtils
sew=DraftGeomUtils.sortEdges([w.Wires])[0][0]
print '%s Wire%d DraftGeomUtils.sortEdges %s' % (obj.Label, i+1,checkwire(sew) )
import OpenSCAD2Dgeom
fcew=Part.Wire(OpenSCAD2Dgeom.findConnectedEdges(w.Edges)[0])
print '%s Wire%d OpenSCAD2Dgeom.findConnectedEdges %s' % (obj.Label, i+1,checkwire(fcew) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment