Layer color by ruby-code?
-
Is it possible to set the layer color by ruby-code?
-
Annoyingly - no. It's one of the missing API methods. We can't get/set the layer material, nor can we set material name, erase materials or layers.
-
I tried it with "layer-color=.rb"
layer = model.layers.add "my_layer" layer.color = [255,255,255]
But there is the following error:
"undefined method `page_behavior=' for nil:NilClass"Do you have an idea why the error occurs?
-
There is no built-in API
layer.color=
BUT see here for my stop-gap new method... http://forums.sketchucation.com/viewtopic.php?p=177016#p177016
with that loaded your examplelayer.color= [255,255,255]
should work... -
@tig said:
There is no built-in API
layer.color=
BUT see here for my stop-gap new method... http://forums.sketchucation.com/viewtopic.php?p=177016#p177016
with that loaded your examplelayer.color= [255,255,255]
should work...See his last post...
-
It works OK for me...
-
would help if we got the whole error - with the line number and traceback
-
@tig said:
There is no built-in API
layer.color=
BUT see here for my stop-gap new method... http://forums.sketchucation.com/viewtopic.php?p=177016#p177016
with that loaded your examplelayer.color= [255,255,255]
should work...I tried that. I copied "layer-color=.rb" to plugins folder.
And than there was the error when I start my code.
What is the mistake I made? -
what is the full error?
line of error, and traceback? -
Have you restarted SUp after installing the new code script ?
-
-
@thomthom said:
would help if we got the whole error - with the line number and traceback
The file "test.rb" is in plugins folder.
ThatΒ΄s the whole code of test.rbmodel = Sketchup.active_model layer = model.layers.add "ABS_Grundriss_Wand2" layer.color = [255,255,255]
The following error message appears if Sketchup start:
%(#FF0000)[Fehler beim Laden der Datei test.rb
undefined method `page_behavior=' for nil:NilClass]That error appears in context with "layer-color=.rb" which is in
plugins folder too. If I remove "layer-color=.rb" from plugins folder
there is the following error message:
%(#FF0000)[Fehler beim Laden der Datei test.rb
undefined method `color=' for #Sketchup::Layer:0x6dfe1ec]That error I understand.
-
But there should be a traceback.
If you have a file like this:
def test_me x == y end
and then call that method you should get this error:
Error: #<NameError: undefined local variable or method
x' for main:Object>
C:/Program Files (x86)/Google/Google SketchUp 8/Plugins/testme.rb:2
(eval):2537`Notice it includes the filename and line number after reporting the error. Do you not get that kind of error?
-
I see an issue with this method:
It has multiple .start_operation and commit_operation inside the code flow - which will interfere with any start_operation you started yourself - since SU doesn't handle nested start_operations:
` model.start_operation
...
layer.color = 'red' # this breaks the undo stack
...
model.commit_operation`
Though, it is not related to the error you got.
-
@thomthom said:
But there should be a traceback.
If you have a file like this:
> def test_me > x == y > end >
and then call that method you should get this error:
Error: #<NameError: undefined local variable or method
x' for main:Object>
C:/Program Files (x86)/Google/Google SketchUp 8/Plugins/testme.rb:2
(eval):2537`Notice it includes the filename and line number after reporting the error. Do you not get that kind of error?
The first way I test was run automatically at the Sketchup start.
There was only the error message I posted. -
@thomthom said:
I see an issue with this method:
It has multiple .start_operation and commit_operation inside the code flow - which will interfere with any start_operation you started yourself - since SU doesn't handle nested start_operations:
` model.start_operation
...
layer.color = 'red' # this breaks the undo stack
...
model.commit_operation`
Though, it is not related to the error you got.
Sorry, I donΒ΄t understand that.
I tried now that:
def layer_color model = Sketchup.active_model layer = model.layers.add "Test_Layer" layer.color = [255,255,255] end if( not file_loaded?("test.rb") ) plugins_menu = UI.menu("Plugins") plugins_menu.add_item("LayerColor") {layer_color} end #----------------------------------------------------------------------------- file_loaded("test.rb")
That works without error - but the new layer has the color 102,68,0
and not 255,255,255!!!???I test that:
def layer_color model = Sketchup.active_model layer = model.layers.add "Test_Layer" layer.color = "Blue" end if( not file_loaded?("test.rb") ) plugins_menu = UI.menu("Plugins") plugins_menu.add_item("LayerColor") {layer_color} end #----------------------------------------------------------------------------- file_loaded("test.rb")
The same result like before - Color 102,68,0 instead of blue
Than I test that:
def layer_color model = Sketchup.active_model my_mat = materials.add "Ahorn" my_mat.texture = "O;\\Sketchup\\Mat\\Ahorn.jpg" layer = model.layers.add "Test_Layer" layer.color = my_mat end if( not file_loaded?("test.rb") ) plugins_menu = UI.menu("Plugins") plugins_menu.add_item("LayerColor") {layer_color} end #----------------------------------------------------------------------------- file_loaded("test.rb")
There was no error but also no layer!!
Advertisement