DEK4
August 9, 2012, 8:55am
1
Hello,
i try to pass an argument to my function with popupmenu but nothig…
this is my menu:
var menu = plugins.window.createPopupMenu()
_sub = menu.addMenuItem()
_sub.text = 'text'
_sub.setMethod(new1)
_sub.methodArguments = [1, "data"]
my function:
function new1(args) {
application.output(args[0])
}
i want to pass also the event is it possible?
thanks
Joas
August 9, 2012, 11:06am
2
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:
// 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"];
DEK4
August 9, 2012, 12:43pm
3
Thanks for your answer.
I tried but nothig…it prints
_sub.methodArguments = ['asd', "data", 'pippo']
/**
* @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])
}
}
Joas
August 9, 2012, 1:17pm
4
You expect the first argument to be an array, but that is not correct. All those values will be separate arguments.
Try this:
function call(index, parentIndex, isSelected, parentText, text, yourFirstArgument, ....) {
...
}
Westy
January 4, 2021, 5:18pm
6
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:
/**
* @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);
}
}
/**
* @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.
Joas
January 5, 2021, 8:06am
7
Haha, glad to have helped!