Toggle sceneplate with python

Toggle sceneplate with python

Anonymous
Not applicable
1,936 Views
16 Replies
Message 1 of 17

Toggle sceneplate with python

Anonymous
Not applicable

Is there any way to control sceneplate switch on and off via python?

 

Thanks

Hiroshi

0 Likes
Accepted solutions (1)
1,937 Views
16 Replies
Replies (16)
Message 2 of 17

seiferp
Community Manager
Community Manager

Sure...

 

vrdSwitchNode(vrSceneplateService.getRootNode().getChild(1)).setChoice(0)

This will select the 1st frontplate in the 2nd switch...

Sceneplate Editor.png

 

Pascal

0 Likes
Message 3 of 17

sinje_thiedemann
Autodesk
Autodesk

Or, if your node name is unique in the Sceneplate Editor, use findNode.

Of course this can also be done in one line as posted by Pascal but here are the individual steps:

node = vrSceneplateService.findNode("MySwitch") # this returns a vrdNode object
switch = vrdSwitchNode(node) # convert it to a switch node
switch.setChoice(0) # set the choice

 

0 Likes
Message 4 of 17

sinje_thiedemann
Autodesk
Autodesk
Accepted solution

If your question was not about Switch nodes but frontplates/backplates:

node = vrSceneplateService.findNode("My Frontplate")
vrdSceneplateNode(node).setVisibilityFlag(False) # hides the front plate

setVisibilityFlag is a function of vrdSceneplateNode's base class vrdNode.

Message 5 of 17

Anonymous
Not applicable

Yes, I mean toggle visibility, so that works perfect!

 

Thanks

 

 

0 Likes
Message 6 of 17

marc.winter2
Advocate
Advocate

Hi Pascal,

 

is there also a python-way to (de-)activate Sceneplates (maybe individual for front- and backplates) as it can be done with vredGui?

 

Best regards,

Marc

0 Likes
Message 7 of 17

seiferp
Community Manager
Community Manager

You want to control the viewport option that can be found in the menu bar?

 2020-01-09 11_16_15-untitled - Autodesk VRED Professional 2021 Beta.png

This is currently not possible but we have a ticket for it in the backlog.

0 Likes
Message 8 of 17

thorsten.droell
Autodesk
Autodesk

Hi Marc,

 

I guess this is not what you want but maybe you can use it, this simply sets the visibility flag of all sceneplates, it takes the type of the plate (front or back) into account.

for sp in vrSceneplateService.getAllSceneplates():
    if sp.getNodeType() == vrSceneplateTypes.NodeType.Frontplate:
        sp.setVisibilityFlag(False)
    if sp.getNodeType() == vrSceneplateTypes.NodeType.Backplate:
        sp.setVisibilityFlag(True) 
0 Likes
Message 9 of 17

marc.winter2
Advocate
Advocate

Hi Pascal,

yes this what i want.

So i'll wait.

Thx.

Marc

0 Likes
Message 10 of 17

marc.winter2
Advocate
Advocate

Hi Thorsten,

 

Thanks for your answer.

But you are right, this is not what i'm looking for.

 

Best regards,

Marc

0 Likes
Message 11 of 17

cjess
Enthusiast
Enthusiast

Hi Marc -

I was wondering about toggling the sceneplates just like via GUI as well.

If you're not aware of this yet, they just added a command for 2021.2

 

enableSceneplates(bool)

 

It works great.

 

-Chris

 

0 Likes
Message 12 of 17

seiferp
Community Manager
Community Manager

The Sceneplate Module is fully decoupled with the Python 2 API if you want to fiddle inside the Sceneplates itself. 

If you want to toggle the global switch from the menu bar on and off we have added the following commands to the latest 2021.2 release!

enableBackplates(), getBackplatesEnabled()
enableFrontplates(), getFrontplatesEnabled()
enableSceneplates(), getSceneplatesEnabled()

 

Message 13 of 17

cjess
Enthusiast
Enthusiast

hi Pascal - @seiferp 

Sorry to resurrect this post again, but I was looking at your code

 

 

vrdSwitchNode(vrSceneplateService.getRootNode().getChild(2)).setChoice(0)

 

 

This works great but I would like to call a specific sceneplate in a specific switch by name. That way if a new sceneplate or switch gets added to the file or the sceneplates get rearranged in the Sceneplate Editor my script will still work as it's not bound to a specific order - like child 2 and choice 0 in your example.

 

Looking at the image you posted I want to call "Frontplate2" in "Switch1" even if 'Switch1' gets moved above 'Switch'.

 

I was hoping selectNodeVariant would work just like for geometry switches or selectMaterialVariant for Materials.

With that logic I woul hope for a command like this:

   selectSceneplateVariant("SceneplateSwitch", "SceneplateOption")

 

But that doesn't work...

Thanks for your help!

-Chris

0 Likes
Message 14 of 17

thorsten.droell
Autodesk
Autodesk

Hi Chris,

 

maybe you are looking for something like this:

switch = vrdSwitchNode(vrSceneplateService.findNode("Switch1"))
frontplate = vrSceneplateService.findNode("Frontplate1")
childIndex = switch.getChildIndex(frontplate)
switch.setChoice(childIndex)

Best regards

 

Thorsten

0 Likes
Message 15 of 17

cjess
Enthusiast
Enthusiast

Thank you Thorsten - this works.

It's a bit complicated, I was hoping for a single line as mentioned before. Considering you can access other variants easily (for example geometry & materials) I will write this up as a request.

 

Have a good day and stay healthy.

0 Likes
Message 16 of 17

Simon.Nagel
Alumni
Alumni

Hi Chris,

maybe this one helps:

https://github.com/simonnagel/VRED-snippets/blob/master/VRED-toggleToNextSceneplate.py

 

This script uses the pageup and pagedown buttons on your keyboard to toogle through all children of a sceneplate node called "TextSwitch".

 

 

0 Likes
Message 17 of 17

cjess
Enthusiast
Enthusiast

Hi @Simon.Nagel 

Thank you for that script. Interesting setup, but I am not using hotkeys at this point for what I am doing. 

I have submitted a request (and will probably do so as well through our support account) that you can see here:

https://forums.autodesk.com/t5/vred-ideas/simple-python-sceneplate-switch/idi-p/9807682 

The idea being that sceneplates should be accessible just like a material or geometry switch. The fact that Sceneplate switches show up in the Variants window tells me that this should work.

Calling a specific sceneplate as well as a !Next or !Previous function should work as well.

 

If anyone in this thread agrees upvote the idea at the above link! 😁

 

Thanks,

Chris

0 Likes