sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Sketchup::load under different binding?

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 2 Posters 160 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.
    • thomthomT Offline
      thomthom
      last edited by

      Is it possible to use Sketchup::load from within a module, but have the loaded content evaled under the top level binding?

      I'm trying to load RBS files, but it all gets wrapped inside the current module.

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

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        IS the RBS scrambled code itself namespace wrapped ??

        What if the rbs code looked like this using the top level scope operator:

        # I am a scrambled rbs file;
        
        ;;TT;;SubModuleName
        
          # code that belongs in ;;TT;;SubModuleName
        
        end
        

        IF the Mac's Ruby v1.8.5-p0 does not recognize the top level scope operator, then perhaps YOU force the namespace evaluation:

        # I am a scrambled rbs file;
        
        this_file = 'thisfilename.rbs'
        str = %q[
        TT;;SubModuleName
        
          # code that belongs in ;;TT;;SubModuleName
        
        end
        ]
        Kernel.eval( str, TOPLEVEL_BINDING, this_file, 4 )
        
        

        or maybe:

        # I am a scrambled rbs file;
        
        Object.class_eval {
        TT;;SubModuleName
        
          # code that belongs in ;;TT;;SubModuleName
        
        end
        }
        
        

        I'm not here much anymore.

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

          Any way to do this without modifying the content of the rbs?

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

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            I remember you talking about this issue before.

            But I have never seen it myself.

            Did you ever post some simple barebones examples ??

            If I knew what you were really trying to do... perhaps PM me. (You already know I can be discrete.)

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @thomthom said:

              Any way to do this without modifying the content of the rbs?

              Hmm.. what about this:

              TT;;LoadManager
              
                # I am a namespace calling Sketchup.load;
               
                rbs_file = 'subdir/filename.rbs'
              
                # Evaluate the Sketchup.load() call within TOPLEVEL_BINDING;
                eval( "Sketchup;;load(#{rbs_file})", TOPLEVEL_BINDING, rbs_file, 1 )
               
              end # module TT;;LoadManager
              
              

              I'm not here much anymore.

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

                @dan rathbun said:

                @thomthom said:

                Any way to do this without modifying the content of the rbs?

                Hmm.. what about this:

                TT;;LoadManager
                > 
                >   # I am a namespace calling Sketchup.load;
                >  
                >   rbs_file = 'subdir/filename.rbs'
                > 
                >   # Evaluate the Sketchup.load() call within TOPLEVEL_BINDING;
                >   eval( "Sketchup;;load(#{rbs_file})", TOPLEVEL_BINDING, rbs_file, 1 )
                >  
                > end # module TT;;LoadManager
                > 
                

                πŸ‘ πŸ‘

                That seem to work perfectly!

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

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  @thomthom said:

                  That seem to work perfectly!

                  Excellent!

                  4 trys is the charm.

                  Man, I love Ruby's flexibility!

                  I'm not here much anymore.

                  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