--- title: Walking a model tree ---

You can traverse a model tree by calling makerjs.model.walk with your model and an object with these optional properties:
property name property type description
onPath function(walkPath object) called for every path (in every model) in your tree.
beforeChildWalk function(walkModel) called for every model in your tree, prior to diving deeper down the tree. Return false if you wish to not dive deeper.
afterChildWalk function(walkModel) called for every model in your tree, after returning from a deep dive down the tree.

walkPath object

A walkPath object has these properties:

walkModel object

A walkModel object has these properties:

Example

In this example we will create a RoundRectangle and walk its tree. We have an onPath function that will get called for every path in the model. If the path is an arc, we will invert it:

{% highlight javascript %} //render a model using mixed units var makerjs = require('makerjs'); function invertArc(arc) { var chord = new makerjs.paths.Chord(arc); var midPoint = makerjs.point.middle(chord); makerjs.path.rotate(arc, 180, midPoint); } var shape = new makerjs.models.RoundRectangle(100, 50, 10); var walkOptions = { onPath: function (wp) { if (wp.pathContext.type === 'arc') { invertArc(wp.pathContext); } } }; makerjs.model.walk(shape, walkOptions); var svg = makerjs.exporter.toSVG(shape); document.write(svg); {% endhighlight %}