sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Attempting to make a button for a toolbar

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 200 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E Offline
      Eric_Erb
      last edited by

      πŸ˜• ❓ πŸ˜• ❓ πŸ˜• ❓ πŸ˜•
      I'm trying to make a toolbar button. I used the webexporter files as my guides. I was able to create the toolbar with the button but the button didn't execute the def it did nothing. I was messing around with it and now I'm getting "Error Loading File addfg2walls.rb
      undefined local variable or method `fg2walls' for main:Object"

      my addfg2walls.rb file (the one that creates the button)looks like this...

      require "Rapidset/fg2walls.rb" def createPlugin() fg2walls.init() end createPlugin()

      and my fg2walls.rb file (the one that defines the button and the def I want the button to run) looks like this...

      ` require 'sketchup'
      def fg2walls::init()
      cmd = UI::Command.new(fg2walls.handleToolbarPress) {handleToolbarButtonPress()}
      cmd.small_icon = "FG.png"
      cmd.large_icon = "FG.png"
      cmd.status_bar_text = cmd.tooltip = "Fox Gray"
      cmd.menu_text = "Wall Colors"
      wallsToolbar = UI::Toolbar.new("Wall Colors")
      wallsToolbar.add_item(cmd)
      wallsToolbar.show

      UI.menu("Plugins").add_item("FG Walls") { fg2walls.init }
      end

      def fg2walls::handleToolbarButtonPress()
      mod = Sketchup.active_model
      su_materials = mod.materials
      my_materials = Hash.new
      my_materials["Wall_surfaces"] = su_materials["FG"]

      begin
      mod.start_operation("Change Walls", true)
      rescue ArgumentError
      mod.start_operation("Change Walls")
      end

      mod.entities.each do |entity|
      if entity.is_a? Sketchup::Drawingelement
      entity.material = my_materials[entity.layer.name] if my_materials[entity.layer.name]
      end
      end

      mod.commit_operation
      end`

      As I said I was just using the WebExporter files as a guide so I don't even know if these need to be two separate files. You know it's funny as soon as I start to feel confident enough to start putting my own things together, Ruby has a way of reminding me that I know nothing. Below you can download either of the files to edit them.
      addfg2Wallsfg2walls

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        I only had a chance to barely glance at the code, but the first thing I see is that you want to define the toolbar and the menu AFTER all methods are defined. Because the menu item you create is calling a method that is not yet defined, and I think that might throw an error in SU.

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • Chris FullmerC Offline
          Chris Fullmer
          last edited by

          Ahh, looking a little close I see other errors in the way.

          I'll try to get a beter response put together, unless someone else beats me to it.

          Chris

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

          1 Reply Last reply Reply Quote 0
          • E Offline
            Eric_Erb
            last edited by

            Alright it's actually pretty simple. If anybody else needs the same thing here you go...

            ` toolbar = UI::Toolbar.new "TOOLBAR.NAME"

             cmd = UI::Command.new("TOOLBAR.ITEM.NAME") {
              
                ###copy everything from the def you want to use here...
               
                ###call it...
                DEF.NAME.call()
             }
             cmd.small_icon = "PATH.TO.ICON"
             cmd.large_icon = "PATH.TO.ICON"
             cmd.tooltip = "POPUP.TEXT"
             cmd.status_bar_text = "TEXT"
             cmd.menu_text = "TEXT"
             toolbar = toolbar.add_item cmd
             toolbar.show`
            
            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement