[Maya-Python] Re: Procedurally determining the number of submenus

2015-10-09 Thread Robert White
So, subMenus are really just menus, which means you can query the itemArray 
value and get a list of their children, if that list is empty, you've got 
an empty subMenu. 

I've got an example of how to search a top level menu recursively and 
return a list of all the empty subMenus:
https://gist.github.com/bob-white/322e0e77f8d21468b8e2

One annoyance with the itemArray query, is that it returns the short name 
of the menuItem, so you need to combine it with it's parent to query any of 
it's children. But otherwise it just works.

On Thursday, October 8, 2015 at 8:36:32 PM UTC-5, Ken Ibrahim wrote:
>
> Silly question here but I haven't figured this out yet nor come across the 
> answer online.
>
> What's the best way to determine the number of submenus a menuItem has 
> after it's been created? I have a system that dynamically adds menu items 
> based on certain criteria. After that work is done I'd like to disable the 
> menu (or remove it) if the total number of children is zero.
>
> Assume that I cannot get the number of items explicitly before creating 
> the menu and that I'm using PyMEL's "with" nested structure to create the 
> menu hierarchy.
>
> Thx!
>
> Ken
>
> -- 
> "God is a metaphor for a mystery that absolutely transcends all human 
> categories of thought. It's as simple as that!" - Joseph Campbell
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/ed6170c2-5521-41c3-9c59-45f9b58e1895%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Re: Procedurally determining the number of submenus

2015-10-09 Thread Kenneth Ibrahim
Thx for the response. I had thought that was the case and had tried using
PyMEL's 'getNumberOfItems' method to no avail. I'll have a look at your
code reference and see what I was doing wrong.

Cheers! Ken

On Fri, Oct 9, 2015 at 12:03 AM, Robert White 
wrote:

> So, subMenus are really just menus, which means you can query the
> itemArray value and get a list of their children, if that list is empty,
> you've got an empty subMenu.
>
> I've got an example of how to search a top level menu recursively and
> return a list of all the empty subMenus:
> https://gist.github.com/bob-white/322e0e77f8d21468b8e2
>
> One annoyance with the itemArray query, is that it returns the short name
> of the menuItem, so you need to combine it with it's parent to query any of
> it's children. But otherwise it just works.
>
> On Thursday, October 8, 2015 at 8:36:32 PM UTC-5, Ken Ibrahim wrote:
>>
>> Silly question here but I haven't figured this out yet nor come across
>> the answer online.
>>
>> What's the best way to determine the number of submenus a menuItem has
>> after it's been created? I have a system that dynamically adds menu items
>> based on certain criteria. After that work is done I'd like to disable the
>> menu (or remove it) if the total number of children is zero.
>>
>> Assume that I cannot get the number of items explicitly before creating
>> the menu and that I'm using PyMEL's "with" nested structure to create the
>> menu hierarchy.
>>
>> Thx!
>>
>> Ken
>>
>> --
>> "God is a metaphor for a mystery that absolutely transcends all human
>> categories of thought. It's as simple as that!" - Joseph Campbell
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/ed6170c2-5521-41c3-9c59-45f9b58e1895%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"God is a metaphor for a mystery that absolutely transcends all human
categories of thought. It's as simple as that!" - Joseph Campbell

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAP_aC5bA%2Bqzbqs0WCe_DrkzJkAWO_qyWtV2fRREDJV%3D8_akHvA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Re: Procedurally determining the number of submenus

2015-10-09 Thread Kenneth Ibrahim
Correct, I only know after the fact.

I got it working by running the following: pm.menu(my_menu, q=True,
numberOfItems=True)

I was trying to be more Pythonic via PyMEL by running this:
my_menu.getNumberOfItems() but that method apparently doesn't exist for the
menu item (which is of type commandMenuItem I think). Again I must be
overlooking something silly in my access attempt here.

On Fri, Oct 9, 2015 at 9:57 AM, Marcus Ottosson 
wrote:

> Just to perhaps state the obvious, I suppose ideally you would look at the
> items you are *about* to create and determine whether or not to create the
> menu in the first place, but maybe that's not an option in this case?
>
> On 9 October 2015 at 18:02, Kenneth Ibrahim  wrote:
>
>> Thx for the response. I had thought that was the case and had tried using
>> PyMEL's 'getNumberOfItems' method to no avail. I'll have a look at your
>> code reference and see what I was doing wrong.
>>
>> Cheers! Ken
>>
>> On Fri, Oct 9, 2015 at 12:03 AM, Robert White 
>> wrote:
>>
>>> So, subMenus are really just menus, which means you can query the
>>> itemArray value and get a list of their children, if that list is empty,
>>> you've got an empty subMenu.
>>>
>>> I've got an example of how to search a top level menu recursively and
>>> return a list of all the empty subMenus:
>>> https://gist.github.com/bob-white/322e0e77f8d21468b8e2
>>>
>>> One annoyance with the itemArray query, is that it returns the short
>>> name of the menuItem, so you need to combine it with it's parent to query
>>> any of it's children. But otherwise it just works.
>>>
>>> On Thursday, October 8, 2015 at 8:36:32 PM UTC-5, Ken Ibrahim wrote:

 Silly question here but I haven't figured this out yet nor come across
 the answer online.

 What's the best way to determine the number of submenus a menuItem has
 after it's been created? I have a system that dynamically adds menu items
 based on certain criteria. After that work is done I'd like to disable the
 menu (or remove it) if the total number of children is zero.

 Assume that I cannot get the number of items explicitly before creating
 the menu and that I'm using PyMEL's "with" nested structure to create the
 menu hierarchy.

 Thx!

 Ken

 --
 "God is a metaphor for a mystery that absolutely transcends all human
 categories of thought. It's as simple as that!" - Joseph Campbell

