sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Layer color by ruby-code?

    Scheduled Pinned Locked Moved Developers' Forum
    16 Posts 3 Posters 896 Views 3 Watching
    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.
    • TIGT Offline
      TIG Moderator
      last edited by

      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
      • thomthomT Offline
        thomthom
        last edited by

        @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
        • TIGT Offline
          TIG Moderator
          last edited by

          It works OK for me... 😕

          TIG

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            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

              @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
              • thomthomT Offline
                thomthom
                last edited by

                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
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  Have you restarted SUp after installing the new code script ?

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    Andreas
                    last edited by

                    @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

                      @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
                      • thomthomT Offline
                        thomthom
                        last edited by

                        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
                        • thomthomT Offline
                          thomthom
                          last edited by

                          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

                            @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

                              @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
                              • First post
                                Last post
                              Buy SketchPlus
                              Buy SUbD
                              Buy WrapR
                              Buy eBook
                              Buy Modelur
                              Buy Vertex Tools
                              Buy SketchCuisine
                              Buy FormFonts

                              Advertisement