How can I get the nodeID in my NodeModel?

Is is possible to get the nodeID, which I see in the “Node name and description”-dialog, in my NodeModel?

Thanks in advance!

Hi Sandra,

Nope, that’s not possible. Your NodeModel does not have access to any of the framework classes. What would you use the NodeID for?


In my node I create a temporary file and I wanted to use the nodeID in the filename to have one file for each existing node. So the execution of a second should not overwrite the file of the first one.

But thanks for your answer!

Just create a temp file with each instantiation of a NodeModel (e.g. in the constructor or via lazy initialization) and you should be safe. NodeModel instances are not shared among different nodes in a workflow.

But I guess you knew that already.



I'm working on the GenericKnimeNodes project and
we do have the same requirement.

Instead of keeping data in tables our nodes are file based meaning they work on files that are passed via file ports. Files are currently stored in the systems temp directory and can be of multiple GBs in size. That's why we want to persist those computed files across KNIME sessions.
(Currently each node loses its computed files after KNIME startup.)

Each file output port generates a single or a list of files. Identifying those is no big deal but discriminating the same port of multiple node instances is currently unsolved.

Thus we need some kind of node instance identifier so we can persists each nodes files.

Thanks for your help in advance.


+1 same problem/need

Hi Sandra, bkahlert, lindenb,

maybe I found a way to determine the NodeID for the current NodeModel instance.  It's absolutely "legal", no magic or subclassing needed, although, as Bernd already stated, probably not intended to be open to node developers.

First I want to explain, why I would like to know the NodeID.  In my node I want to write files with a dedicated filename; on the one hand I want a filename with some special info included, but distinct from other NodeModel instances, on the other hand I want deterministic and reproducible filenames, so I didn't want to use automatic generated temporary filenames.

Ok, now my proposal:

    private int m_nodeIndex = -1;

    private void getNodeIndex() {
        NodeContext nodeContext = NodeContext.getContext();
        WorkflowManager workflowManager = nodeContext.getWorkflowManager();
        Map<NodeID, MyNodeModel> nodes =
                workflowManager.findNodes(MyNodeModel.class, true);
        for (Entry<NodeID, MyNodeModel> entry : nodes.entrySet()) {
            if (entry.getValue() == this) {
                m_nodeIndex = entry.getKey().getIndex();

This does only work with a fully constructed instance, so I call getNodeIndex() in the configure() method.  And of course this is a very simple approach that e.g. does not consider meta nodes or sub-workflows.

Best, Frank