OK, starting from the Adornment Buttons sample…
First, since you clearly don’t want the selection Adornment template to include buttons, there’s no reason to specify a custom Node.selectionAdornmentTemplate.
Second, since there will be at most one such set of "Button"s visible at a time, they will be a single Adornment, not a template. So change the code to be like:
var adornmentButtons =
$(go.Adornment, "Spot",
$(go.Placeholder),
$(go.Panel, "Horizontal",
. . .
Third, we need to notice as the Diagram.selection collection changes. So we add a “ChangedSelection” DiagramEvent listener:
$(go.Diagram, . . .,
{
"ChangedSelection": function(e) {
var node = null; // find the last selected Node, if any
e.diagram.selection.each(function(p) { if (p instanceof go.Node) node = p; });
if (node && node !== adornmentButtons.adornedPart) {
adornmentButtons.adornedObject = node;
node.addAdornment("Buttons", adornmentButtons);
} else if (!node) {
var oldnode = adornmentButtons.adornedPart;
if (oldnode) {
oldnode.removeAdornment("Buttons");
adornmentButtons.adornedObject = null;
}
}
},
. . .
Note how it finds the last selected Node, not just the last selected Part that might be a Link or something else.
Fourth, if we want to select a Node before the Diagram is fully initialized, we should do something like:
var node = myDiagram.findNodeForKey(4);
if (node) {
node.isSelected = true;
adornmentButtons.adornedObject = node;
node.addAdornment("Buttons", adornmentButtons);
}