[Plugin] Colour N-Gons v1.0 (17/4/12)
-
Thanks for the code.
[off:1fwx2648]Have you seen Windows 8 on the iPad with touch recognition?
Pretty cool[/off:1fwx2648] -
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 ^>
-
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}
-
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...
-
You're reading my mind Khai. This is beyond my ability but I'll have a stab at it.
-
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... -
I get that Tig.. it's having the code handy all the time and where do I enter it?
-
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... -
does this thing need a module/class etc?
Also does it need a def? All this is still greek to me
-
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
Advertisement