sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    When (and why) might "file_loaded?" be needed?

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 3 Posters 233 Views 3 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.
    • RichMorinR Offline
      RichMorin
      last edited by

      In some plugins I've perused, there is code like this:

      
      unless file_loaded?('MyPlugin.rb')
        UI.menu('Plugins').add_item('My Plugin')
        file_loaded('MyPlugin.rb')
      end
      
      

      I'm curious about when and why SketchUp might try to reload a plugin. Does anyone know the answer to this?

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        It's more of a convenience for the developer - when you reload your script you don't get lots of duplicate menu entries.

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          It's there to stop more than one instance of the plugin loading into the menu/context-menu etc.

          If you hadn't added this trap then this might happen if you typed load "MyPlugin.rb" after you have already got it loaded - e.g. automatically at startup.

          It's not going to have to stop these potential duplicate menu items unless you try to 'load' the script more than once - e.g. while you are testing it, or perhaps when you have a script in a sub-folder that doesn't auto-load, but it might be loaded by another script [that is itself already loaded] under certain circumstances, and potentially these circumstances might occur more than once in that session - but you only want the one menu/context/toolbar item...

          TIG

          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