>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Python Programming for Autodesk Maya" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to python_inside_maya+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/python_inside_maya/ed6170c2-5521-41c3-9c59-45f9b58e1895%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> "God is a metaphor for a mystery that absolutely transcends all human
>> categories of thought. It's as simple as that!" - Joseph Campbell
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to python_inside_maya+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/python_inside_maya/CAP_aC5bA%2Bqzbqs0WCe_DrkzJkAWO_qyWtV2fRREDJV%3D8_akHvA%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *Marcus Ottosson*
> konstrukt...@gmail.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAD5YWpvHVZAg3Rfj4BXw_26fQJQWndj%2B6QtnugLZBVaw%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"God is a metaphor for a mystery that absolutely transcends all human
categories of thought. It's as simple as that!" - Joseph Campbell

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" 

Re: [Maya-Python] Re: Procedurally determining the number of submenus

2015-10-09 Thread Robert White
Your not overlooking anything, MenuItem, and CommandMenuItem don't have the 
same methods on them that Menu does. Basically MenuItems and 
CommandMenuItems can't have any children, because they aren't Menus, but 
once you've set subMenu=True, the item returned is now a Menu, it can 
possibly have children.

So another thing you could attempt, would be just duck typing the whole 
affair by wrapping your call to getNumberOfItems() in a try / except block 
that catch's AttributeErrors, these would obviously fail on 
MenuItems/CommandMenuItems, but would return properly for Menus, this would 
let you continue to use the PyMel convenience methods, and is certainly 
considered 'pythonic'.

On Friday, October 9, 2015 at 12:11:32 PM UTC-5, Ken Ibrahim wrote:
>
> Correct, I only know after the fact.
>
> I got it working by running the following: pm.menu(my_menu, q=True, 
> numberOfItems=True)
>
> I was trying to be more Pythonic via PyMEL by running this: 
> my_menu.getNumberOfItems() but that method apparently doesn't exist for the 
> menu item (which is of type commandMenuItem I think). Again I must be 
> overlooking something silly in my access attempt here.
>
> On Fri, Oct 9, 2015 at 9:57 AM, Marcus Ottosson  > wrote:
>
>> Just to perhaps state the obvious, I suppose ideally you would look at 
>> the items you are *about* to create and determine whether or not to create 
>> the menu in the first place, but maybe that's not an option in this case?
>>
>> On 9 October 2015 at 18:02, Kenneth Ibrahim > > wrote:
>>
>>> Thx for the response. I had thought that was the case and had tried 
>>> using PyMEL's 'getNumberOfItems' method to no avail. I'll have a look at 
>>> your code reference and see what I was doing wrong.
>>>
>>> Cheers! Ken
>>>
>>> On Fri, Oct 9, 2015 at 12:03 AM, Robert White >> > wrote:
>>>
 So, subMenus are really just menus, which means you can query the 
 itemArray value and get a list of their children, if that list is empty, 
 you've got an empty subMenu. 

 I've got an example of how to search a top level menu recursively and 
 return a list of all the empty subMenus:
 https://gist.github.com/bob-white/322e0e77f8d21468b8e2

 One annoyance with the itemArray query, is that it returns the short 
 name of the menuItem, so you need to combine it with it's parent to query 
 any of it's children. But otherwise it just works.

 On Thursday, October 8, 2015 at 8:36:32 PM UTC-5, Ken Ibrahim wrote:
