💡 LightUp 7.1 | SketchUp's only real-time renderer that uses object-based rendering
Download Trial
Question about code on SU-forum
-
Hello,
I have a question about adding lines of code to my posts. Most of the times it looks like this:
Example Code
all green
But some people on the forum post code in a topic-message with the syntax highlighted.
How does this work?Tnanks a lot !
-
use
[`` code=php`` ]
instead
Unfortunately we do not have a ruby syntax highlighter plugin but the php works, too (somewhat).Here is Weld.rb as an example:
<span class="syntaxdefault"></span><span class="syntaxcomment"># Copyright 2004,2005 by Rick Wilson <br /><br /># THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR<br /># IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED<br /># WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.<br /><br /># Name ; Weld 3.0<br /># Description ; weld edges into curve ("polyline")<br /># Author ; RickW<br /># Usage ; select edges, then run the script (Plugins>Weld)<br /># Edges will be joined into a curve ("polyline")<br /># Script will prompt to find faces<br /># Date ; 4.Aug.2004<br /># Type ; tool<br /># History;<br /># 3.0 (4.Aug.2005) - Special Anniversary Edition! ;)<br /># now welds to existing curves, adds option<br /># to find faces<br /># 2.2 (1.Aug.2005) - used group/explode to fix most problems<br /># still won't weld to non-arc curves<br /># 2.1 (27.Jul.2005) - fixed the fix that caused strange non-welding<br /># issues.<br /># 2.0 (25.Jul.2005) - fixed bug where unselected edges were welded,<br /># now retains existing faces.<br /># 1.2 (12.May.2005) - fixed edge bug that occasionally resulted<br /># in strange edge locations and deletions<br /># 1.1 (10.Sep.2004) - allows working in groups/components<br /># 1.0 (4.Aug.2004) - first version<br /><br /></span><span class="syntaxdefault">require </span><span class="syntaxstring">'sketchup.rb'<br /><br /></span><span class="syntaxdefault">def join_edges<br /> model</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br /> ents</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities<br /> sel</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection<br /> sl</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">sel</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length<br /> verts</span><span class="syntaxkeyword">=[]<br /></span><span class="syntaxdefault"> edges</span><span class="syntaxkeyword">=[]<br /></span><span class="syntaxdefault"> newVerts</span><span class="syntaxkeyword">=[]<br /></span><span class="syntaxdefault"> startEdge</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">startVert</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">nil<br /><br /></span><span class="syntaxcomment">#CHECK FOR A VALID SELECTION<br /><br /># if sel.first.curve<br /># return UI.messagebox("Please select at least 2 non-joined edges") if sel.length == sel.first.curve.count_edges<br /># end<br /><br />#DELETE NON-EDGES, GET THE VERTICES<br /><br /></span><span class="syntaxdefault"> sel</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">item</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> edges</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">item</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> if item</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">typename</span><span class="syntaxkeyword">==</span><span class="syntaxstring">"Edge"</span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> edges</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">edge</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> verts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">)}<br /></span><span class="syntaxdefault"> verts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">flatten</span><span class="syntaxkeyword">!<br /></span><span class="syntaxdefault"> return UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Please select at least 2 edges"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> if edges</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length </span><span class="syntaxkeyword"><</span><span class="syntaxdefault"> 2<br /><br /></span><span class="syntaxcomment">#FIND AN END VERTEX<br /><br /></span><span class="syntaxdefault"> vertsShort</span><span class="syntaxkeyword">=[]<br /></span><span class="syntaxdefault"> vertsLong</span><span class="syntaxkeyword">=[]<br /></span><span class="syntaxdefault"> verts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each do </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">v</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> if vertsLong</span><span class="syntaxkeyword">.include?(</span><span class="syntaxdefault">v</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> vertsShort</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">v</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> else<br /> vertsLong</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">v</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> end<br /> if </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">startVert</span><span class="syntaxkeyword">=(</span><span class="syntaxdefault">vertsLong</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">vertsShort</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">first</span><span class="syntaxkeyword">)==</span><span class="syntaxdefault">nil<br /> startVert</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">vertsLong</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">first<br /> closed</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">true<br /> startEdge </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> startVert</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">edges</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">first<br /> else<br /> closed</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">false<br /> startEdge </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">edges </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> startVert</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">edges</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">first<br /> end<br /> </span><span class="syntaxcomment">#sel.clear<br /><br /><br />#SORT VERTICES, LIMITING TO THOSE IN THE SELECTION SET<br /><br /></span><span class="syntaxdefault"> if startVert</span><span class="syntaxkeyword">==</span><span class="syntaxdefault">startEdge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start<br /> newVerts</span><span class="syntaxkeyword">=[</span><span class="syntaxdefault">startVert</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> counter</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">0<br /> while newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length </span><span class="syntaxkeyword"><</span><span class="syntaxdefault"> verts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length<br /> edges</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each do </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">edge</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> if edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">end</span><span class="syntaxkeyword">==</span><span class="syntaxdefault">newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">last<br /> newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> elsif edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start</span><span class="syntaxkeyword">==</span><span class="syntaxdefault">newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">last<br /> newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">end</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> end<br /> counter</span><span class="syntaxkeyword">+=</span><span class="syntaxdefault">1<br /> if counter </span><span class="syntaxkeyword">></span><span class="syntaxdefault"> verts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length<br /> return nil if UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"There seems to be a problem. Try again?"</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> MB_YESNO</span><span class="syntaxkeyword">)!=</span><span class="syntaxdefault">6<br /> newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse</span><span class="syntaxkeyword">!<br /></span><span class="syntaxdefault"> reversed</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">true<br /> end<br /> end<br /> else<br /> newVerts</span><span class="syntaxkeyword">=[</span><span class="syntaxdefault">startVert</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> counter</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">0<br /> while newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length </span><span class="syntaxkeyword"><</span><span class="syntaxdefault"> verts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length<br /> edges</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each do </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">edge</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> if edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">end</span><span class="syntaxkeyword">==</span><span class="syntaxdefault">newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">last<br /> newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> elsif edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start</span><span class="syntaxkeyword">==</span><span class="syntaxdefault">newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">last<br /> newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">end</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> end<br /> counter</span><span class="syntaxkeyword">+=</span><span class="syntaxdefault">1<br /> if counter </span><span class="syntaxkeyword">></span><span class="syntaxdefault"> verts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length<br /> return nil if UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"There seems to be a problem. Try again?"</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> MB_YESNO</span><span class="syntaxkeyword">)!=</span><span class="syntaxdefault">6<br /> newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse</span><span class="syntaxkeyword">!<br /></span><span class="syntaxdefault"> reversed</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">true<br /> end<br /> end<br /> end<br /> newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">uniq</span><span class="syntaxkeyword">!<br /></span><span class="syntaxdefault"> newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse</span><span class="syntaxkeyword">!</span><span class="syntaxdefault"> if reversed<br /><br /><br /></span><span class="syntaxcomment">#CONVERT VERTICES TO POINT3Ds<br /><br /></span><span class="syntaxdefault"> newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">collect</span><span class="syntaxkeyword">!{|</span><span class="syntaxdefault">x</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> x</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position</span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> if closed<br /> newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">newVerts</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">])<br /></span><span class="syntaxdefault"> else<br /> newVerts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">newVerts</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">])</span><span class="syntaxdefault"> if UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Close curve?"</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> MB_YESNO</span><span class="syntaxkeyword">)==</span><span class="syntaxdefault">6<br /> closed</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">true<br /> end<br /><br /></span><span class="syntaxcomment">#CREATE THE CURVE<br /><br /></span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_operation </span><span class="syntaxstring">"weld"<br /></span><span class="syntaxdefault"> edges</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">item</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> item</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">explode_curve if item</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">curve and newVerts</span><span class="syntaxkeyword">.include?(</span><span class="syntaxdefault">item</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position</span><span class="syntaxkeyword">)}<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#sel.each {|e| e.erase!}<br /></span><span class="syntaxdefault"> gp1e</span><span class="syntaxkeyword">=(</span><span class="syntaxdefault">gp1</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_group</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">entities<br /> curveEdges</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">gp1e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_curve</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">newVerts</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> $gpents</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">gp1</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">explode<br /> ents</span><span class="syntaxkeyword">[-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">find_faces if closed and ents</span><span class="syntaxkeyword">[-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">typename</span><span class="syntaxkeyword">==</span><span class="syntaxstring">"Edge"</span><span class="syntaxdefault"> and UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Find faces for this curve?"</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> MB_YESNO</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">"Weld Edges Utility"</span><span class="syntaxkeyword">)==</span><span class="syntaxdefault">6<br /></span><span class="syntaxcomment"># if $gpents.first.typename=="Edge"<br /># edges=$gpents.first.curve.edges<br /># elsif $gpents.first.typename=="Curve"<br /># edges=$gpents.first.edges<br /># else<br /># edges=$gpents.last.edges<br /># end<br /># model.active_entities.add_curve(newVerts)<br /># edges.each_index do |i|<br /># if i>0<br /># edges[i].reverse! if edges[i].start!=edges[i-1].end<br />## if edges[i].start!=edges[i-1].end<br />## sel.clear<br />## sel.add(edges)<br />## join_edges<br />## return<br />## end<br /># end<br /># end<br /></span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">commit_operation<br /> sel</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">clear<br />end<br /><br /></span><span class="syntaxcomment">#ALL DONE!<br /><br />#-----------------------------------------------------------------------------<br /></span><span class="syntaxkeyword">if(</span><span class="syntaxdefault"> not file_loaded</span><span class="syntaxkeyword">?(</span><span class="syntaxstring">"weld.rb"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> add_separator_to_menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Plugins"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxcomment"># BEGIN CHANGES BY organizerEdit.rb<br /></span><span class="syntaxdefault">if $submenu</span><span class="syntaxkeyword">!=</span><span class="syntaxdefault">nil<br /> $submenu</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Weld"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> join_edges </span><span class="syntaxkeyword">}<br />else<br /></span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Plugins"</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Weld"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> join_edges </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault">end<br /></span><span class="syntaxcomment"># END CHANGES BY organizerEdit.rb<br /></span><span class="syntaxdefault">end<br /></span><span class="syntaxcomment">#-----------------------------------------------------------------------------<br /></span><span class="syntaxdefault">file_loaded</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"weld.rb"</span><span class="syntaxkeyword">)<br /><br /><br /></span><span class="syntaxcomment">#verts=sel.first.curve.vertices<br />#edges=[]<br />#pts=verts.collect{|v| v.position}<br />#0.upto(pts.length-3) {|i| edges.push(ents.add_line(pts[i],pts[i+2]))}<br />#edges.each {|e| e.erase!}<br /></span><span class="syntaxdefault"> </span>
-
Hi Gaieus,
Thanx, it can be so simple! I checked your website, nice website!
-
This one?
http://gaieus.hu/hehe. Thanks. Nice but first of all, simple! Does not need too much maintenance. Maybe a gallery would spice it up though...
?)
Advertisement