[Code] Rantexpos
-
hey guys. first up, i dont take credit for that plugin. its by axel lee. i found this plugin rantexpos at http://rhin.crai.archi.fr/rld/plugin_details.php?id=324
it doesnt seem to work in su 8. can one of you look into it and maybe correct it? i'm not into coding but really need this to work.
its supposed to randomize the texture position of the selected group/faces.
code is as follows.
def rantexpos Sketchup.active_model.start_operation("RANTEXPOS!") selected = Sketchup.active_model.selection for ent in selected if( ent.is_a? Sketchup;;Face ) tex = ent.material texpoint = [] texpoint.push [rand(2048), rand(2048), rand(2048)] texpoint.push [rand(2048), rand(2048), rand(2048)] texpoints = [texpoint[0],texpoint[1]] ent.position_material (tex, texpoints, true) ent.position_material (tex, texpoints, false) end if( ent.is_a? Sketchup;;Group ) for fac in ent.entities if( fac.is_a? Sketchup;;Face ) tex = ent.material texpoint = [] texpoint.push [rand(2048), rand(2048), rand(2048)] texpoint.push [rand(2048), rand(2048), rand(2048)] texpoints = [texpoint[0],texpoint[1]] fac.position_material (tex, texpoints, true) fac.position_material (tex, texpoints, false) end end end end Sketchup.active_model.commit_operation end filename="rantexpos.rb" if !file_loaded?(filename) plugins_menu = UI.menu("Plugins") if plugins_menu plugins_menu.add_separator plugins_menu.add_item("Randomize texture positions") {rantexpos} end file_loaded(filename) end
thanks in advance.
-
thanks dan for looking into it. when starting sketchup i get an error now:
"Error Loading File rantexpos.rb
undefined local variable or method `filename' for AxelLee:Module"and still when i start the plugin from the plugins menu su crashes.
greets,
mo -
Hi,
Typo: replace: file_loaded(filename) with: file_loaded(Filename)
-
@g.moggel said:
it doesnt seem to work in su 8.
Parenthesized argument lists for methods. (And remove a few spaces when they were in between method names and arg lists. This causes an error in Ruby 1.8.6)
Wrapped in a module.
Added Constants at top for setting menus.<span class="syntaxdefault"></span><span class="syntaxcomment">#<br /># rantexpos.rb<br />#<br /></span><span class="syntaxdefault">module AxelLee<br /><br /> </span><span class="syntaxcomment"># CONSTANTS<br /><br /></span><span class="syntaxdefault"> TOPMENU </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Plugins'</span><span class="syntaxdefault"> unless defined</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">TOPMENU</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># SUBMENU is blank to put on Plugins menu<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Enter a string in the quotes to create a submenu;<br /></span><span class="syntaxdefault"> SUBMENU </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">""</span><span class="syntaxdefault"> unless defined</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">SUBMENU</span><span class="syntaxkeyword">)<br /><br /></span><span class="syntaxdefault"> Filename </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">downcase<br /><br />module_function<br />def rantexpos<br /> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_operation</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"RANTEXPOS!"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> selected </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection <br /> for ent in selected<br /> if ent</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"> tex </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">material<br /> texpoint </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[]<br /></span><span class="syntaxdefault"> texpoint</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">([</span><span class="syntaxdefault">rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2048</span><span class="syntaxkeyword">),</span><span class="syntaxdefault"> rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2048</span><span class="syntaxkeyword">),</span><span class="syntaxdefault"> rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2048</span><span class="syntaxkeyword">)])<br /></span><span class="syntaxdefault"> texpoint</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">([</span><span class="syntaxdefault">rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2048</span><span class="syntaxkeyword">),</span><span class="syntaxdefault"> rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2048</span><span class="syntaxkeyword">),</span><span class="syntaxdefault"> rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2048</span><span class="syntaxkeyword">)])<br /></span><span class="syntaxdefault"> texpoints </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">texpoint</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">],</span><span class="syntaxdefault">texpoint</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">]]<br /></span><span class="syntaxdefault"> ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position_material</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">tex</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> texpoints</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> true</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position_material</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">tex</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> texpoints</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> false</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> if ent</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">Group</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> for fac in ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br /> if fac</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"> tex </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">material<br /> texpoint </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[]<br /></span><span class="syntaxdefault"> texpoint</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">([</span><span class="syntaxdefault">rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2048</span><span class="syntaxkeyword">),</span><span class="syntaxdefault"> rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2048</span><span class="syntaxkeyword">),</span><span class="syntaxdefault"> rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2048</span><span class="syntaxkeyword">)])<br /></span><span class="syntaxdefault"> texpoint</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">([</span><span class="syntaxdefault">rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2048</span><span class="syntaxkeyword">),</span><span class="syntaxdefault"> rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2048</span><span class="syntaxkeyword">),</span><span class="syntaxdefault"> rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2048</span><span class="syntaxkeyword">)])<br /></span><span class="syntaxdefault"> texpoints </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">texpoint</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">],</span><span class="syntaxdefault">texpoint</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">]]<br /></span><span class="syntaxdefault"> fac</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position_material</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">tex</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> texpoints</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> true</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> fac</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position_material</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">tex</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> texpoints</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> false</span><span class="syntaxkeyword">)<br /><br /></span><span class="syntaxdefault"> end<br /> end<br /> end<br /> end<br /> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">commit_operation<br />end<br /><br /><br />if </span><span class="syntaxkeyword">!</span><span class="syntaxdefault">file_loaded</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Filename</span><span class="syntaxkeyword">)<br /><br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">topmenu</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">TOPMENU</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> unless SUBMENU</span><span class="syntaxkeyword">.empty?<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">=@@</span><span class="syntaxdefault">topmenu</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_submenu</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">SUBMENU</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> else<br /> </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">=@@</span><span class="syntaxdefault">topmenu<br /> end<br /> </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Randomize texture positions"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{</span><span class="syntaxdefault">rantexpos</span><span class="syntaxkeyword">}<br /><br /></span><span class="syntaxdefault"> file_loaded</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Filename</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">end<br /><br />end </span><span class="syntaxcomment"># module<br /></span><span class="syntaxdefault"> </span>
-
@didier bur said:
Typo: replace: file_loaded(filename) with: file_loaded(Filename)
Done. Edited the code.
I did that in a secs just before bed. I have not tested it. (I assume it worked under Ruby 1.8.0, and didn't under 1.8.6 because of spaces between method names and argumentlists, etc.)
-
@g.moggel said:
and still when i start the plugin from the plugins menu su crashes.
I was able to get it to work on a simple model (attached.)
SaucePan.skpI was also able to get a BugSplat! on a very complex old ver 7.1 model. I selected the terrian mesh, and tried it on that. (splatto!)
-
hey man this is awesome. i needed to make a cutting board like ikeas whole-wood boards and they consist of individual parts glued together... anyway: NICE ONE!
although i have another thing. the textures original rotation is changed and completely oriented in the other way. is it possible to not let the rotation change or choose whether it randomizes rotation at a given angle?thanks again, this was a big help
greets,
mo -
I don't have time myself to work on this.
Um.. if you have control.. then it would no longer be random ?
but I did notice that when I ran it on a pavement texture on a bridge model, that the roadway became misalign with the bridge. (Looked terrible.)
-
figured it out. i just need to rotate my face/object to be oriented with the axis. then i can hit rantexpos and it aligns them in the other way. thanks again for your help.
mo
Advertisement