Page 1 of 1

methodArguments popupMenu

PostPosted: Thu Aug 09, 2012 10:55 am
by DEK4
Hello,
i try to pass an argument to my function with popupmenu but nothig...

this is my menu:

Code: Select all
var menu = plugins.window.createPopupMenu()
_sub = menu.addMenuItem()
_sub.text = 'text'
_sub.setMethod(new1)
_sub.methodArguments = [1, "data"]


my function:
Code: Select all
function new1(args) {
   application.output(args[0])
}


i want to pass also the event is it possible?

thanks

Re: methodArguments popupMenu

PostPosted: Thu Aug 09, 2012 1:06 pm
by Joas
There are a couple of default arguments that will always be passed to a method triggered by the popupmenu, your argument will start at index 5.
See the comment in the sample code:
Code: Select all
// set the arguments to be sent to the callback method
// (an array of elements which will be passed as arguments 5, 6 and so on to the callback method)
// the first 5 arguments are fixed:
//   [0] item index
//   [1] parent item index
//   [2] isSelected boolean
//   [3] parent menu text
//   [4] menu text
entry.methodArguments = [17, "data"];

Re: methodArguments popupMenu

PostPosted: Thu Aug 09, 2012 2:43 pm
by DEK4
Thanks for your answer.
I tried but nothig...it prints <null>


Code: Select all
_sub.methodArguments = ['asd', "data", 'pippo']


Code: Select all
/**
* @param {Array} args
* @properties={typeid:24,uuid:"30649593-2E51-4B39-AA5B-F67CB2EDE3BD"}
*/
function call(args) {
   for (var index = 0; index < args.length; index++) {
      application.output(args[index])
   }
   
}

Re: methodArguments popupMenu

PostPosted: Thu Aug 09, 2012 3:17 pm
by Joas
You expect the first argument to be an array, but that is not correct. All those values will be separate arguments.

Try this:
Code: Select all
function call(index, parentIndex, isSelected, parentText, text, yourFirstArgument, ....) {
   ...
}

Re: methodArguments popupMenu

PostPosted: Thu Aug 09, 2012 4:30 pm
by DEK4
Thanks...it works!!

Re: methodArguments popupMenu

PostPosted: Mon Jan 04, 2021 7:18 pm
by Westy
After eight years of not being able to pass parameters with the popupMenu I today stumbled upon this post (THANK YOU).

The following now works for me:

Code: Select all
/**
* @properties={typeid:24,uuid:"A43C20A4-35FE-4F93-8F4E-16B5A28D5689"}
*/
function showpopup(event) {
   var popupmenu = plugins.window.createPopupMenu()

   var menuitem1 = popupmenu.addMenuItem('Menu Text', globals.myGlobalMethod)
   //add arguments to the method call
   menuitem1.methodArguments = ['myInfo']

   var source = event.getSource()
   if (source != null) {
      popupmenu.show(source);
   }
}


Code: Select all
/**
* @param {String} itemIndex0
* @param {String} parentItemIndex1
* @param {String} isSelectedBoolean2
* @param {String} parentMenuText3
* @param {String} menuText4
* @param {String} arg5
*
* @properties={typeid:24,uuid:"77930261-9675-4270-A5AC-F4EC3E1BDB96"}
*/
function myGlobalMethod(itemIndex0, parentItemIndex1, isSelectedBoolean2, parentMenuText3, menuText4, arg5) {
   application.output(arg5);
}


Dean Westover, President
Choices Software, Inc.

Re: methodArguments popupMenu

PostPosted: Tue Jan 05, 2021 10:06 am
by Joas
Haha, glad to have helped! :)