Modifying DragCreatingTool to Place Nodes of Differing Categories

My intent is to modify the DragCreatingTool to place nodes with differing categories. I intend to have several instances each with creating a different node category type.
For example: I want to place a textblock node. I have created a template and added it to the templatemap.
I am having trouble with the archetypenodedata.
Here is my code:

 myDiagram.toolManager.mouseMoveTools.insertAt(2,
            $$(DragTextCreatingTool,
            {
                isEnabled: true,  // disabled by the checkbox
                delay: 0,  // always canStart(), so PanningTool never gets the chance to run
                box: $$(go.Part,
                       { layerName: "Tool" },
                       $$(go.Shape,
                         { name: "SHAPE", fill: null, stroke: "cyan", strokeWidth: 2 })
                     ),
                archetypeNodeData: {category:"commentBlock"}, // initial properties shared by all nodes
                insertPart: function (bounds) {  // override DragCreatingTool.insertPart
                    // use a different color each time
                    //this.archetypeNodeData.color = go.Brush.randomColor();
                    this.archetypeNodeData.category = "commentBlock";
                    // call the base method to do normal behavior and return its result
                    return DragTextCreatingTool.prototype.insertPart.call(this, bounds);
                }
            }));

I have tried several different approaches each only retrieves the default templatemap item.

Any help would be greatly appreciated.
Thanks,
CBH

I find that the code works for me. I had to replace DragTextCreatingTool with DragCreatingTool, since you didn’t give that definition. Here’s the code I used in an adaptation of the FlowChart sample:

    myDiagram.toolManager.mouseMoveTools.insertAt(2,
         $(DragCreatingTool,
           {
             isEnabled: true,  // disabled by the checkbox
             delay: 0,  // always canStart(), so PanningTool never gets the chance to run
             box: $(go.Part,
                    { layerName: "Tool" },
                    $(go.Shape,
                      { name: "SHAPE", fill: null, stroke: "cyan", strokeWidth: 2 })
                  ),
             archetypeNodeData: { },  // initial properties shared by all nodes
             insertPart: function(bounds) {  // override DragCreatingTool.insertPart
               this.archetypeNodeData.category = (this.archetypeNodeData.category === "End" ? "Start" : "End");
               this.archetypeNodeData.text = go.Point.stringify(this.diagram.firstInput.documentPoint);
               this.archetypeNodeData.loc = this.archetypeNodeData.text;
               // call the base method to do normal behavior and return its result
               return DragCreatingTool.prototype.insertPart.call(this, bounds);
             }
           }));

This alternates between creating a “Start” category node and an “End” category node. Presumably you have defined your own DragTextCreatingTool so as to set the size of the node in a manner more appropriate for your templates.

OK I can confirm that your code works to modify the Flowchart example.

I am still having issues with my code. The default category is always drawn.

I will have to look closer at what is going on.

Hmmmm

Dooh! I found it. I was calling the node template variable name not the key.