sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Update | Sketchucation Tools 5.0.8 released with licensing improvements and bugfixes Download

    Problem with color

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 4 Posters 937 Views 4 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
      TIG Moderator
      last edited by

      Apart from sloppy coding you are muddling up 'color' and 'material'.
      You make a color and then try to assign it to a face as if it were a material - that won't work
      Make a material.
      Give that material a color.
      Add the material to the face.
      mat=model.materials.add("MyLovelyMaterial") mat.color=[255,240,187] face.material=mat
      etc etc

      TIG

      1 Reply Last reply
      Reply Quote 0
      • C
        Chris88
        last edited by

        @ Dan:
        well unfortunately this doesn't help,
        i have only one file with the aforementioned code.
        And if i wrapped it in a namespace, the problem isn't fixed. The cuboid is drawn colorlessly. Only the sketchup-bridge in RDE draw it with color, but it should do that from the plungins folder.

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

          @chris88 said:

          @ Dan:
          well unfortunately this doesn't help,
          i have only one file with the aforementioned code.
          And if i wrapped it in a namespace, the problem isn't fixed. The cuboid is drawn colorlessly. Only the sketchup-bridge in RDE draw it with color, but it should do that from the plungins folder.

          Maybe you can't create geometry like that immediacy as SU starts?
          What happens if you call your command from the Ruby Console, or activate it from a menu? Just a thought since your file calls your method as it loads with SU - maybe SU isn't ready.

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

          1 Reply Last reply
          Reply Quote 0
          • TIGT
            TIG Moderator
            last edited by

            You are wrongly applying a color as if it were a material, if you'd reread my post!

            On the question of it not working at startup why not add a test loop at the very start of your def, along the lines of
            unless Sketchup.active_model;until Sketchup.active_model.active_entities;end;end
            so it waits until there IS an active entities object to add geometry to ???

            TIG

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

              @tig said:

              On the question of it not working at startup why not add a test loop at the very start of your def, along the lines of
              unless Sketchup.active_model;until Sketchup.active_model.active_entities;end;end
              so it waits until there IS an active entities object to add geometry to ???

              That that doesn't block the processing queue? ❓

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

              1 Reply Last reply
              Reply Quote 0
              • TIGT
                TIG Moderator
                last edited by

                Haven't tried it...
                He could also try a timer to kick in after a few seconds from loading the code ?

                TIG

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

                  Maybe.

                  But maybe there's another way around this...

                  I think we need to step back and figure out the purpose of this exercise, and not get caught up in an issue that could be a non-issue if there are better alternatives.

                  Why is the method called upon startup? Is it to perform testing? Do you (Chris88) restart SU when you change your code?
                  If you do - then there is an alternative. Just type into the Ruby Console: load 'myrubyfile.rb' to reload the code without restarting SU.

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

                  1 Reply Last reply
                  Reply Quote 0
                  • Dan RathbunD
                    Dan Rathbun
                    last edited by

                    @chris88 said:

                    @ Dan: well unfortunately this doesn't help,
                    i have only one file with the aforementioned code.

                    Sorry.. wrong issue. I saw create_box() and assumed.. shame on me. 😳
                    Quitting smoking and working on the dirty underside of my car males me grumpy, but I should not have "snipped" at you. My apologies.

                    @chris88 said:

                    And if i wrapped it in a namespace, the problem isn't fixed.

                    True.. but you still need to write code in your own namespace.

                    @chris88 said:

                    @ Dan: well unfortunately this doesn't help,
                    I have only one file with the aforementioned code.

                    Google installs the other two files.. which conflict with each other.

                    You would best chose another method name, if your going to define that method in the global Objectspace.

                    😉

                    I'm not here much anymore.

                    1 Reply Last reply
                    Reply Quote 0
                    • C
                      Chris88
                      last edited by

                      Sorry i wasn't online the last days.
                      First of all thanks for your suggestions.
                      I don't prefer the method with the timer, because i have to close and
                      open SU many times in a row. But i like the method "load rubyscript.rb"
                      i will test it.
                      And thanks to TIG, your help me a lot.
                      @Dan It's ok 😉

                      1 Reply Last reply
                      Reply Quote 0
                      • C
                        Chris88
                        last edited by

                        This unless Sketchup.active_model;until Sketchup.active_model.active_entities;end;end
                        and this load 'myrubyfile.rb' are the solutions for my problem, well it's really so,
                        that SU isn't ready to load the color.
                        Thanks again.

                        Can anyone say how to make the material transparent, please?

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

                          @chris88 said:

                          Can anyone say how to make the material transparent, please?

                          Error 404 (Not Found)!!1

                          favicon

                          (code.google.com)

                          Note that the Material object doesn't use the alpha channel of the Color object.

                          <span class="syntaxdefault">m </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">materials</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxstring">'MyMaterial'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">m</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">color </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">255</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">128</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault">m</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">alpha </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> 0.5<br /></span>
                          

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

                          1 Reply Last reply
                          Reply Quote 0
                          • C
                            Chris88
                            last edited by

                            Great!
                            Thank you, i like this forum more and more.

                            Merry Christmas and happy holidays to all!

                            1 Reply Last reply
                            Reply Quote 0

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

                            Advertisement