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

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

    Scheduled Pinned Locked Moved Plugins
    40 Posts 9 Posters 23.4k 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      A 'one-liner' stands as it is - it's just like typing any commands into the Ruby Console.
      Of course you could make it a 'module' that has a 'menu' item and a 'dialog' for the number of faces etc etc...

      TIG

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

        let's not go there. As much as I need to highlight quads I don't want to tear my hair out. There's not much left after last time 😕

        Download the free D'oh Book for SketchUp 📖

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          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 Offline
            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 Offline
              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 Offline
                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 Offline
                  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 Offline
                    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 Offline
                      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 Offline
                        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 Offline
                          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 Offline
                            Gaieus
                            last edited by

                            What about a bi? 😒

                            Gai...

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

                              Gai...

                              Just let bi-gons by bygones.

                              John | Illustrator | Beaverton, Oregon

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

                                @gaieus said:

                                What about a bi? 😒

                                they go either way

                                1 Reply Last reply Reply Quote 0
                                • Rich O BrienR Offline
                                  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 Offline
                                    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 Offline
                                      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 Offline
                                        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 Offline
                                          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 Offline
                                            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
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement