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

    Problems with SketchUp 8 plugins in Sketchup 2015

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 3 Posters 643 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      I assume you are trying to assign a hash to a menu-reference ?
      @@menu[:top]= UI.menu("Plugins")
      Works fine provided the variable={} is predefined.
      I just tried it.
      You must assign @@menu={} as the class/module is created: it needs to be done outside of any class/module's methods that will use it later...
      for example:

      class MyClass
        @@menu={}
        def some_method()
          @@menu[;top]= UI.menu("Plugins")
          ...
        end
      end
      

      or

      module MyModule
        @@menu={} ### or @menu={} etc
        def self.some_method()
          @@menu[;top]= UI.menu("Plugins")
          ...
        end
      end
      

      You haven't explained why it needs to be a @@ variable ??
      Why not @menu={} ?
      Or it could just as easily be a Constant ? Menu={}
      Without seeing and understanding all of your code it's impossible to resolve this.

      TIG

      1 Reply Last reply Reply Quote 0
      • A Offline
        Andreas
        last edited by

        It is a little bit complex.
        I don´t want to show hundreds of lines code here.
        So I try it like this:

        # File in SketchUp-Plugins
        
        require('sketchup.rb')
        require('extensions.rb')
        
        module ABSBMP  ### ( Toplevel namespace)
        
          module MoMo  ### ( This plugin's nested namespace. )
            @@relExtPfad = 'ABSBMP/mo_mo_moebel' # relative path 
            @@ladeprogramm = 'mo_mo_load'        # load script 
        	
            ...
            @@plugin = SketchupExtension.new( @@sagExt;titel],File.join@@relExtPfad,@@ladeprogramm) )
            ...
        		
            Sketchup.register_extension( @@plugin, true )
        		
          end # module MoMo
        end # module ABSBMP		
        
        file_loaded('Plugins;ABSBMP_mo_mo_moebel_ext')  # global method from 'Tools/sketchup.rb'
        
        
        
        
        # File (@@ladeprogramm 'mo_mo_load') in subdirectory (@@relExtPfad)
        
        require('sketchup.rb')
        
        module ABSBMP;;MoMo
          Sketchup.require(File.join(@@relExtPfad,'mo_mo_main'))
        end  # < module ABSBMP;;MoMo 
        
        file_loaded('ABSBMP;mo_mo_load')  # global method from 'Tools/sketchup.rb'
        
        
        
        
        
        # File ('mo_mo_main') in subdirectory (@@relExtPfad)
        
        require('sketchup.rb')
        
        module ABSBMP;;MoMo
            ...
            @@menu[;top]= UI.menu("Plugins")
            ...
        		
        end  # module ABSBMP;;MoMo 
        
        file_loaded('ABSBMP;mo_mo_main')  # global method from 'Tools/sketchup.rb'		
        		
        

        With best regards from Germany

        Andreas

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

          module ABSBMP  ### ( Toplevel namespace)
            module MoMo  ### ( This plugin's nested namespace. )
              @@menu={} ### Otherwise the hash is nil !
          

          TIG

          1 Reply Last reply Reply Quote 0
          • A Offline
            Andreas
            last edited by

            Sorry, my mistake. It is not complete, I forgot something.
            This should be correct:

            # File in SketchUp-Plugins
            
            require('sketchup.rb')
            require('extensions.rb')
            
            module ABSBMP  ### ( Toplevel namespace)
            
              module MoMo  ### ( This plugin's nested namespace. )
                @@relExtPfad = 'ABSBMP/mo_mo_moebel' # relative path 
                @@ladeprogramm = 'mo_mo_load'        # load script 
               
                ...
                @@plugin = SketchupExtension.new( @@sagExt;titel],File.join@@relExtPfad,@@ladeprogramm) )
                ...
                  
                Sketchup.register_extension( @@plugin, true )
                  
              end # module MoMo
            end # module ABSBMP      
            
            file_loaded('Plugins;ABSBMP_mo_mo_moebel_ext')  # global method from 'Tools/sketchup.rb'
            
            
            
            
            
            # File (@@ladeprogramm 'mo_mo_load') in subdirectory (@@relExtPfad)
            
            require('sketchup.rb')
            
            module ABSBMP;;MoMo
               Sketchup.require(File.join(@@relExtPfad,'mo_mo_main'))
            end  # < module ABSBMP;;MoMo 
            
            file_loaded('ABSBMP;mo_mo_load')  # global method from 'Tools/sketchup.rb'
            
            
            
            
            
            # File ('mo_mo_var_get') in subdirectory (@@relExtPfad)
            
            require('sketchup.rb')
            
            module ABSBMP;;MoMo   
              
              ### MODUL-VARIABLEN  ( MODULE VARIABLES )
            
               ...
               #{# Menüs  ( Menus )
               #
                 @@menu = {}
               #
               #}#	
               ...
            	
            end  # module ABSBMP;;MoMo
            
            file_loaded('ABSBMP;mo_mo_var_get')  # global method from 'Tools/sketchup.rb'	
            
            
            
            
            
            # File ('mo_mo_main') in subdirectory (@@relExtPfad)
            
            require('sketchup.rb')
            
            module ABSBMP;;MoMo
                ...
                @@skript = ["mo_mo_var_get"]		
            		
                Sketchup;;require(File.join(@@relExtPfad,@@skript))		
                ...
            
            
                ...
                @@menu[;top]= UI.menu("Plugins")
                ...
               
            
               
            end  # module ABSBMP;;MoMo 
            
            file_loaded('ABSBMP;mo_mo_main')  # global method from 'Tools/sketchup.rb'      
            
            
            
            

            With best regards from Germany

            Andreas

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

              Why don't you simply set up @@menu = {}
              inside the first loading file which creates
              module ABSBMP::MoMo
              Then the loading order of the rest of the files [which seems unnecessarily complicated!] become unimportant.

              TIG

              1 Reply Last reply Reply Quote 0
              • A Offline
                Andreas
                last edited by

                It is a large application. Therefore it is comprehensible to declare the variable in a separate file.

                But it seems, that the real problem is included elsewhere. So I've changed my method. Till now I've tried to find out what does not work. Now I am trying to find out what works.

                In that process I found an error in the following code:

                
                require('sketchup.rb')
                
                module ABSBMP;;MoMo
                ...
                
                ...
                
                class << self
                
                  # Proxy class inside module ABSBMP;;MoMo
                
                  # Create Reader methods for currently defined module variables.
                  #{
                  ABSBMP;;MoMo;;class_variables.each do |varstr|
                
                    kind = eval %[#{varstr}.class]
                		
                    attstr = varstr.gsub(/(\A@@)/,'')  <-- Error; #<NoMethodError; undefined method `gsub' for ;@@relExtPfad;Symbol>
                				
                    # Reader Method 
                    unless ['@@sag','@@skript'].include?(varstr)
                      eval %[def #{attstr}(); return #{varstr}; end;]
                      if kind.is_a?(TrueClass) || kind.is_a?(FalseClass)
                        eval %[alias_method('#{attstr}?','#{attstr}');]
                      end
                    end
                
                  end #} do class_variables.each
                
                
                end  # Proxy class 
                
                end  # module ABSBMP;;MoMo
                
                file_loaded('ABSBMP;mo_mo_var_get')  # global method from 'Tools/sketchup.rb'
                
                
                
                

                %(#4040FF)[The error-message is shown at the start of SketchUp 2015.
                In SketchUp 8 it works well!!!]

                With best regards from Germany

                Andreas

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

                  Perhaps: varstr.to_s.gsub...
                  Since I don't understand what your code is trying to do it's not that easy to help...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    Andreas
                    last edited by

                    @unknownuser said:

                    Perhaps: varstr.to_s.gsub...

                    Is a good idea, but does not really works.

                    It works like this:

                    
                       varstr = varstr.to_s
                       attstr = varstr.gsub(/(\A@@)/,'')
                    
                    

                    The names of the module variables will be reduced by the first two "@" sign.
                    This names will be used later as descriptions to make the color settings. For example for cabinet sides, cabinet doors, tabletops ...

                    We are manufacturer of office furniture.
                    http://www.momo-moebel.de/

                    The application is used to create plans for office furniture.
                    You can get the plugins as a free download for usage with SketchUp 8 from our homepage.
                    http://www.momo-moebel.de/fileadmin/service/mo_mo_SketchUp_V_3_2_06.zip
                    We want to offer that for current sketchup Versions. Therefore, we are reworking the SketchUp plugins.

                    With best regards from Germany

                    Andreas

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

                      So your code
                      ABSBMP::MoMo::class_variables
                      returns an Array of Symbols
                      >>> [:@@a, :@@b,...]
                      So you need the step varstr = varstr.to_s to make it into a String.
                      :@@a >>> "@@a"
                      Then you use attstr = varstr.gsub(/^[@][@]/, "") to strip off the initial '@@'...

                      TIG

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

                        @@skript = ["mo_mo_var_get"]
                        should be just:
                        @@skript = "mo_mo_var_get"

                        I'm not here much anymore.

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

                          @tig said:

                          So your code
                          ABSBMP::MoMo::class_variables
                          returns an Array of Symbols
                          >>> [:@@a, :@@b,...]
                          So you need the step varstr = varstr.to_s to make it into a String.
                          :@@a >>> "@@a"
                          Then you use attstr = varstr.gsub(/^[@][@]/, "") to strip off the initial '@@'...

                          Many of the global query methods changed from Ruby 1.8 to Ruby 2.0.

                          They now return arrays of symbols (for each variable or method name.) In Ruby 1.8 they returned array of string (for each variable or method name.)

                          There are also many other "breaking changes" in Ruby 2.0 that need to be dealt with.
                          (@TIG, Was there a post here on breaking changes?)


                          Also garbage collection is much better under Ruby 2.0, so any menu reference will most likely only be valid during the evaluation of the file in which the reference is first made by an API call.
                          So the attempt to hold the reference @@menu[:top] across multiple files may no longer work.

                          We have been complaining about the non persistence of UI element references, for years! (Especially menu references.)

                          So the workaround is to save the menu NAME (as a string,) instead of the actual reference to the menu object.
                          @@menu[:top]= "Plugins"
                          ... then whenever you need the object reference, use:
                          topmenu = UI.menu( @@menu[:top] )
                          or
                          submenu = UI.menu( @@menu[:top] ).add_submenu( "MoMo" )

                          💭

                          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