Jump to content

Return Item name of ordered Menu


freko12

Recommended Posts

Hi, I have been struggling with this for the past 2 days.

I need help in returning the name of the selected item in an ordered menu.

 

What I am trying to achieve is to dynamically populate the ordered menu with the list of projects via menu scrip (python)

import os
path="k:/Projects/"
dirList = os.listdir(path)
dirs = []
for dirName in dirList:
    fullPath = os.path.normpath(os.path.join(path, dirName))
    if os.path.isdir(fullPath):
          #dirs += [fullPath, dirName]
          dirs += [dirName, dirName]

          
return dirs

This code scans for folders in directory(k:/Projects/) and lists them in the menu. All works fine till here.

 

Now I need to return the name value of the selected menu item from another parameter.
So I have tried this

listItemName = hou.pwd().parm("parmList_Projects").eval()

and this

listItemName =  hou.pwd().parm("parmList_Projects").evalAsString()

but it returns only integer values from (0,1,2,...)

How can I get the name or label value ?

Edited by freko12
Link to comment
Share on other sites

3 hours ago, Stalkerx777 said:

It's easier to use a String type parameter (with a menu) for this instead of ordered menu. This way, eval() will return a string.

Wow it worked like a charm. How come I overlooked this!

Thanks a ton Stalkerx777

Cheers!

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...