RenderMode Bug?


#1

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!


#2

To render monochrome I found the following code in this forum post….

Sketchup.send_action('renderMonochrome:')

#3

Can y ou elaborate on what isn’t working good? What are you observing vs what you are expecting?
(Screenshots are helpful)


#4

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


#5

Hope the following images explain the problem better…


#6

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.


#7

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!


#8

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.


#9

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: https://github.com/SketchUp/api-issue-tracker/issues/132)

I was also able to reproduce the crash. I logged an issue for this as well: https://github.com/SketchUp/api-issue-tracker/issues/133


#10

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.


#11

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.