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 <[email protected] 
> <javascript:>> 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 <[email protected] 
>> <javascript:>> 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 <[email protected] 
>>> <javascript:>> 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 [email protected] 
>>>> <javascript:>.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/python_inside_maya/ed6170c2-5521-41c3-9c59-45f9b58e1895%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/python_inside_maya/ed6170c2-5521-41c3-9c59-45f9b58e1895%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> 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 [email protected] 
>>> <javascript:>.
>>> 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
>>>  
>>> <https://groups.google.com/d/msgid/python_inside_maya/CAP_aC5bA%2Bqzbqs0WCe_DrkzJkAWO_qyWtV2fRREDJV%3D8_akHvA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> *Marcus Ottosson*
>> [email protected] <javascript:>
>>
>> -- 
>> 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 [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAD5YWpvHVZAg3Rfj4BXw_26fQJQWndj%2B6QtnugLZBVaw%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAD5YWpvHVZAg3Rfj4BXw_26fQJQWndj%2B6QtnugLZBVaw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/ceba8f5a-437b-4c01-aba1-f3c7a37693f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to