Creating a part in a group without moving group

I have a diagram, a palette, several node types and a group. When I create a Part by double clicking in the diagram I create a node of the same category as the one that is selected in the palette. Similarly, I can create a Part by of a given category by dragging its node from the palette to the diagram. This all works Smile

However, I have one category (“Risk”) that should only be created within the group called “Risks”. I have got this working but alas the group moves to the location of the part creation double click or the drop location. Is there away to force the newly create node to the location of the group (ie the group stays put during this operation)?

kind regards
Julian H J Loaring

If you are using the ClickCreatingTool, you will want to override ClickCreatingTool.insertPart to ignore its location argument (which is normally the [double-]click point in document coordinates) and instead call the base method with a point that is suitably within the “Risks” Group that presumably already exists.

Thanks Walter

I am using the techniques found in http://www.nwoods.com/forum/forum_posts.asp?TID=5146&KW=override+method&PID=21884&title=questions-about-mouses-behaviors#21884 to do the override but I am now stuck again (it didn’t take long!).

In my override of insertPart(), how do I determine the category of the part being inserted? In the code below what is “???”, I tried “this” but it didn’t work. Also, is the call to to the base class correct - it was a complete guess!

CustomClickCreatingTool.prototype.insertPart = function (loc) {

    if (???.category === "Risk") {

    } else {
        go.ClickCreatingTool.insertPart(this, loc);
    }
};

kind regards
Julian

Close – calling the base method should be in the following format:
go.ClickCreatingTool.prototype.insertPart(this, loc);

Only you know how to decide what category data to create, since that is specific to your app. From your description I think you want to look at something like:
myPalette.selection.first().data.category === “Risk”
But that’s just a wild guess on my part. And of course you need to handle the case when there’s no selected Part in myPalette.

D’oh! I had completely forgotten that I could access the palette! I will give this a try.

VMT
Julian