[Plugin] Colour N-Gons v1.0 (17/4/12)
-
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... -
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
-
<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>
-
Do I delete the orange? cause it ain't firing?
-
@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! -
error message below....
?
There's none?
-
Ah - found a typo:
def self.self.colour_ngon
- should bedef self.colour_ngon
. I updated my post. -
That little fella was highlighted in Notepad++. So it finds the errors for you.
-
Updated first post with plugin.
Thanks Thom
-
Ah, neophyte question, what is the defintion of an Ngon?
-
a polygon with n sides
a quad is a 4-gon
a tri is a 3-gon
etc....
Hi John
-
What about a bi?
-
Gai...
Just let bi-gons by bygones.
-
-
I forgot Oregon
-
a bi-gone = a segment line !
A one gone = a point !
0 gone = void -
a cool thing will be something like that
colour ngons > 6 and < 10 (just example) -
@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?
-
anyone know of the perfect companion to this? select colour?
and thank you guys for this... hunting Ngons just got so much easier
-
@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.
Advertisement