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

    Will NOT scramble ??

    Scheduled Pinned Locked Moved Developers' Forum
    44 Posts 4 Posters 1.4k Views 4 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.
    • K Offline
      ksor
      last edited by

      When I run this as a rs-file it "works" fine - it comes up in the menu !

      require 'sketchup'
          
      filename=File.basename(__FILE__)
      if(not file_loaded?(filename))
          UI.menu("Plugins").add_item("Remskive") { Sketchup.active_model.select_tool Polley.new }
      end
      file_loaded(filename)
      
      class Polley
      
          # store bogstaver evt. med _ er en CONST
          MINDIAP = 50.mm
          MINDIAA = 10.mm
          MINKRVD = 25.mm
          MINKRVB = 15.mm
          
      end #class   
      
      

      when I scramble the file - NOTHING comes up in the menu !

      NO CHANGES except that it's scrambled - why ?

      Best regards
      KSor, Denmark
      Skype: keldsor

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

        The Ruby __FILE__ won't work inside a compiled .rbs file, so that's probably breaking it.
        You would normally only scramble code you want to remain protected and private.
        Making some menu items is not one of those.
        Why do you want to scramble such a 'simple script'?
        You are hardly protecting your intellectual property rights in the code you showed us...
        Can I suggest that you make a 'loader' script that is a .rb file [which has code the menus/toolbars etc, 'require'ing the main script[s] etc which will be inside your own tool's subfolder - any encrypted .rbs scripts are [usually] kept inside such a subfolder - that's also where any webdialog files, images for toolbar buttons etc will reside...
        Then you have no difficulties setting the menu up via the .rb file AND your code in the .rbs file[s] remains confidential... IF you really have to protect it in this way...

        TIG

        1 Reply Last reply Reply Quote 0
        • K Offline
          ksor
          last edited by

          @tig said:

          The Ruby __FILE__ won't work inside a compiled .rbs file, so that's probably breaking it.
          You would normally only scramble code you want to remain protected and private.
          Making some menu items is not one of those.
          Why do you want to scramble such a 'simple script'?
          You are hardly protecting your intellectual property rights in the code you showed us...
          Can I suggest that you make a 'loader' script that is a .rb file [which has code the menus/toolbars etc, 'require'ing the main script[s] etc which will be inside your own tool's subfolder - any encrypted .rbs scripts are [usually] kept inside such a subfolder - that's also where any webdialog files, images for toolbar buttons etc will reside...
          Then you have no difficulties setting the menu up via the .rb file AND your code in the .rbs file[s] remains confidential... IF you really have to protect it in this way...

          I just want to try to scramble my code because I (thought I !) can !

          This simple sample is just because I tried to eliminate big chunks of code - and by the first try it went wrong.

          And you'r just right - setting up menues is not something you want to protect - and now I know I CAN'T 😉)

          Best regards
          KSor, Denmark
          Skype: keldsor

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

            So restructure your toolset as "two scripts"...
            An .rb file in the Plugins folder that will auto-load - making the menus/toolbars etc, and the scrambled .rbs file inside the tool's subfolder, which is what the .rb 'requires', and that makes the 'module/class/methods' called by the .rb items...
            😉

            TIG

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

              If you do what TIG suggest you can use the opportunity to make it into a SketchupExtension so it's listed in the Extension list.

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

              1 Reply Last reply Reply Quote 0
              • K Offline
                ksor
                last edited by

                @tig said:

                The Ruby __FILE__ won't work inside a compiled .rbs file, so that's probably breaking it.
                ...
                ...

                Something is not right here - you say the "FILE" won't wotk in .rbs files - NOT TRUE !

                Here is an example and it works fine BOTH as rb- and rbs-file:

                
                require 'sketchup'
                
                filename=File.basename(__FILE__)
                if(not file_loaded?(filename))
                    UI.menu("Plugins").add_item("Bolte") { Sketchup.active_model.select_tool Bolte.new }
                end
                file_loaded(filename)
                
                class Bolte
                
                    # Konstanter til diverse dialoger og statustekster
                    DIAMETER  = "Diameter      ;"
                    HOVEDTYP  = "Hovedtype     ;"
                    SKIVEVED  = "Skive ved     ;"
                    PLACER    = "Placer ved    ;"
                    KOPI      = "Tilføj kopi   ;"
                    
                    FORFRA    = " ELLER højre-klik for at starte forfra !"
                    NOTONFACE = "Det udprikkede punkt er IKKE på en flade !"
                    UDAFEMNET = "Angiv boltlængden ved at klikke, hvor hjælpelinien kommer ud af emnet"
                    EVTFLERE  = "Vælg evt. flere boltplaceringer, indtast fast boltlængde"
                    
                    SEKSKANT  = "6 Kant"
                    UNBRAKO   = "Unbrako"
                    
                    INGEN     = "Ingen"
                    HOVED     = "Hoved"
                    MOETRIK   = "Motrik"
                    BEGGE     = "Begge"
                    UDMAAL    = "Krydsstreger"
                    KLIKMUS   = "Klik med mus"
                    JA        = "Ja"
                    NEJ       = "Nej"
                    
                    
                	def initialize
                        UI.messagebox("Hertil !",MB_OK)
                	end
                	
                	
                end # of class Bolte
                

                I beleave the code witch started this posting is structured EXACTLY likewise - but it will ONLY run as a rb-file, NOT as a rbs-file - i can't see the principal difference:

                require 'sketchup'
                
                filename=File.basename(__FILE__)
                if(not file_loaded?(filename))
                    UI.menu("Plugins").add_item("Remskive") { Sketchup.active_model.select_tool Polley.new }
                end
                file_loaded(filename)
                  
                class Polley
                
                    # store bogstaver evt. med _ er en CONST
                    MINDIAP = 50.mm
                    MINDIAA = 10.mm
                    MINKRVD = 25.mm
                    MINKRVB = 15.mm
                    
                    def initialize()
                       UI.messagebox("Hertil !",MB_OK)
                    end #initialize
                end #class   
                
                

                Can someone pleace tell me why ?

                Both sample codes are cut down to minimal still showing the problem (you can cut out more if you like) - that's why they seems so non sence !

                (>> thomthom: The original files ARE organised as SketchupExtensions - but it's not shown here because I don't think it's part of the problem)

                Best regards
                KSor, Denmark
                Skype: keldsor

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

                  😒 OK... perhaps I should have said something like using 'FILE' won't work inside a .rbs compiled script consistently...
                  When a Ruby runs it has FILE got from the script's own path, which is unique to each script.
                  When a .rbs runs with the FILE code compiled within it, you cannot assume that it will return the path to the .rbs file itself, so if it's returning the path to the 'executing app' it might just work for one .rbs, but then not for any others subsequently, because FILE will NOT point at the .rbs file itself and will have been added to the file_loaded's array already !

                  I can't see why you are spending so much time trying to compile a 'menu setter' - just make it a .rb - that way it's transparent to the user and won't have these issues, it makes the menu items/toolbars etc and required the .rbs files from their subfolder - it's a 'loader'...
                  Then your compiled .rbs files [without any need to include 'menu code'] can go into your tool's subfolder where they belong with the other files a complex tool needs... This is the 'proper' way to do it... IF you must protect your code by compiling it...
                  At the moment getting you code to run properly is much more important, but if you compile it no one can look at it to help you debug because decompiling a .rbs file is not possible...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • K Offline
                    ksor
                    last edited by

                    @tig said:

                    :roll: OK... perhaps I should have said something like using 'FILE' won't work inside a .rbs compiled script consistently...
                    When a Ruby runs it has FILE got from the script's own path, which is unique to each script....

                    Ha, ha, I think I'm the one who should do the 😒 😒 😒 !

                    Can I ask (and get an answer of cause ) is the SCRAMBLER just a prototype ?

                    And please don't turn the focus to me trying to scramble menu setting - that's not the point - it's just a smokescreen over the real problem I think.

                    Even this simple code doesn't work when scrambled and loaded as an extension:

                    require 'sketchup.rb'
                    
                    class Polley
                    
                        # store bogstaver evt. med _ er en CONST
                        MINDIAP = 50.mm
                        MINDIAA = 10.mm
                        MINKRVD = 25.mm
                        MINKRVB = 15.mm
                        
                        def initialize()
                    UI.messagebox("A")
                        end #initialize
                        
                        def draw_pulley()
                        end # draw_polley
                        
                        def input_dialog()
                        end # input_dialog    
                      
                        def makePulley(diaP, diaA, krvD, krvB)
                        end # makePulley
                    end #class   
                    
                    

                    The "A" never comes up 😠 😠 😠 - maybe the scrambler IS a prototype - then just say it then.

                    Best regards
                    KSor, Denmark
                    Skype: keldsor

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

                      You only need to call
                      require 'sketchup.rb'
                      once in a session [it might have been called earlier by another script anyway],
                      do should that in your 'loading' .rb file that makes the 'extension'.
                      Then you can omit it from the .rbs because it's already loaded...
                      OR alternatively try to use
                      Sketchup::require 'xxx'
                      inside a compiled script, which should work...

                      TIG

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

                        The scrambler is not a prototype.
                        It started as @Last's then taken over by Google...
                        So it has been around for many years, but it has always had such issues...
                        But then a few simple ground-rules when devising the set up of your code avoids them.

                        I don't understand your antipathy 😕

                        Either work with what you've been given [taking into account the advice we give freely and kindly], or forget about scrambling things altogether until you are really 'up to steam' on Ruby scripting with the API, OR if you have the ability then write a better scrambler and explain to us how to use it !

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • K Offline
                          ksor
                          last edited by

                          @tig said:

                          You only need to call
                          require 'sketchup.rb'
                          once in a session [it might have been called earlier by another script anyway],
                          do should that in your 'loading' .rb file that makes the 'extension'.
                          Then you can omit it from the .rbs because it's already loaded...
                          OR alternatively try to use
                          Sketchup::require 'xxx'
                          inside a compiled script, which should work...

                          ?????

                          Ha, ha just a new smokescreen ....

                          Whether or not I have the "require 'sketchup.rb'" is not the point - and it has NO difference on the problem !

                          The point is if the scrambler IS a prototype or NOT ... and you have not a single word about it 😒 !

                          I remember to have read somewhere in this forum, that it maybe would be a good idea to write a better scrambler .... I would add: maybe a better interpretor too - not to mention an editor with some intellisence .... that would be really nice.

                          There is much too much 'really low level' debugging going on in what should be a high level language.

                          .... but take Ruby as it is or leave it !

                          Best regards
                          KSor, Denmark
                          Skype: keldsor

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

                            If you make an extension, using SketchupExtension, which loads a .rbs file you'll get namespace trouble.

                            Say you have a plugin written in module FooBar stored a .rbs loaded via SketchupExtension then it will beloaded into SketchupExtension::FooBar instead of the expected root namespace. I seems that SketchupExtension eval into its own namespace. I ran into that problem with Vertex Tools - and because of that had to make an unscrambled proxy loader to ensure everything came into the correct namespace.

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

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

                              @ksor said:

                              The "A" never comes up 😠 😠 😠 - maybe the scrambler IS a prototype - then just say it then.

                              So when you do tried Polley.new nothing happened - no error at all?

                              Your example didn't include anything about how you tested it - maybe there is something there.

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

                              1 Reply Last reply Reply Quote 0
                              • K Offline
                                ksor
                                last edited by

                                @thomthom said:

                                @ksor said:

                                The "A" never comes up 😠 😠 😠 - maybe the scrambler IS a prototype - then just say it then.

                                So when you do tried Polley.new nothing happened - no error at all?

                                Your example didn't include anything about how you tested it - maybe there is something there.

                                I just did the same as with the .rb file - just clicked in the menu: when run by .rb the "A" comes up, when run as .rbs nothing happens - no error, nothing at all.

                                I never used so much time on so little code with so little outcome - it feels like just killing time !

                                Best regards
                                KSor, Denmark
                                Skype: keldsor

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

                                  @ksor said:

                                  I just did the same as with the .rb file - just clicked in the menu: when run by .rb the "A" comes up, when run as .rbs nothing happens - no error, nothing at all.

                                  There is something else going on. I tried that Polley snippet you posted - scrambled it. Loaded the .rbs and wrote in the console: x=Polley.new
                                  The messagebox popped up.

                                  Did you try exactly that small snippet yourself - or did you extract it from your main code? Sounds like your issues lies with the construct of your plugin.

                                  Since you don't get any messagebox, nor any errors when it should pop up it sound like something is overriding the initialize method.
                                  (Remember you cannot reload a .rbs - you must restart SketchUp to see any changes.)

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

                                  1 Reply Last reply Reply Quote 0
                                  • K Offline
                                    ksor
                                    last edited by

                                    @thomthom said:

                                    @ksor said:

                                    I just did the same as with the .rb file - just clicked in the menu: when run by .rb the "A" comes up, when run as .rbs nothing happens - no error, nothing at all.

                                    There is something else going on. I tried that Polley snippet you posted - scrambled it. Loaded the .rbs and wrote in the console: x=Polley.new
                                    The messagebox popped up.

                                    Did you try exactly that small snippet yourself - or did you extract it from your main code? Sounds like your issues lies with the construct of your plugin.

                                    Since you don't get any messagebox, nor any errors when it should pop up it sound like something is overriding the initialize method.
                                    (Remember you cannot reload a .rbs - you must restart SketchUp to see any changes.)

                                    I did EXACTLY that snippet af code - and I start SketchUp from scratch each time I do some tests.

                                    I start it as an extension as recommended and this primary code is here:

                                    require 'sketchup.rb'
                                    require 'extensions.rb'
                                    
                                    filename=File.basename(__FILE__)
                                    if(not file_loaded?(filename))
                                        UI.menu("Plugins").add_item("Remskive") { Sketchup.active_model.select_tool Polley.new }
                                    end
                                    file_loaded(filename)
                                      
                                    # Create the extension.
                                    ext = SketchupExtension.new 'Remskive', 'Remskive/Remskive_LOADER'
                                    
                                    # Attach some nice info.
                                    ext.creator     = 'Keld Sørensen, Danmark'
                                    ext.version     = '1.0.0'
                                    ext.copyright   = '2012..., Keld Sørensen'
                                    ext.description = 'Visit my website; http://kelds.weebly.com/udvidelser.html'
                                    
                                    # Register and load the extension on startup.
                                    Sketchup.register_extension ext, true
                                      
                                    
                                    
                                    

                                    Best regards
                                    KSor, Denmark
                                    Skype: keldsor

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

                                      @ksor said:

                                      I did EXACTLY that snippet af code - and I start SketchUp from scratch each time I do some tests.

                                      I start it as an extension as recommended and this primary code is here:

                                      Did you read my previous comment about namespace and loading scrambled files via SketchupExtension?

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

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

                                        On a sidenote - it can be confusing for the user if the menus are always there - regardless if the extension is loaded. And it'd defeat the purpose of using the extension. Menus should be loaded by the script that SketchupExtension loads.

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

                                        1 Reply Last reply Reply Quote 0
                                        • K Offline
                                          ksor
                                          last edited by

                                          @thomthom said:

                                          On a sidenote - it can be confusing for the user if the menus are always there - regardless if the extension is loaded. And it'd defeat the purpose of using the extension. Menus should be loaded by the script that SketchupExtension loads.

                                          ????
                                          Maybe I misunderstands you - english isn't my first language 😄 - but isn't exactly the opposit of what TIG told me to do ?

                                          Best regards
                                          KSor, Denmark
                                          Skype: keldsor

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

                                            @ksor said:

                                            @thomthom said:

                                            On a sidenote - it can be confusing for the user if the menus are always there - regardless if the extension is loaded. And it'd defeat the purpose of using the extension. Menus should be loaded by the script that SketchupExtension loads.

                                            ????
                                            Maybe I misunderstands you - english isn't my first language 😄 - but isn't exactly the opposit of what TIG told me to do ?

                                            Not quite.

                                            The general structure is:

                                            Plugins/plugin.rb
                                            Defines the SketchupExtension and maybe some constants containing the path of the plugin which the scrambled files can later use.
                                            The extension loads Plugins/MyPlugin/loader.rb

                                            Plugins/MyPlugin/loader.rb
                                            Loads the rest of the .rbs files. You can define the menus here as well.
                                            This proxy unscrambled .rbs file ensures that the content of the rbs files doesn't end up under the SketchupExtension namespace.
                                            Putting the menus there also ensures they are not cluttering the UI while the extension is disabled.

                                            If the .rbs files need to address the path where the plugin is located they would then refer to the path constant previously defined - withing your own namespace of course.

                                            Was that outline somewhat clear?


                                            Engelsk er ikke mitt første språk heller. 😉 (Men jeg bodde der i fire år...)

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

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 3
                                            • 1 / 3
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement