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

    Separating a plugin from others

    Scheduled Pinned Locked Moved Developers' Forum
    22 Posts 7 Posters 1.1k Views 7 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.
    • daikuD Offline
      daiku
      last edited by

      When you create an object from the class, you have to specify which module it should come from. This code works fine for me:

      
      module Mod1
      	class Test
      		def id
      			puts "Mod1 Test"
      		end	
      	end
      end
      
      module Mod2
      	class Test
      		def id
      			puts "Mod2 Test"
      		end
      	end
      end
      
      t1 = Mod1;;Test.new
      t2 = Mod2;;Test.new
      
      t1.id
      t2.id
      
      

      Result:

      
      Mod1 Test
      Mod2 Test
      
      

      Note that I create two objects (t1 and t2), one of each class. I get away with the classes having the same name because they live in different modules. CB.

      Clark Bremer
      http://www.northernlightstimberframing.com

      1 Reply Last reply Reply Quote 0
      • T Offline
        tomasz
        last edited by

        I see, so doing:
        t3 = Test.new
        Will get unexpected results!

        Thank you!

        Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

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

          @unknownuser said:

          I see, so doing:
          t3 = Test.new
          Will get unexpected results!

          Thank you!

          Depends in what cope you are in.

          
          module Mod1
             class Test
                def id
                   puts "Mod1 Test"
                end   
             end
             t1 = Test.new # Should refer to Mod1;;Test
          end
          
          module Mod2
             class Test
                def id
                   puts "Mod2 Test"
                end
             end
             t2 = Test.new # Should refer to Mod2;;Test
             t4 = Mod1;;Test.new
          end
          
          t3 = Test.new # I don't know if this will even work
          
          

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

          1 Reply Last reply Reply Quote 0
          • T Offline
            tomasz
            last edited by

            @unknownuser said:

            Sketchup.load 'Plugin.rbs'
            returns 0 (!=true or false).
            There is no explanation in the API for such a case.

            Is there someone from Google who can tell me what 0 means in this case?
            It happens on Vista64 SU 7.1.

            Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

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

              What is Plugin.rbs ?

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

              1 Reply Last reply Reply Quote 0
              • T Offline
                tomasz
                last edited by

                @chris fullmer said:

                What is Plugin.rbs ?

                I have used SDK Scrambler on Plugin.rb file >> Plugin.rbs.
                It is 'a' plugin name. Not relevant in this case.

                Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

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

                  Once you scramble a file, there are problems with it loading. I think you have to hard code the path into the file.

                  I'm not sure if you use the FILE constant in your script, but I tihnk that might not work in a scrambled script. I'm sure others here know more about this. But I do know that scrambled scripts are a little trickier to load somehow....Perhaps that is why it seems to not be loading?

                  Chris

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

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

                    @unknownuser said:

                    @unknownuser said:

                    Sketchup.load 'Plugin.rbs'
                    returns 0 (!=true or false).
                    There is no explanation in the API for such a case.

                    Is there someone from Google who can tell me what 0 means in this case?
                    It happens on Vista64 SU 7.1.

                    Does the plugin load? Might be the manual that's incorrect, and it returns 1 on success and on failure?

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

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      Jim
                      last edited by

                      Sketchup.load acts like Sketchup.require which acts like require - which means it checks the $" special global variable before loading.

                      0 could mean it has already been loaded. Check the $" variable in the Ruby Console window to see if the file is already on the list.

                      Hi

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        tomasz
                        last edited by

                        @chris fullmer said:

                        I'm not sure if you use the FILE constant in your script, but I tihnk that might not work in a scrambled script. I'm sure others here know more about this. But I do know that scrambled scripts are a little trickier to load somehow....Perhaps that is why it seems to not be loading?

                        I just realized same thing. I do use FILE. I will hard code it. I am not sure if it will be unless file_loaded?('Plugin.rb') or unless file_loaded?('Plugin.rbs'). Will check it.

                        @thomthom said:

                        Does the plugin load? Might be the manual that's incorrect, and it returns 1 on success and on failure?

                        The plugin loads automatically on my machine (Vista32Home). When I Sketchup.load 'Plugin.rbs' it returns 0 .. which may mean that the plugin has been already loaded.
                        The thing is that an user on Vista64 gets olso 0, but there is no plugin whatsoever in his Plugins menu.

                        I have another tester with Vista64 and it works fine for him, so there must be some interaction with a different plugin I believe.

                        Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                        1 Reply Last reply Reply Quote 0
                        • J Offline
                          Jim
                          last edited by

                          @unknownuser said:

                          I am not sure if it will be unless file_loaded?('Plugin.rb') or unless file_loaded?('Plugin.rbs'). Will check it.

                          Not important - can be any string. It just adds the string to a global variable. It is something invented for Sketchup for the sole purpose of guarding the menus from adding multiple entries.

                          Yeah - I think I'll call them "menu guards".

                          Hi

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

                            I can confirm. Sketchup.load returns 0 (fixnum class) if it loaded and false (falseclass) if it did not load.

                            Odd, that should go in as a bug fix, and an API fix?

                            Chris

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

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              tomasz
                              last edited by

                              @jim said:

                              Not important - can be any string...
                              Yeah - I think I'll call them "menu guards".

                              So FILE is not the issue. I think I have a problem with a different plugin, that stops mine to load into Plugins.
                              Thanks for explanation.

                              Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

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

                                You say its a Vista user with problems? Nearly all the Vista problems I get are related to the "Compatibility Files" folder. Sometimes when a user downloads a file directly to the plugins folder, it will put it into a safe compatilibity folder, and it does not appear in the plugins folder.

                                Have the user check their compatibility folder, delete any old versions of your plugin, reinstall, and try again. That might help.

                                Chris

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

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  tomasz
                                  last edited by

                                  I have discovered something important for those who use rbs.
                                  If you check if your plugin has already been loaded with:
                                  file_loaded?(File.basename(__FILE__))
                                  from inside of a rbs file - the FILE value == '(eval)' !
                                  If there are two rbs plugins which use the same method, the first will block the second.
                                  That is why my rbs has been loaded, but didn't create a menu in Plugins.

                                  Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

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

                                    @unknownuser said:

                                    If you check if your plugin has already been loaded with:
                                    file_loaded?(File.basename(__FILE__))
                                    from inside of a rbs file - the FILE value == '(eval)' !

                                    Sounds like File.basename(FILE) is getting set to part of an eval error string.
                                    I wonder if eval error strings are put to the $! message global?

                                    I'm not here much anymore.

                                    1 Reply Last reply Reply Quote 0
                                    • tbdT Offline
                                      tbd
                                      last edited by

                                      FILE when ruby is scrambled is useless as it gets evaled, so you cannot use it. had the same problem when developing/using Sketchup Bridge.

                                      workaround: add the path to the global search path for loading scripts $:

                                      SketchUp Ruby Consultant | Podium 1.x developer
                                      http://plugins.ro

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

                                      Advertisement