Python: Return list of selected compositing nodes

Discussions concerning programming of SOFTIMAGE©
Post Reply
TwirlySocrates
Posts: 9
Joined: 15 Jan 2014, 02:47

Python: Return list of selected compositing nodes

Post by TwirlySocrates » 15 Jan 2014, 17:55

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 :-)

EricTRocks
Moderator
Posts: 754
Joined: 25 Nov 2009, 01:41
Contact:

Re: Python: Return list of selected compositing nodes

Post by EricTRocks » 15 Jan 2014, 18:52

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.
Eric Thivierge
Lead Kraken Developer, Fabric Engine
http://fabric-engine.github.io/Kraken

TwirlySocrates
Posts: 9
Joined: 15 Jan 2014, 02:47

Re: Python: Return list of selected compositing nodes

Post by TwirlySocrates » 15 Jan 2014, 19:13

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.


User avatar
csaez
Posts: 253
Joined: 09 Jul 2012, 15:31
Skype: csaezmargotta
Location: Sydney, Australia
Contact:

Re: Python: Return list of selected compositing nodes

Post by csaez » 15 Jan 2014, 20:43

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

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 11:02
Location: Montreal Canada
Contact:

Re: Python: Return list of selected compositing nodes

Post by xsisupport » 15 Jan 2014, 21:00

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.
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

TwirlySocrates
Posts: 9
Joined: 15 Jan 2014, 02:47

Re: Python: Return list of selected compositing nodes

Post by TwirlySocrates » 15 Jan 2014, 21:21

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.

TwirlySocrates
Posts: 9
Joined: 15 Jan 2014, 02:47

Re: Python: Return list of selected compositing nodes

Post by TwirlySocrates » 15 Jan 2014, 21:32

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?

luceric
Posts: 1251
Joined: 22 Jun 2009, 00:08

Re: Python: Return list of selected compositing nodes

Post by luceric » 15 Jan 2014, 21:41

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

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 11:02
Location: Montreal Canada
Contact:

Re: Python: Return list of selected compositing nodes

Post by xsisupport » 15 Jan 2014, 21:53

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.
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

TwirlySocrates
Posts: 9
Joined: 15 Jan 2014, 02:47

Re: Python: Return list of selected compositing nodes

Post by TwirlySocrates » 15 Jan 2014, 22:39

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'

User avatar
csaez
Posts: 253
Joined: 09 Jul 2012, 15:31
Skype: csaezmargotta
Location: Sydney, Australia
Contact:

Re: Python: Return list of selected compositing nodes

Post by csaez » 15 Jan 2014, 23:12

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.

EricTRocks
Moderator
Posts: 754
Joined: 25 Nov 2009, 01:41
Contact:

Re: Python: Return list of selected compositing nodes

Post by EricTRocks » 15 Jan 2014, 23:13

As Luc-Eric said, the selected nodes view attribute was only added in 2014. Prior versions, you're out of luck.
Eric Thivierge
Lead Kraken Developer, Fabric Engine
http://fabric-engine.github.io/Kraken

TwirlySocrates
Posts: 9
Joined: 15 Jan 2014, 02:47

Re: Python: Return list of selected compositing nodes

Post by TwirlySocrates » 15 Jan 2014, 23:17

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.

luceric
Posts: 1251
Joined: 22 Jun 2009, 00:08

Re: Python: Return list of selected compositing nodes

Post by luceric » 16 Jan 2014, 00:11

so.. why do you want that selection, what were you going to do with it

TwirlySocrates
Posts: 9
Joined: 15 Jan 2014, 02:47

Re: Python: Return list of selected compositing nodes

Post by TwirlySocrates » 16 Jan 2014, 00:24

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests