Layer color by ruby-code?
-
@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 endand then call that method you should get this error:
Error: #<NameError: undefined local variable or methodx' 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 methodx' 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!!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement