How to save a diagram as node Template?

I want create a diagram useing some base shapes of GoJS,and then save the diagram as a node template use it to another diagram.
how to do that? are there some demos?

Call Diagram.makeImage, GoJS Making Images -- Northwoods Software. To save memory you will want to scale it down to a reasonable size with the same aspect ratio. Use the Image in a Picture with the same dimensions. Hold the Picture inside a “Viewbox” Panel so that it is automatically scaled down or up without warping to the size that you want inside your node template. GoJS Panels -- Northwoods Software

In our using,the “Node” more like a group of shapes,but It can be drag into diagram from palette one time.

we want our user can design the “Node” by themselves. The “Node” is more complicated than example “FloorPlanEditor”,and we want to control the sub part of the “node” by script,such as change color of the sub part, etc.

Use SVG is not a good idear,because when resize a node it’s strokeWidth will changed, and if use SVG Image we can’t control the sub part of node by script.

So you want to offer a general node editor where the user can edit individual Shapes. Each such Shape should be inside a Part, to support selection, moving, resizing, rotating, reshaping, and deleting and copying. Some samples include Geometry Reshaping and Freehand Drawing Tool.

Then you can make a Node out of those Parts. Have the Node be a “Position” Panel. Copy the Shape of each Part into the Node. Scale down the Node so that it’s a reasonable size. If you don’t want the strokes to get thinner you will have to scale down the geometries of all of the Shapes and scale down their positions.

I suppose you will want to give each Shape a name so that it’s easy to talk about to control it’s fill and/or stroke color.

So then How to export the shapes in then diagram to data stream ? Are there some simple method to do this, such as: model.toJson() or .makeSvg()?

It depends on how much you want to keep constant in the template and how much you want to parameterize in the model. I suppose you could put the “variable” properties of each Shape in an object. You could have a variable number of those as items in an Array; this would be data bound from Panel.itemArray, and the itemTemplate could just be a Panel holding a Shape with a bunch of data bindings, one for each of the properties in the item data object.

Assuming you only are binding properties with JSON-serializable property values, then Model.toJson and Model.fromJson will work.