Setting icon path for KnimeNode instance

Hi Team,

I am working on dynamic node generation. In my DynamicNodeFactory::createNodeDescription(), I am creating node description for a new node and facing issue while setting the icon path in knimenode::setIcon(). The code snippet is as below. This fails if the path has either a drive separator (on Windows) or a space. How should I escape those before setting the String path in setIcon()?

KnimeNodeDocument doc = KnimeNodeDocument.Factory.newInstance();
KnimeNode node = doc.addNewKnimeNode();
URL iconURL = DynamicNodePlugin.getDefault().getBundle().getEntry(
        "/icons/schrodinger64.png");
iconURL = FileLocator.resolve(iconURL);
node.setIcon(iconURL.toURI().getPath());

Hi @ravikiran,
can you tell me which error you are encountering exactly (Exception / Error Message etc.)?
I think this is probably an encoding issue, can you inspect the urls to see whether the drive separators and spaces are escaped?
Also, did you try just setting the bundle relative path directly as the node icon? That should make this much easier.

best,
Gabriel

Hi Gabriel,

did you try just setting the bundle relative path directly as the node icon? That should make this much easier.

This worked like a charm.

Thanks
Ravikiran