Jump to content

Toggle between wireframe and shaded render mode with shortcut


Recommended Posts

Hi,


I want to be able to toggle between wireframe and shaded view on my design layer with a simple shortcut key combination.

 

I'm trying to do it with a script. Can anyone point me in the right direction for the commands? I do find the wiki and git a bit uncomplete to find these commands. 
I also tried to use DoMenuTextByName but that didn't seem to work for setting the render mode.

 

A bit of the (not working) script logic: 

(doesn't matter if it's in python or vs for me)

 

import vs

# Get the current render mode
current_mode = vs.GetRenderMode()

# Check and toggle
if current_mode == 2:  # Wireframe
    vs.SetRenderMode(6)  # Set to Shaded
else:
    vs.SetRenderMode(2)  # Set to Wireframe
 

 

I know, you can put a shortcut on "shaded" and another one on wireframe. But I'd rather have it the same button to toggle between the 2 states.

 

 

Thanks,

Bert

Edited by Bertf
Link to comment

One of the issues with your script is that there is no GetRenderMode or SetRenderMode function in the Vectorscript or Python library.  Instead, you'll want to try to use vs.GetLayerRenderMode and vs.SetLayerRenderMode.  Did you have ChatGPT generate this code?

 

This is what you want your code to look like:

import vs

# Get the current render mode
current_mode = vs.GetLayerRenderMode(vs.ActLayer())

# Check and toggle
if current_mode == 0:  # Wireframe
    vs.SetLayerRenderMode(vs.ActLayer(),11,True,True)  # Set to Shaded
else:
    vs.SetLayerRenderMode(vs.ActLayer(),0,True,True)  # Set to Wireframe

 

One thing to note is that when you run code, the view won't immediately change.  You'll want to make sure that you are in a 3D view and not Top/Plan, and after running the script, pan the drawing slightly and you'll see the change.  I didn't spend a lot of time on this, but even with the vs.ReDrawAll() function, I wasn't able to successfully force redraw the screen to make the change immediately take.

  • Like 2
Link to comment

I could not make SetLayerRenderMode to work in either Python or Vectorscript. Even with redraws and rest objects.

 

I dropped back to DoMenuTextByName.

 

import vs
# Get the current render mode
current_mode = vs.GetLayerRenderMode(vs.ActLayer())
# Check and toggle
if current_mode == 11:  # Wireframe
    vs.DoMenuTextByName('Wireframe Render Chunk', 1)  # Set to Shaded
else:
    vs.DoMenuTextByName('OpenGL Render Chunk', 1)  # Set to Wireframe

 

The following thread has a tutorial on how to make a script into a Plugin Menu command and how to add that command to your workspace and add a keyboard shortcut.

 

 

 

  • Like 1
Link to comment

Thanks Jesse for your input.

Thanks Pat for the script and link.

 

I went for Pat's script so I don't have to do the panning. I can confirm this work flawless. Thanks!

I just want to let you know that the pdf "SST-Add a Command to a Workspace..." on your linked post isn't downloading for me though. Might be broken?

But I've been able to add it as a menu item and add a shortcut to it with the workspace editor.

 

Thanks again. 

  • Like 1
Link to comment

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.   Restore formatting

  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...