[Code] Rantexpos

[Code] Rantexpos

Postby g.moggel » Wed Feb 09, 2011 9:09 pm

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.

Code: Select all
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.
0
Last edited by thomthom on Thu Feb 10, 2011 6:23 pm, edited 1 time in total.
Reason: Added [Code] tag for indexing

g.moggel 
 

Re: Rantexpos

Postby Dan Rathbun » Thu Feb 10, 2011 8:37 am

g.moggel wrote: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.

Code: Select all
#
#  rantexpos.rb
#
module AxelLee

  
# CONSTANTS

  TOPMENU = 'Plugins' unless defined?(TOPMENU)
  # SUBMENU is blank to put on Plugins menu
  # Enter a string in the quotes to create a submenu:
  SUBMENU = "" unless defined?(SUBMENU)

  Filename = File.basename(__FILE__).downcase

module_function
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


if 
!file_loaded?(Filename)

  @@topmenu=UI.menu(TOPMENU)
  unless SUBMENU.empty?
    @@menu=@@topmenu.add_submenu(SUBMENU)
  else
    
@@menu=@@topmenu
  end
  
@@menu.add_item("Randomize texture positions") {rantexpos}

  file_loaded(Filename)
end

end 
# module
 
0
Last edited by Dan Rathbun on Thu Feb 10, 2011 4:55 pm, edited 1 time in total.
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: Rantexpos

    Postby g.moggel » Thu Feb 10, 2011 10:05 am

    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
    0

    g.moggel 
     

    Re: Rantexpos

    Postby Didier Bur » Thu Feb 10, 2011 12:50 pm

    Hi,

    Typo: replace: file_loaded(filename) with: file_loaded(Filename)
    0
    Didier Bur
    User avatar
    Didier Bur 
     

    Re: Rantexpos

    Postby Dan Rathbun » Thu Feb 10, 2011 4:59 pm

    Didier Bur wrote: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.)
    0
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: Rantexpos

      Postby Dan Rathbun » Thu Feb 10, 2011 6:47 pm

      g.moggel wrote: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.skp


      I 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!)
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        Re: [Code] Rantexpos

        Postby g.moggel » Sun Feb 13, 2011 9:58 am

        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
        0

        g.moggel 
         

        Re: [Code] Rantexpos

        Postby Dan Rathbun » Sun Feb 13, 2011 11:18 pm

        I don't have time myself to work on this.

        Um.. if you have control.. then it would no longer be random ? :lol:

        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.)
        0
          I'm not here much anymore. But a PM will fire email notifications.
          User avatar
          Dan Rathbun 
          PluginStore Author
          PluginStore Author
           

          Re: [Code] Rantexpos

          Postby g.moggel » Mon Feb 14, 2011 12:37 am

          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
          0

          g.moggel 
           

          SketchUcation One-Liner Adverts

          by Ad Machine » 5 minutes ago



          Ad Machine 
          Robot
           



           

          Return to Developers' Forum

          Who is online

          Users browsing this forum: No registered users and 16 guests