1. Open the chain_blank.fcstd file.

2. Select [Ctrl] Sketch008, Link2 and Link1.

3. Paste below script ant hit enter:

Code: Select all

```
#an very buggy and ugly chain generator script
from FreeCAD import Vector
import math, Part, Draft, DraftGeomUtils
s = FreeCADGui.Selection.getSelection()
try:
edges = s[0].Shape.Edges #select chain driving sketch/wire
shape = s[1].Shape #select first chain link
shape2 = s[2].Shape #select select chain link
except:
print "Wrong selection"
is_intersect = True
r = 25.4 #link length
edge = edges[0]
p1 = edge.Vertexes[0].Point
p2 = edge.Vertexes[1].Point
angle = math.degrees(Draft.DraftVecUtils.angle(Vector(1,0,0),(p2-p1)))
sc1 = 1
for e in range(len(edges)):
edge = edges[e]
is_intersect = True
pl = FreeCAD.Placement(p1, Vector(0,0,1), angle) #base, rotation axis, angle
while is_intersect == True:
arc = Draft.makeCircle(radius=r,placement=pl,face=False,startangle=-90,endangle=90,support=None) #draw helper half-circle
intersect = DraftGeomUtils.findIntersection(arc.Shape.Edges[0], edge)
p2 = intersect[0]
is_intersect = DraftGeomUtils.isPtOnEdge(p2, edge) #check if intersection point is on edge
angle = math.degrees(Draft.DraftVecUtils.angle(Vector(1,0,0),(p2-p1)))
pl = FreeCAD.Placement(p2, Vector(0,0,1), angle)
if sc1 == 1:
newshape = shape.copy()
sc1 = 0
else:
newshape = shape2.copy()
sc1 = 1
newshape.rotate(Vector(0,0,0),Vector(0,0,1),angle)
newshape.translate(p1)
p1 = p2
Part.show(newshape)
```