---
title: Find a single chain
---
Let's start with a drawing of a rectangle. A rectangle is a model, but we also implicitly know that a rectangle comprises a chain of 4 paths which connect end to end.
Let's find this chain now using makerjs.model.findSingleChain(model):
{% highlight javascript %}
//from a rectangle, find a single chain
var makerjs = require('makerjs');
var model = new makerjs.models.Rectangle(100, 50);
var svg = makerjs.exporter.toSVG(model);
document.write(svg);
//now find the chain
var chain = makerjs.model.findSingleChain(model);
document.write('found a chain with ' + chain.links.length + ' links and endless=' + chain.endless);
{% endhighlight %}
Now, let's combine two rectangle models in a union.
Notice that a chain will continue unconstrained by the fact that the two rectangle models are independent:
{% highlight javascript %}
//combine 2 rectangles
var makerjs = require('makerjs');
var drawing = {
models: {
r1: new makerjs.models.Rectangle(100, 50),
r2: makerjs.model.move(new makerjs.models.Rectangle(100, 50), [50, 25])
}
};
makerjs.model.combineUnion(drawing.models.r1, drawing.models.r2);
var svg = makerjs.exporter.toSVG(drawing);
document.write(svg);
//now find the chain
var chain = makerjs.model.findSingleChain(drawing);
document.write('found a chain with ' + chain.links.length + ' links and endless=' + chain.endless);
{% endhighlight %}