Bertf Posted April 26 Share Posted April 26 (edited) 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 April 26 by Bertf Quote Link to comment
Jesse Cogswell Posted April 26 Share Posted April 26 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. 2 Quote Link to comment
Pat Stanford Posted April 26 Share Posted April 26 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. 1 Quote Link to comment
Bertf Posted April 27 Author Share Posted April 27 14 hours ago, Jesse Cogswell said: Did you have ChatGPT generate this code? Busted. 😁 Thanks for the quick responds! I'll try them out now. 1 Quote Link to comment
Bertf Posted April 27 Author Share Posted April 27 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. 1 Quote Link to comment
Pat Stanford Posted April 27 Share Posted April 27 I think you have to be logged into the forum, not just viewing as a guest to be able to download. I was able to download without issue. 1 Quote Link to comment
Recommended Posts
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.