hello devs
I am having trouble toggling between render modes with code. Bellow is an example of what I am trying to do. Help is appreciated.
model = Sketchup.active_model # Open model
#Wireframe = Working Good
model.rendering_options['RenderMode']= 0
#Hidden Line = Working Good ... But why is it named hidden line though?
model.rendering_options['RenderMode']= 1
#Shaded = Working Good
model.rendering_options['RenderMode']= 2
# The following are not working as expected...
# Shaded with texture = NOT Working Good
model.rendering_options['RenderMode']= 3
# Monochrome = NOT Working Good and SketchUp crashes when I call the code bellow!
model.rendering_options['RenderMode']= 4
To get Shaded with texture I have to the followingâŚ
# I think model.rendering_options['RenderMode']= 3 is much easier but it doesn't work.
model.rendering_options['RenderMode']= 2
model.rendering_options['Texture']= 1
Now I need help with Monochrome because I donât know how too call it with code easily. Can anyone help me with this?
Thanks in advance!
To render monochrome I found the following code in this forum postâŚ.
Sketchup.send_action('renderMonochrome:')
Can y ou elaborate on what isnât working good? What are you observing vs what you are expecting?
(Screenshots are helpful)
monochrome Sketchup.active_model.rendering_options["RenderMode"] = 5
the way to discover these option values is to change them manually and then query in Ruby ConsoleâŚ
john
1 Like
Hope the following images explain the problem betterâŚ
If you want to see what number corresponds to what mode, just pick them from the UI one by one and run Sketchup.active_model.rendering_options["RenderMode"]
in between.
It is entirely possible some numbers are missing from this sequence. Maybe there has been other rendering modes in older versions that are now removed. Missing numbers could even represent now removed implementations of what is visually to the same renderings mode as we still have.
1 Like
So now I know that both âShadedâ and âShaded with Textureâ use RenderMode = 2 thanks to @eneroth3
And, that means that the only way to get Textured Mode is using the code belowâŚ
model.rendering_options['RenderMode']= 2
model.rendering_options['Texture']= 1
or
Sketchup.send_action('renderTextures:') #Not sure if it works on Macs!
Thanks!
1 Like
It is preferable to use the direct object instance methods to manipulate the SketchUp environment.
Generally, the send actions are similar to keyboard macros and are asynchronous, ⌠meaning your following code could be executing before the âactionâ has completed.
However, for custom toolbar buttons that the user will be clicking, the send actions are fine.
1 Like
Yea, I recall running into the same thing, the Styles toolbar toggles doesnât correspond 1:1 to just a single property for all the buttons. Worth adding more info about in the docs. (I logged an issue for this: Document rendering_options properties vs Styles toggles ¡ Issue #132 ¡ SketchUp/api-issue-tracker ¡ GitHub)
I was also able to reproduce the crash. I logged an issue for this as well: Crash when rendering_options["RenderMode"] = 4 ¡ Issue #133 ¡ SketchUp/api-issue-tracker ¡ GitHub
2 Likes
Regression happened at SU2017. SU2016 and older does not crash. In the source code I find a note about that mode being âobsoleteâ - though Iâm not sure what superseded it. Iâm still investigating.
2 Likes
It appear that RenderMode 4 have been obsolete for a very long time. I wasnât able to track down when.
But the crash-regression in SU2017 appear to be related to refactoring the graphic pipeline - where previously it appear to have taken into account invalid render modes. Now its more fuzzy about it.
3 Likes