>
> Silly question here but I haven't figured this out yet nor come across 
> the answer online.
>
> What's the best way to determine the number of submenus a menuItem has 
> after it's been created? I have a system that dynamically adds menu items 
> based on certain criteria. After that work is done I'd like to disable 
> the 
> menu (or remove it) if the total number of children is zero.
>
> Assume that I cannot get the number of items explicitly before 
> creating the menu and that I'm using PyMEL's "with" nested structure to 
> create the menu hierarchy.
>
> Thx!
>
> Ken
>
> -- 
> "God is a metaphor for a mystery that absolutely transcends all human 
> categories of thought. It's as simple as that!" - Joseph Campbell
>
 -- 
 You received this message because you are subscribed to the Google 
 Groups "Python Programming for Autodesk Maya" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to python_inside_maya+unsubscr...@googlegroups.com 
 .
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/python_inside_maya/ed6170c2-5521-41c3-9c59-45f9b58e1895%40googlegroups.com
  
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>>
>>>
>>>
>>> -- 
>>> "God is a metaphor for a mystery that absolutely transcends all human 
>>> categories of thought. It's as simple as that!" - Joseph Campbell
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Python Programming for Autodesk Maya" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to python_inside_maya+unsubscr...@googlegroups.com 
>>> .
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/python_inside_maya/CAP_aC5bA%2Bqzbqs0WCe_DrkzJkAWO_qyWtV2fRREDJV%3D8_akHvA%40mail.gmail.com
>>>  
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> *Marcus Ottosson*
>> 

Re: [Maya-Python] Re: Procedurally determining the number of submenus

2015-10-09 Thread Kenneth Ibrahim
Thx for the clarification!

On Fri, Oct 9, 2015 at 10:24 AM, Robert White 
wrote:

> Your not overlooking anything, MenuItem, and CommandMenuItem don't have
> the same methods on them that Menu does. Basically MenuItems and
> CommandMenuItems can't have any children, because they aren't Menus, but
> once you've set subMenu=True, the item returned is now a Menu, it can
> possibly have children.
>
> So another thing you could attempt, would be just duck typing the whole
> affair by wrapping your call to getNumberOfItems() in a try / except block
> that catch's AttributeErrors, these would obviously fail on
> MenuItems/CommandMenuItems, but would return properly for Menus, this would
> let you continue to use the PyMel convenience methods, and is certainly
> considered 'pythonic'.
>
> On Friday, October 9, 2015 at 12:11:32 PM UTC-5, Ken Ibrahim wrote:
>>
>> Correct, I only know after the fact.
>>
>> I got it working by running the following: pm.menu(my_menu, q=True,
>> numberOfItems=True)
>>
>> I was trying to be more Pythonic via PyMEL by running this:
>> my_menu.getNumberOfItems() but that method apparently doesn't exist for the
>> menu item (which is of type commandMenuItem I think). Again I must be
>> overlooking something silly in my access attempt here.
>>
>> On Fri, Oct 9, 2015 at 9:57 AM, Marcus Ottosson 
>> wrote:
>>
>>> Just to perhaps state the obvious, I suppose ideally you would look at
>>> the items you are *about* to create and determine whether or not to create
>>> the menu in the first place, but maybe that's not an option in this case?
>>>
>>> On 9 October 2015 at 18:02, Kenneth Ibrahim  wrote:
>>>
 Thx for the response. I had thought that was the case and had tried
 using PyMEL's 'getNumberOfItems' method to no avail. I'll have a look at
 your code reference and see what I was doing wrong.

 Cheers! Ken

 On Fri, Oct 9, 2015 at 12:03 AM, Robert White 
 wrote:

> So, subMenus are really just menus, which means you can query the
> itemArray value and get a list of their children, if that list is empty,
> you've got an empty subMenu.
>
> I've got an example of how to search a top level menu recursively and
> return a list of all the empty subMenus:
> https://gist.github.com/bob-white/322e0e77f8d21468b8e2
>
> One annoyance with the itemArray query, is that it returns the short
> name of the menuItem, so you need to combine it with it's parent to query
> any of it's children. But otherwise it just works.
>
> On Thursday, October 8, 2015 at 8:36:32 PM UTC-5, Ken Ibrahim wrote:
>>
>> Silly question here but I haven't figured this out yet nor come
>> across the answer online.
>>
>> What's the best way to determine the number of submenus a menuItem
>> has after it's been created? I have a system that dynamically adds menu
>> items based on certain criteria. After that work is done I'd like to
>> disable the menu (or remove it) if the total number of children is zero.
>>
>> Assume that I cannot get the number of items explicitly before
>> creating the menu and that I'm using PyMEL's "with" nested structure to
>> create the menu hierarchy.
>>
>> Thx!
>>
>> Ken
>>
>> --
>> "God is a metaphor for a mystery that absolutely transcends all human
>> categories of thought. It's as simple as that!" - Joseph Campbell
>>
> --
> You received this message because you are subscribed to the Google
> Groups "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/ed6170c2-5521-41c3-9c59-45f9b58e1895%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



 --
 "God is a metaphor for a mystery that absolutely transcends all human
 categories of thought. It's as simple as that!" - Joseph Campbell

 --
 You received this message because you are subscribed to the Google
 Groups "Python Programming for Autodesk Maya" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to python_inside_maya+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/python_inside_maya/CAP_aC5bA%2Bqzbqs0WCe_DrkzJkAWO_qyWtV2fRREDJV%3D8_akHvA%40mail.gmail.com