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

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

Postby Rich O Brien » Tue Apr 17, 2012 3:48 pm

Colour N-Gons



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
0
There's a frontroom and a backroom....reverse faces
User avatar
Rich O Brien 
Administrator
 

Re: [REQ] Colour Quad Faces only

Postby thomthom » Tue Apr 17, 2012 3:56 pm

Rich O'Brien wrote: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?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [REQ] Colour Quad Faces only

Postby thomthom » Tue Apr 17, 2012 3:58 pm

Off-Topic:
You're such a tease! :lol:
Tease.png
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [REQ] Colour Quad Faces only

Postby Rich O Brien » Tue Apr 17, 2012 4:04 pm

Just boring old quads.

Off-Topic:
What are you talking about? I'm using v9 on my iPad every day. Did you not see my post in the corner bar?
0
There's a frontroom and a backroom....reverse faces
User avatar
Rich O Brien 
Administrator
 

Re: [REQ] Colour Quad Faces only

Postby thomthom » Tue Apr 17, 2012 4:12 pm

Code: Select all
for face in Sketchup.active_model.selection
  next unless face
.is_a?( Sketchup::Face )
  
face.material 'red' if face.edges.length == 4
end
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [REQ] Colour Quad Faces only

Postby thomthom » Tue Apr 17, 2012 4:13 pm

Off-Topic:
Nice Windows UI your iPad has...
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [REQ] Colour Quad Faces only

Postby Rich O Brien » Tue Apr 17, 2012 4:16 pm

Thanks for the code. :thumb:

Off-Topic:
Have you seen Windows 8 on the iPad with touch recognition?
Pretty cool
0
There's a frontroom and a backroom....reverse faces
User avatar
Rich O Brien 
Administrator
 

Re: [REQ] Colour Quad Faces only

Postby Rich O Brien » Tue Apr 17, 2012 4:51 pm

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

Code: Select all
(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
                                           ^>
0
There's a frontroom and a backroom....reverse faces
User avatar
Rich O Brien 
Administrator
 

Re: [REQ] Colour Quad Faces only

Postby thomthom » Tue Apr 17, 2012 4:54 pm

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}
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [REQ] Colour Quad Faces only

Postby Khai » Tue Apr 17, 2012 6:44 pm

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...

:mrgreen: :mrgreen: :mrgreen: :mrgreen:
0

Khai 
 

Re: [REQ] Colour Quad Faces only

Postby Rich O Brien » Tue Apr 17, 2012 7:45 pm

You're reading my mind Khai. This is beyond my ability but I'll have a stab at it. :?
0
There's a frontroom and a backroom....reverse faces
User avatar
Rich O Brien 
Administrator
 

Re: [REQ] Colour Quad Faces only

Postby TIG » Tue Apr 17, 2012 8:02 pm

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...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [REQ] Colour Quad Faces only

Postby Khai » Tue Apr 17, 2012 8:23 pm

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

Khai 
 

Re: [REQ] Colour Quad Faces only

Postby TIG » Tue Apr 17, 2012 9:02 pm

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...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [REQ] Colour Quad Faces only

Postby Rich O Brien » Tue Apr 17, 2012 9:06 pm

does this thing need a module/class etc?

Also does it need a def? All this is still greek to me :roll:
0
There's a frontroom and a backroom....reverse faces
User avatar
Rich O Brien 
Administrator
 

Re: [REQ] Colour Quad Faces only

Postby TIG » Tue Apr 17, 2012 9:09 pm

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...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [REQ] Colour Quad Faces only

Postby Rich O Brien » Tue Apr 17, 2012 9:15 pm

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 :?
0
There's a frontroom and a backroom....reverse faces
User avatar
Rich O Brien 
Administrator
 

Re: [REQ] Colour Quad Faces only

Postby thomthom » Tue Apr 17, 2012 9:42 pm

Code: Select all
# First yeh need this - you just do - so do it!
require 'sketchup.rb'

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

end # module ROB

# Mark this file as loaded.
file_loaded( File.basename(__FILE__) )
 
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [REQ] Colour Quad Faces only

Postby Rich O Brien » Tue Apr 17, 2012 9:52 pm

Do I delete the orange? cause it ain't firing?
0
There's a frontroom and a backroom....reverse faces
User avatar
Rich O Brien 
Administrator
 

Re: [REQ] Colour Quad Faces only

Postby thomthom » Tue Apr 17, 2012 10:00 pm

Rich O'Brien wrote: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! :D
Gimme the error message and a wallop of money!
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [REQ] Colour Quad Faces only

Postby Rich O Brien » Tue Apr 17, 2012 10:03 pm

error message below.... :?

Code: Select all
?


There's none?
0
There's a frontroom and a backroom....reverse faces
User avatar
Rich O Brien 
Administrator
 

Re: [REQ] Colour Quad Faces only

Postby thomthom » Tue Apr 17, 2012 10:08 pm

Ah - found a typo: def self.self.colour_ngon - should be def self.colour_ngon. I updated my post.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [REQ] Colour Quad Faces only

Postby Rich O Brien » Tue Apr 17, 2012 10:10 pm

That little fella was highlighted in Notepad++. So it finds the errors for you.
0
There's a frontroom and a backroom....reverse faces
User avatar
Rich O Brien 
Administrator
 

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

Postby Rich O Brien » Tue Apr 17, 2012 10:47 pm

Updated first post with plugin.

Thanks Thom :thumb:
0
There's a frontroom and a backroom....reverse faces
User avatar
Rich O Brien 
Administrator
 

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

Postby JClements » Tue Apr 17, 2012 11:20 pm

Ah, neophyte question, what is the defintion of an Ngon?
0
John
Illustrator
Beaverton, Oregon
User avatar
JClements 
Premium Member
Premium Member
 

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

Postby Rich O Brien » Tue Apr 17, 2012 11:22 pm

a polygon with n sides

a quad is a 4-gon

a tri is a 3-gon

etc....

Hi John :thumb:
0
There's a frontroom and a backroom....reverse faces
User avatar
Rich O Brien 
Administrator
 

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

Postby Gaieus » Tue Apr 17, 2012 11:25 pm

What about a bi? :roll:
0
User avatar
Gaieus 
 

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

Postby JClements » Tue Apr 17, 2012 11:28 pm

Gai...

Just let bi-gons by bygones.
0
John
Illustrator
Beaverton, Oregon
User avatar
JClements 
Premium Member
Premium Member
 

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

Postby Khai » Tue Apr 17, 2012 11:28 pm

Gaieus wrote:What about a bi? :roll:


they go either way
0

Khai 
 

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

Postby pilou » Tue Apr 17, 2012 11:31 pm

a bi-gone = a segment line ! :mrgreen:
A one gone = a point ! :)
0 gone = void :D
0
Last edited by pilou on Tue Apr 17, 2012 11:32 pm, edited 1 time in total.
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
pilou 
Top SketchUcator
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 

Next


 

Return to Plugins

Who is online

Users browsing this forum: No registered users and 12 guests

Visit our sponsors: