Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #***************************************************************************
- #* *
- #* Copyright (c) 2013 Daniel Falck <ddfalck@gmail.com> *
- #* *
- #* This program is free software; you can redistribute it and/or modify *
- #* it under the terms of the GNU Lesser General Public License (LGPL) *
- #* as published by the Free Software Foundation; either version 2 of *
- #* the License, or (at your option) any later version. *
- #* for detail see the LICENCE text file. *
- #* *
- #* This program is distributed in the hope that it will be useful, *
- #* but WITHOUT ANY WARRANTY; without even the implied warranty of *
- #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- #* GNU Library General Public License for more details. *
- #* *
- #* You should have received a copy of the GNU Library General Public *
- #* License along with this program; if not, write to the Free Software *
- #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
- #* USA *
- #* *
- #***************************************************************************
- '''
- Macro to reverse the list of edges in a wire and turn reverse the order of their
- Vertexes
- '''
- from DraftGeomUtils import sortEdges, findMidpoint,findWires, isReallyClosed, isClockwise,findWires
- from FreeCAD import Vector,Base,Part
- import FreeCADGui
- def flip_wire():
- sel=Gui.Selection.getSelection()
- group= sel[0]
- geom = group.Group
- name = group.Name
- LinesArcs = True
- edges=[]
- # points = []
- for s in geom:
- if s.Type =='Part::Vertex':
- LinesArcs = False
- # startpt = App.activeDocument().addObject("Part::Feature", "startpt")
- # startpt.Shape = s
- # group.addObject(startpt)
- #points.append(s)
- else:
- LinesArcs = True
- #objs.append(s.Object)
- edges.append(s.Shape)
- #group.removeObject(s.Shape)
- if LinesArcs:
- App.activeDocument().removeObject(s.Name)
- sorted_edges = []
- sorted_edges = sortEdges(edges)
- wire1 = findWires(sorted_edges)
- new_list = []
- for w in wire1[0].Edges:
- new_list.append(w)
- new_list.reverse()
- def flip_verts(edgeList):
- edge_list = []
- shape = ''
- new_edge = ''
- for s in edgeList:
- if (isinstance(s.Curve,Part.Line)):
- FreeCAD.Console.PrintMessage( 'Line\n')
- v2 = s.Edges[0].Vertexes[0]
- v1 = s.Edges[0].Vertexes[-1]
- shape = 'Line'
- new_edge = Part.makeLine(Vector(v1.X,v1.Y,v1.Z),Vector(v2.X,v2.Y,v2.Z))
- edge_list.append(new_edge)
- elif (isinstance(s.Curve,Part.Circle)):
- if s.Closed:
- shape = 'Circle'
- center = s.Curve.Center
- radius = s.Curve.Radius
- new_edge = Part.makeCircle(radius,center,0,360)
- edge_list.append(new_edge)
- else:
- FreeCAD.Console.PrintMessage( 'Arc\n')
- shape = 'Arc'
- v3 = s.Edges[0].Vertexes[0].Point
- FreeCAD.Console.PrintMessage( str(v3)+'\n')
- v2 = findMidpoint(s)
- FreeCAD.Console.PrintMessage( str(v2)+'\n')
- v1 = s.Edges[0].Vertexes[-1].Point
- FreeCAD.Console.PrintMessage( str(v1)+'\n')
- new_arc = Part.Arc(v1,v2,v3)
- new_edge = new_arc.toShape()
- #FreeCAD.Console.PrintMessage( str(new_edge.Type)+'\n')
- edge_list.append(new_edge)
- elif (isinstance(s.Curve,Part.Point)):
- shape = 'Point'
- else:
- pass
- return edge_list
- flip_list = flip_verts(new_list)
- secondWire = Part.Wire(flip_list)
- # newwire=App.activeDocument().addObject("Part::Feature", "w")
- # newwire.Shape = secondWire
- # group.addObject(newwire)
- #Part.show(secondWire)
- for i in flip_list:
- newobj = App.activeDocument().addObject("Part::Feature", "edge")
- newobj.Shape = i
- group.addObject(newobj)
- App.activeDocument().recompute()
- flip_wire()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement