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.
    • Rich O BrienR Online
      Rich O Brien Moderator
      last edited by

      Colour N-Gons

      [flash=640,480:38x4j7qi]http://www.youtube.com/v/RkhbkytXFdY[/flash:38x4j7qi]

      Description:

      Paints N-Gons in a selection

      Usage:

      Run 'Colour N-Gon' from the 'Plugin' menu.

      Versions:
      1.0 17/4/2012 - First Release

      Color_N_Gon.rb

      Download the free D'oh Book for SketchUp 📖

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

        @unknownuser said:

        Is it possible to colour only quad faces via ruby?

        Yes - but you do mean native quads - or the non-planar ones that works with QuadFace Tools etc?

        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

          [off:1hu3f8tf]You're such a tease! 😆
          Tease.png[/off:1hu3f8tf]

          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 Online
            Rich O Brien Moderator
            last edited by

            Just boring old quads.

            [off:34wymujb]What are you talking about? I'm using v9 on my iPad every day. Did you not see my post in the corner bar?[/off:34wymujb]

            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="syntaxkeyword">for&nbsp;</span><span class="syntaxdefault">face&nbsp;in&nbsp;Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection<br />&nbsp;&nbsp;next&nbsp;unless&nbsp;face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?(&nbsp;</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">material&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxstring">'red'&nbsp;</span><span class="syntaxkeyword">if&nbsp;</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">edges</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length&nbsp;</span><span class="syntaxkeyword">==&nbsp;</span><span class="syntaxdefault">4<br />end<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
              • thomthomT Offline
                thomthom
                last edited by

                [off:3r39t1pm]Nice Windows UI your iPad has...[/off:3r39t1pm]

                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 Online
                  Rich O Brien Moderator
                  last edited by

                  Thanks for the code. 👍

                  [off:1fwx2648]Have you seen Windows 8 on the iPad with touch recognition?
                  Pretty cool[/off:1fwx2648]

                  Download the free D'oh Book for SketchUp 📖

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

                    How do I enter this in the console? I tried but I'm getting errors....

                    (eval);438
                    for face in Sketchup.active_model.selection
                    Error; #<SyntaxError; (eval);438; compile error
                    (eval);438; syntax error, unexpected $end, expecting kDO_COND or ';' or '\n' or ';'
                    for face in Sketchup.active_model.selection
                                                               ^>
                    

                    Download the free D'oh Book for SketchUp 📖

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

                      Ah, it was just general code.

                      Here is a one-liner:

                      Sketchup.active_model.selection.each{|e|e.material='red' if e.is_a?(Sketchup::Face) && e.edges.length==4}

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

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

                        ohh I can really use this 😄

                        I wish I knew how to give it a UI - so you could select edge count (3,4,5,etc) and colour...

                        💚 💚 💚 💚

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

                          You're reading my mind Khai. This is beyond my ability but I'll have a stab at it. 😕

                          Download the free D'oh Book for SketchUp 📖

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

                            Easy-peasy... see the part that says e.edges.length==4
                            Just change it to any value between 3 and 1000000+
                            e.edges.length==3 for triangulated faces
                            e.edges.length==6 for hexagonal faces
                            etc...

                            TIG

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

                              I get that Tig.. it's having the code handy all the time and where do I enter it?

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

                                A 'one-liner' needs to be copied+pasted+<enter> into the Window > Ruby Console to do its stuff.
                                In this case it works on the current Selection, and changes the material of all selected faces that have the given number of edges...

                                TIG

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

                                  does this thing need a module/class etc?

                                  Also does it need a def? All this is still greek to me 😒

                                  Download the free D'oh Book for SketchUp 📖

                                  1 Reply Last reply Reply Quote 0
                                  • 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 Online
                                      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 Online
                                          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
                                            • 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