Page 1 of 1

Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 17:55
by TwirlySocrates
Hi,

When I'm compositing, I noticed that there's a difference between selecting a node in the explorer (located in Scene_Root.FxTree.nodeName), and selecting a node in the compositing window. If I click a node in the GUI, it doesn't affect the highlighted node in the Explorer.

I'm trying to use a python script to return a list of selected objects in the compositing window. I can use "Application.Selection", but that returns the list of nodes/objects selected in the explorer, not in the compositing window.

Any help would be most appreciated :-)

Re: Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 18:52
by EricTRocks
You probably have to find the FX Tree view object via the Application.Desktop.Views collection or something like that. Once you have the view there should be a view attribute that gives you a string of the selected nodes which you can then split out for your needs.

Re: Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 19:13
by TwirlySocrates
EricTRocks wrote:You probably have to find the FX Tree view object via the Application.Desktop.Views collection or something like that. Once you have the view there should be a view attribute that gives you a string of the selected nodes which you can then split out for your needs.
Hi, thanks for your reply.
Would you know of any documentation that could help me find what I need?

I'm still pretty new to XSI's python api, so if any guesswork is involved, I probably won't figure it out.

Re: Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 19:16
by EricTRocks

Re: Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 20:43
by csaez
Looks like fxtree does not implement any view attribute :/

Code: Select all

views = Application.Desktop.ActiveLayout.Views
v = views.Find("Fx Tree") or views.Find("View Manager").Views.Find("Fx Tree")
if v:
    print v.GetAttributeValue("selection")  # None

Re: Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 21:00
by xsisupport
It implements at least one attribute: targetcontent.
The doc page is hidden; FxTree isn't listed on the View Attributes page, but it is possible to find it through the search.

But even I find that Search page ... opaque.

Re: Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 21:21
by TwirlySocrates
csaez wrote:Looks like fxtree does not implement any view attribute :/

Code: Select all

views = Application.Desktop.ActiveLayout.Views
v = views.Find("Fx Tree") or views.Find("View Manager").Views.Find("Fx Tree")
if v:
    print v.GetAttributeValue("selection")  # None

Thanks for your reply - this code executes, but it returns

Code: Select all

None
when I have compositing nodes selected.
Is supposed to return a list... or maybe an object?

As xsisupport pointed out, the documentation hardly covers this at all. Even if I were able to find the Fx Tree page, it doesn't list "secection" as an attribute.

Re: Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 21:32
by TwirlySocrates
xsisupport wrote:It implements at least one attribute: targetcontent.
The doc page is hidden; FxTree isn't listed on the View Attributes page, but it is possible to find it through the search.

But even I find that Search page ... opaque.
Is there a command that can list attributes, so that I know what I can look for?

Re: Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 21:41
by luceric
Yikes, that requires and archeology search, because nobody bothered to update the doc, and the softimage sdk doc sucks in general.
It's only documented in Consulting release documents.

The view attribute "selectednodes" was added in Softimage 2014

SOFT-8036 QFE: Please add view attributes support for the Fx Tree.
Nudity warning: [ Show ]
NewScene, false
set oTree = CreateFxTree
AddFxOp oTree, "EdgeDetect"
set oTree = CreateFxTree
AddFxOp oTree, "File Input"
AddFxOp oTree, "Noise"
OpenView "Fx Tree"
set oFxView = Desktop.ActiveLayout.Views( "Fx Tree" )
LogMessage( oFxView.GetAttributeValue( "targetcontent" ) )
LogMessage( oFxView.GetAttributeValue( "selectednodes" ) )
' See result 1

set oFxView = Desktop.ActiveLayout.Views( "Fx Tree" )
oFxView.SetAttributeValue "targetcontent", "FxTree1"
LogMessage( oFxView.GetAttributeValue( "targetcontent" ) )
' See result 2

set oFxView = Desktop.ActiveLayout.Views( "Fx Tree" )
oFxView.SetAttributeValue "selectednodes", "FxTree1.Noise"
LogMessage( oFxView.GetAttributeValue( "selectednodes" ) )
' See result 3

set oFxView = Desktop.ActiveLayout.Views( "Fx Tree" )
oFxView.SetAttributeValue "selectednodes", "FxTree1.FileIn"
LogMessage( oFxView.GetAttributeValue( "selectednodes" ) )
' See result 4

Re: Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 21:53
by xsisupport
TwirlySocrates wrote:
xsisupport wrote:It implements at least one attribute: targetcontent.
The doc page is hidden; FxTree isn't listed on the View Attributes page, but it is possible to find it through the search.

But even I find that Search page ... opaque.
Is there a command that can list attributes, so that I know what I can look for?
No. Unless something has changed, the only way I knew to find attributes was to grep the source code.

Re: Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 22:39
by TwirlySocrates
Thanks for your sample code... would you have anything that works in Soft 2012?
I tried using the attribute "selection" and it's only returning 'None'

Re: Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 23:12
by csaez
TwirlySocrates wrote:I tried using the attribute "selection" and it's only returning 'None'
I know, forget about that snippet, it was just a shot in the dark hoping to find some consistency with similar views, but it doesn't work.

Re: Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 23:13
by EricTRocks
As Luc-Eric said, the selected nodes view attribute was only added in 2014. Prior versions, you're out of luck.

Re: Python: Return list of selected compositing nodes

Posted: 15 Jan 2014, 23:17
by TwirlySocrates
EricTRocks wrote:As Luc-Eric said, the selected nodes view attribute was only added in 2014. Prior versions, you're out of luck.
Alrighty. Thank you.

Re: Python: Return list of selected compositing nodes

Posted: 16 Jan 2014, 00:11
by luceric
so.. why do you want that selection, what were you going to do with it

Re: Python: Return list of selected compositing nodes

Posted: 16 Jan 2014, 00:24
by TwirlySocrates
luceric wrote:so.. why do you want that selection, what were you going to do with it
I'm doing a lot of repetitive tasks in comp.

Some of these tasks would include:
* Arrange selected nodes in an evenly spaced horizontal line.
* Comp selected nodes together using "over" nodes at .5 opacity
* Comp selected nodes together using "over" nodes at 1.0 opacity

It's easy to do by hand, but when you have to do it all day, it would be easier to script.