• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Layer color by ruby-code?

Scheduled Pinned Locked Moved Developers' Forum
16 Posts 3 Posters 896 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    Andreas
    last edited by 23 Sept 2010, 10:03

    Is it possible to set the layer color by ruby-code?

    With best regards from Germany

    Andreas

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 23 Sept 2010, 11:18

      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. 😞

      Thomas Thomassen β€” SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • A Offline
        Andreas
        last edited by 23 Sept 2010, 11:33

        😒 😒 😒 😒 😒 😒 😒

        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?

        With best regards from Germany

        Andreas

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 23 Sept 2010, 11:56

          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 example layer.color= [255,255,255] should work...

          TIG

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 23 Sept 2010, 12:07

            @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 example layer.color= [255,255,255] should work...

            See his last post...

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 23 Sept 2010, 12:21

              It works OK for me... πŸ˜•

              TIG

              1 Reply Last reply Reply Quote 0
              • T Offline
                thomthom
                last edited by 23 Sept 2010, 12:26

                would help if we got the whole error - with the line number and traceback

                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • A Offline
                  Andreas
                  last edited by 23 Sept 2010, 12:45

                  @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 example layer.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?

                  With best regards from Germany

                  Andreas

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 23 Sept 2010, 12:48

                    what is the full error?
                    line of error, and traceback?

                    Thomas Thomassen β€” SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      TIG Moderator
                      last edited by 23 Sept 2010, 12:52

                      Have you restarted SUp after installing the new code script ?

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • A Offline
                        Andreas
                        last edited by 23 Sept 2010, 13:08

                        @tig said:

                        Have you restarted SUp after installing the new code script ?

                        Yes

                        With best regards from Germany

                        Andreas

                        1 Reply Last reply Reply Quote 0
                        • A Offline
                          Andreas
                          last edited by 23 Sept 2010, 13:12

                          @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.rb

                            model = 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.

                          With best regards from Germany

                          Andreas

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            thomthom
                            last edited by 23 Sept 2010, 13:12

                            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?

                            Thomas Thomassen β€” SketchUp Monkey & Coding addict
                            List of my plugins and link to the CookieWare fund

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              thomthom
                              last edited by 23 Sept 2010, 13:19

                              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.

                              Thomas Thomassen β€” SketchUp Monkey & Coding addict
                              List of my plugins and link to the CookieWare fund

                              1 Reply Last reply Reply Quote 0
                              • A Offline
                                Andreas
                                last edited by 23 Sept 2010, 13:38

                                @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.

                                With best regards from Germany

                                Andreas

                                1 Reply Last reply Reply Quote 0
                                • A Offline
                                  Andreas
                                  last edited by 23 Sept 2010, 13:56

                                  @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!!

                                  With best regards from Germany

                                  Andreas

                                  1 Reply Last reply Reply Quote 0
                                  • 1 / 1
                                  1 / 1
                                  • First post
                                    1/16
                                    Last post
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement