Show messages: All
1-8
9-19
From: MO (MO_TE)
Hi Michael
Thanks for the info. I'll try it out later. :)
From: Michael Gibson
Hi Mo, something like this for a script to find the node editor object from script running outside of the node editor dialog.
code:
var uipanels = moi.ui.getUIPanels();
for ( var i = 0; i < uipanels.length; ++i )
{
var uipanel = uipanels.item(i);
// uipanel is the HTML window object that holds global variables.
// Find the one that has "nodeeditor" somewhere in it's URL:
moi.ui.alert( uipanel.document.URL );
}
If there is a global variable on the node editor dialog named LiteGraph then you should be able to do uipanel.LiteGraph.editor
- Michael
From: MO (MO_TE)
Thank you Michael. Yes, It found the "LiteGraph" variable and works very well.
I'll try again later. :)
From: Michael Gibson
Hi Mo, also maybe instead of looking at the URL it may be better to look for that global variable existing.
Something like this:
code:
var uipanels = moi.ui.getUIPanels();
for ( var i = 0; i < uipanels.length; ++i )
{
var uipanel = uipanels.item(i);
/* uipanel is the HTML window object that holds global variables. */
/* Find the one that has a global variable "LiteGraph". */
if ( uipanel.LiteGraph )
{
moi.ui.alert( 'found it' );
}
}
From: Barry-H
I have made some progress with the use of Copilot to this point.
1) on shortcut key file opens to pick nod file.
2) Nodeditor opens automatically on selection of nod file.
3) File fails to load with undifined error.
Problem with path I think.
Here's the JS code.
function openNodeFile() {
try {
// Open the file selection dialog
var filePath = moi.filesystem.getOpenFileName('Open', 'MoI Nodeeditor files (*.nod)|*.nod');
if (!filePath) {
moi.ui.alert('No file selected.');
return; // Exit if no file is selected
}
// Alert the selected file path
moi.ui.alert('File selected: ' + filePath);
// Open the Nodeditor dialog with the correct path
moi.ui.createDialog('moi://appdata/nodeeditor/index.html?scheme=Light', 'resizeable,defaultWidth:680,defaultHeight:420', moi.ui.mainWindow);
// Attempt to load the selected .nod file into the Nodeditor
// Placeholder for actual logic to load the file
// If `loadNodeFile` is not the correct method, replace this with the correct one
if (typeof moi.ui.commandUI.loadNodeFile === 'function') {
moi.ui.commandUI.loadNodeFile(filePath); // Replace with the correct method if necessary
moi.ui.alert('File loaded successfully.');
} else {
moi.ui.alert('Error: loadNodeFile method not found in moi.ui.commandUI.');
}
} catch (error) {
moi.ui.alert('Error: ' + error.message);
}
}
// Run the openNodeFile function
openNodeFile();
From: Frenchy Pilou (PILOU)
you are a valiant pioneer!
From: Barry-H
Thanks pilou,
Hope someone will come up with the answer why the nod file won't load from the code I've posted.
Anyway good experience playing with Ai
Cheers
From: Michael Gibson
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();
From: Michael Gibson
Hi Barry, so although there does not seem to be a loadNodeFile() function, you can give the node editor a parameter named 'file' in the URL's search string to tell it which file to load when it starts.
Like this:
code:
function openNodeFile() {
try {
// Open the file selection dialog
filePath = moi.filesystem.getOpenFileName('Open', 'MoI Nodeeditor files (*.nod)|*.nod');
if (!filePath) {
moi.ui.alert('No file selected.');
return; // Exit if no file is selected
}
// Alert the selected file path
moi.ui.alert('File selected: ' + filePath);
// Put parameter file=path.nod in the URL's search string to have it load the file.
var url = 'moi://appdata/nodeeditor/index.html?scheme=Light&file=' + filePath;
// Open the Nodeditor dialog with the correct path
moi.ui.createDialog(encodeURI(url), 'resizeable,defaultWidth:680,defaultHeight:420', moi.ui.mainWindow);
} catch (error) {
moi.ui.alert('Error: ' + error.message);
}
}
// Run the openNodeFile function
openNodeFile();
From: Michael Gibson
Hi Barry, so the part about telling the node editor which file to load using a file= parameter in the URL is a little buggy in the node editor code.
To fix it, open the node editor file init.js and find this on line number 44:
code:
var data = '', loadFilePath = NeParameters.file.replace(/%5C/g,"\\");
change it to this instead:
code:
var data = '', loadFilePath = decodeURIComponent(NeParameters.file);
Then the code to use it should go like this:
code:
function openNodeFile() {
try {
// Open the file selection dialog
filePath = moi.filesystem.getOpenFileName('Open', 'MoI Nodeeditor files (*.nod)|*.nod');
if (!filePath) {
moi.ui.alert('No file selected.');
return; // Exit if no file is selected
}
// Alert the selected file path
moi.ui.alert('File selected: ' + filePath);
// Put parameter file=path.nod in the URL's search string to have it load the file.
var url = 'moi://appdata/nodeeditor/index.html?scheme=Light&file=' + encodeURIComponent(filePath);
// Open the Nodeditor dialog with the correct path
moi.ui.createDialog(url, 'resizeable,defaultWidth:680,defaultHeight:420', moi.ui.mainWindow);
} catch (error) {
moi.ui.alert('Error: ' + error.message);
}
}
// Run the openNodeFile function
openNodeFile();
From: Barry-H
Thanks Michael,
works fine now.
Cheers
Barry
Show messages: All
1-8
9-19