Hi Barry,
re:
> Hope someone will come up with the answer why the nod file won't load from the code I've posted.
Well a couple things - moi.ui.commandUI.loadNodeFile() won't work because moi.ui.commandUI is for accessing the UI in the command options area in the upper right area of the main window. Like where the width and height fields are shown when you're drawing a rectangle.
The node editor isn't located there, it's in a dialog not in "command UI".
Another thing is that you will need to wait until the dialog has finished loading before you can access it.
Also there is not any function named loadNodeFile() in the node editor.
Here is an example of waiting for the dialog to be loaded. Then I think you will need to copy the code from Editor.prototype.onLoadButton in editor.js .
code:
var g_dlg = null;
var g_filePath = '';
function handleOnLoad() {
// You can access LiteGraph here.
moi.ui.alert( g_dlg.htmlWindow.LiteGraph );
}
function openNodeFile() {
try {
// Open the file selection dialog
g_filePath = moi.filesystem.getOpenFileName('Open', 'MoI Nodeeditor files (*.nod)|*.nod');
if (!g_filePath) {
moi.ui.alert('No file selected.');
return; // Exit if no file is selected
}
// Alert the selected file path
moi.ui.alert('File selected: ' + g_filePath);
// Open the Nodeditor dialog with the correct path
g_dlg = moi.ui.createDialog('moi://appdata/nodeeditor/index.html?scheme=Light', 'resizeable,defaultWidth:680,defaultHeight:420', moi.ui.mainWindow);
// Need to wait for the dialog to finish loading before accessing it.
// You can push global variables onto it now but the regular content in it isn't loaded yet.
g_dlg.htmlWindow.addEventListener( 'load', handleOnLoad );
} catch (error) {
moi.ui.alert('Error: ' + error.message);
}
}
// Run the openNodeFile function
openNodeFile();
|