Now you can join multiple wires all at once
This commit is contained in:
committed by
Yorik van Havre
parent
7e7e298efb
commit
954cc2faad
@@ -1339,7 +1339,20 @@ def extrude(obj,vector,solid=False):
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
return newobj
|
||||
|
||||
def joinWires(wire1, wire2):
|
||||
def joinWires(wires, joinAttempts = 0):
|
||||
if joinAttempts > len(wires):
|
||||
return FreeCAD.ActiveDocument.recompute()
|
||||
joinAttempts += 1
|
||||
for wire1Index, wire1 in enumerate(wires):
|
||||
for wire2Index, wire2 in enumerate(wires):
|
||||
if wire2Index <= wire1Index:
|
||||
continue
|
||||
if not joinTwoWires(wire1, wire2):
|
||||
wires.pop(wire2Index)
|
||||
break
|
||||
joinWires(wires, joinAttempts)
|
||||
|
||||
def joinTwoWires(wire1, wire2):
|
||||
wire1AbsPoints = [wire1.Placement.multVec(point) for point in wire1.Points]
|
||||
wire2AbsPoints = [wire2.Placement.multVec(point) for point in wire2.Points]
|
||||
if wire1AbsPoints[0] == wire2AbsPoints[0]:
|
||||
@@ -1349,10 +1362,13 @@ def joinWires(wire1, wire2):
|
||||
wire2AbsPoints = list(reversed(wire2AbsPoints))
|
||||
elif wire1AbsPoints[-1] == wire2AbsPoints[-1]:
|
||||
wire2AbsPoints = list(reversed(wire2AbsPoints))
|
||||
elif wire1AbsPoints[-1] == wire2AbsPoints[0]:
|
||||
pass
|
||||
else:
|
||||
return False
|
||||
wire2AbsPoints.pop(0)
|
||||
wire1.Points = [wire1.Placement.inverse().multVec(point) for point in wire1AbsPoints] + [wire1.Placement.inverse().multVec(point) for point in wire2AbsPoints]
|
||||
FreeCAD.ActiveDocument.removeObject(wire2.Name)
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
def fuse(object1,object2):
|
||||
'''fuse(oject1,object2): returns an object made from
|
||||
|
||||
@@ -3234,7 +3234,7 @@ class Join(Modifier):
|
||||
print(FreeCADGui.Selection.getSelection())
|
||||
FreeCADGui.addModule("Draft")
|
||||
self.commit(translate("draft","Upgrade"),
|
||||
['Draft.joinWires(FreeCADGui.Selection.getSelection()[0], FreeCADGui.Selection.getSelection()[1])', 'FreeCAD.ActiveDocument.recompute()'])
|
||||
['Draft.joinWires(FreeCADGui.Selection.getSelection())', 'FreeCAD.ActiveDocument.recompute()'])
|
||||
self.finish()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user