Getting the ICE tree view from a menu callback

How do you get the ICE Tree view in a menu callback? For example, if you add a menu item to the ICE Tree > User Tools, how does the menu item callback get the ICE Tree view?

The answer is actually in code I posted before, but that was in a blog post titled Getting the selected ICE nodes. So, with that title, you wouldn’t necessarily think to look there.

So what’s the answer? Uses Context.GetAttribute( “Target” ). For custom menus in the views like the ICE Tree view, the Fcurve Editor, and the Material Manager, the Target attribute is the View object. And once you have the View object, you can get the View attributes.

# Callback added to the menu item with Menu.AddCallbackItem
def My_menuItem_Callback( in_ctxt ):

	# Get the ICE Tree view
	oView = in_ctxt.GetAttribute("Target")
	LogMessage( 'View: ' + oView.Name )
	# get the selected nodes
	nodes = oView.GetAttributeValue('selection')
	LogMessage( 'Selected nodes: ' + nodes )

Soapbox alert…
This post illustrates why indexes are a good thing…with them, you can find information no matter what page or heading contains the information.
For ICE trees, you’d have index entries something like this:

  • ICE tree
    • view attributes
      • target
      • container
    • selected nodes, getting
    • view, getting
    • ICETree node, getting

1 thought on “Getting the ICE tree view from a menu callback

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s