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!
    Mac User? | Join the Rayscaper Beta for Mac Learn More

    [Plugin] Colour N-Gons v1.0 (17/4/12)

    Scheduled Pinned Locked Moved Plugins
    40 Posts 9 Posters 29.3k Views 9 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.
    • thomthomT
      thomthom
      last edited by

      <span class="syntaxdefault"><br /></span><span class="syntaxcomment"># First yeh need this - you just do - so do it!<br /></span><span class="syntaxdefault">require </span><span class="syntaxstring">'sketchup.rb'<br /><br /></span><span class="syntaxcomment"># Then yeh need a module to group your plugins<br /># so it doesn't fekk up everyone else's.<br /></span><span class="syntaxdefault">module ROB<br />  <br />  </span><span class="syntaxcomment"># Then a smart-arse name for the actual plugin.<br /></span><span class="syntaxdefault">  module ColorByNGon<br />    <br />    </span><span class="syntaxcomment"># Add your menu items here, but make sure it's<br /></span><span class="syntaxdefault">    </span><span class="syntaxcomment"># not added multiple times.<br /></span><span class="syntaxdefault">    unless file_loaded</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">basename</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">__FILE__</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">      </span><span class="syntaxcomment"># Fetch yourself a handy top-level menu...<br /></span><span class="syntaxdefault">      menu </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Plugins'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">      </span><span class="syntaxcomment"># ...sprinkle with some menu items...<br /></span><span class="syntaxdefault">      menu</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Colour N-Gons'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault">        self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">colour_ngon<br />      </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault">    end<br />    <br />    </span><span class="syntaxcomment"># You deffo want to add some methods.<br /></span><span class="syntaxdefault">    def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">colour_ngon<br />      </span><span class="syntaxcomment"># Lets ask the user for colour and number<br /></span><span class="syntaxdefault">      </span><span class="syntaxcomment"># of sides in the n-gon;<br /></span><span class="syntaxdefault">      prompts  </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Colour'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'N-Gon Sides'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault">      defaults </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Red'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 4 </span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault">      title    </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Colour N-Gons'<br /></span><span class="syntaxdefault">      result </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">inputbox</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> prompts</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> defaults</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> title </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">      return if result </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> false </span><span class="syntaxcomment"># User cancelled - the bugger!<br /></span><span class="syntaxdefault">      </span><span class="syntaxcomment"># Do the magic trick!<br /></span><span class="syntaxdefault">      color</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> ngon </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> result </span><span class="syntaxcomment"># Extract the user input from the results.<br /></span><span class="syntaxdefault">      model </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model </span><span class="syntaxcomment"># Get yourself a reference to the model.<br /></span><span class="syntaxdefault">      model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_operation</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Colour N-Gons'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> true </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Because you like a tidy Undo stack<br /></span><span class="syntaxdefault">      for face in model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection<br />        next unless face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">        next unless face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">edges</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> ngon<br />        face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">material </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> color<br />      end<br />      model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">commit_operation </span><span class="syntaxcomment"># Can you commit - can you?!???<br /></span><span class="syntaxdefault">      </span><span class="syntaxcomment"># Profit???<br /></span><span class="syntaxdefault">    end<br />    <br />  end </span><span class="syntaxcomment"># module ColorByNGon<br /><br /></span><span class="syntaxdefault">end </span><span class="syntaxcomment"># module ROB<br /><br /># Mark this file as loaded.<br /></span><span class="syntaxdefault">file_loaded</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">basename</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">__FILE__</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span>
      

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

      1 Reply Last reply
      Reply Quote 0
      • Rich O BrienR
        Rich O Brien Moderator
        last edited by

        Do I delete the orange? cause it ain't firing?

        Download the free D'oh Book for SketchUp 📖

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

          @unknownuser said:

          Do I delete the orange? cause it ain't firing?

          The orange is just comments - they do nothing.

          I didn't test it before posting - because now I can 'fix' it for a grand fee! 😄
          Gimme the error message and a wallop of money!

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

          1 Reply Last reply
          Reply Quote 0
          • Rich O BrienR
            Rich O Brien Moderator
            last edited by

            error message below.... 😕

            ?
            

            There's none?

            Download the free D'oh Book for SketchUp 📖

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

              Ah - found a typo: def self.self.colour_ngon - should be def self.colour_ngon. I updated my post.

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

              1 Reply Last reply
              Reply Quote 0
              • Rich O BrienR
                Rich O Brien Moderator
                last edited by

                That little fella was highlighted in Notepad++. So it finds the errors for you.

                Download the free D'oh Book for SketchUp 📖

                1 Reply Last reply
                Reply Quote 0
                • Rich O BrienR
                  Rich O Brien Moderator
                  last edited by

                  Updated first post with plugin.

                  Thanks Thom 👍

                  Download the free D'oh Book for SketchUp 📖

                  1 Reply Last reply
                  Reply Quote 0
                  • JClementsJ
                    JClements
                    last edited by

                    Ah, neophyte question, what is the defintion of an Ngon?

                    John | Illustrator | Beaverton, Oregon

                    1 Reply Last reply
                    Reply Quote 0
                    • Rich O BrienR
                      Rich O Brien Moderator
                      last edited by

                      a polygon with n sides

                      a quad is a 4-gon

                      a tri is a 3-gon

                      etc....

                      Hi John 👍

                      Download the free D'oh Book for SketchUp 📖

                      1 Reply Last reply
                      Reply Quote 0
                      • GaieusG
                        Gaieus
                        last edited by

                        What about a bi? 😒

                        Gai...

                        1 Reply Last reply
                        Reply Quote 0
                        • JClementsJ
                          JClements
                          last edited by

                          Gai...

                          Just let bi-gons by bygones.

                          John | Illustrator | Beaverton, Oregon

                          1 Reply Last reply
                          Reply Quote 0
                          • K
                            Khai
                            last edited by

                            @gaieus said:

                            What about a bi? 😒

                            they go either way

                            1 Reply Last reply
                            Reply Quote 0
                            • Rich O BrienR
                              Rich O Brien Moderator
                              last edited by

                              @John

                              I forgot Oregon 👍

                              Download the free D'oh Book for SketchUp 📖

                              1 Reply Last reply
                              Reply Quote 0
                              • pilouP
                                pilou
                                last edited by

                                a bi-gone = a segment line ! 💚
                                A one gone = a point ! 😄
                                0 gone = void 😄

                                Frenchy Pilou
                                Is beautiful that please without concept!
                                My Little site :)

                                1 Reply Last reply
                                Reply Quote 0
                                • pilouP
                                  pilou
                                  last edited by

                                  a cool thing will be something like that
                                  colour ngons > 6 and < 10 (just example)

                                  Frenchy Pilou
                                  Is beautiful that please without concept!
                                  My Little site :)

                                  1 Reply Last reply
                                  Reply Quote 0
                                  • Rich O BrienR
                                    Rich O Brien Moderator
                                    last edited by

                                    @unknownuser said:

                                    a cool thing will be something like that
                                    colour ngons > 6 and < 10 (just example)

                                    ..and you will want these to be randomly painted also?

                                    Download the free D'oh Book for SketchUp 📖

                                    1 Reply Last reply
                                    Reply Quote 0
                                    • K
                                      Khai
                                      last edited by

                                      anyone know of the perfect companion to this? select colour?

                                      and thank you guys for this... hunting Ngons just got so much easier 😄

                                      1 Reply Last reply
                                      Reply Quote 0
                                      • EarthMoverE
                                        EarthMover
                                        last edited by

                                        @unknownuser said:

                                        @unknownuser said:

                                        a cool thing will be something like that
                                        colour ngons > 6 and < 10 (just example)

                                        ..and you will want these to be randomly painted also?

                                        🤣

                                        Thanks Thom...very handy.

                                        3D Artist at Clearstory 3D Imaging
                                        Guide Tool at Winning With Sketchup
                                        Content Creator at Skapeup

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

                                          @khai said:

                                          anyone know of the perfect companion to this? select colour?

                                          SelectMaterial.png

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

                                          1 Reply Last reply
                                          Reply Quote 0
                                          • pilouP
                                            pilou
                                            last edited by

                                            @unknownuser said:

                                            ..and you will want these to be randomly painted also?

                                            No Need! All yet exist!
                                            this will be easy made if the previous ngons colors request was done! 😉

                                            You paint in red the 6 > and < 10 by the colour ngons
                                            then Select by material current by Kwalkerman so red
                                            then Random Painter by ChrisFullmer if your previous was done! 😉

                                            So waiting the colour ngons with conditions
                                            Must be no so difficult 🤓

                                            http://burgart.files.wordpress.com/2009/08/600px-rosace_cathedrale_strasbourg.jpg

                                            Frenchy Pilou
                                            Is beautiful that please without concept!
                                            My Little site :)

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

                                            Advertisement