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

    Methods from Support files

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 204 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.
    • K Offline
      ktkoh
      last edited by

      I am trying to move some def's that are common to most of my joint scripts to a support file. I am already using Arithmetic parsing.rb which I think Jim sent me to convert equations into calculated lengths. I thought I could add other def's there and use them from the main program. I get this error message
      Error: #<NoMethodError: undefined method cal_xCL_points' for ArithmeString:Module> C:\Users\Keith\Documents\ShopProjects\TestPlugins\K2WS_Tools\KK_Tools_Template.rb:214:in onLButtonDown'

      The code in the support file is:

        def ArithmeString.cal_xCL_points(x1,e_len,dir_x,spacing,qty)
          @xcl=Array.new qty.to_i
          case spacing
            when "Symetrical"
              #Debug UI.messagebox("Spacing = " + spacing.to_s)
              if qty == 1
                @xcl[0]=x1+(end2CL*dir_x)
                #Debug UI.messagebox("@xcl[0] = " + @xcl[0].to_s)
                #Debug UI.messagebox("Completed qty = " + qty.to_s)
              elsif qty == 2
                @xcl[0]=x1+(end2CL*dir_x)
                @xcl[1]=x1+((e_len-end2CL)*dir_x)
                #Debug UI.messagebox("Completed qty = " + qty.to_s)        
              elsif qty == 3
                @xcl[0]=x1+(end2CL*dir_x)
                @xcl[1]=x1+((e_len/2)*dir_x)
                @xcl[2]=x1+((e_len-end2CL)*dir_x)
                #Debug UI.messagebox("Completed qty = " + qty.to_s)
              elsif qty >= 4
                #Debug UI.messagebox("Started qty = " + qty.to_s)
                @xcl[0]=x1+(end2CL*dir_x)
                @xcl[qty-1]=x1+((e_len-end2CL)*dir_x)
                @xcl[qty/2]=x1+((e_len/2)*dir_x)
                n =(qty-2)/2  #loop number
                sn = 1 #Starting number
                i = 0
                while n > 0
                  temp_offset=cl_offset[i]
                  #Debug  UI.messagebox("CL Offset = "+ temp_offset.to_s)
                  @xcl[sn]=@xcl[sn-1]+((temp_offset)*dir_x)
                  @xcl[qty-1-sn]=@xcl[qty-sn]-((temp_offset)*dir_x)
                  sn = sn + 1
                  n = n -1
                  i = i + 1
                end # while n > 0                
              end #if qty == 
              #Debug  @xcl.each {|e| UI.messagebox("Symetrical CL point = "+ e.to_s)}           
            when "Equal"
              #Debug UI.messagebox("Case Spacing = " + spacing.to_s)
              equal_offset=(e_len-(end2CL*2))/(qty-1)
              @xcl[0]=x1+(end2CL*dir_x)
              @xcl[qty-1]=x1+((e_len-end2CL)*dir_x)
              n =(qty-2)  #loop number
              sn = 1 #Starting number
              while n > 0
                @xcl[sn]=@xcl[sn-1]+((equal_offset)*dir_x)
                sn = sn + 1
                n = n -1
              end # while n > 0
              #Debug @xcl.each {|e| UI.messagebox("Equal CL point = "+ e.to_s)}        
            when "User"
              #Debug UI.messagebox("Case Spacing = " + spacing.to_s)
              @xcl[0]=x1+(end2CL*dir_x)
              n =(qty-1)  #loop number
              sn = 1 #Starting number
              i = 0
              while n > 0
                user_offset=cl_offset[i]
                #user_offset=user_offset.to_l
                #Debug UI.messagebox("user_offset = "+ user_offset.to_s)
                @xcl[sn]=@xcl[sn-1]+((user_offset)*dir_x)
                sn = sn + 1
                i = i + 1
                n = n -1
              end # while n > 0
              #Debug @xcl.each {|e| UI.messagebox("User CL point = "+ e.to_s)} 
            when "Fixed"
              #Debug UI.messagebox("Case Spacing = " + spacing.to_s)
              @xcl[0]=x1+(end2CL*dir_x)
              n =(qty-1)  #loop number
              sn = 1 #Starting number
              while n > 0
                fixed_offset=cl_offset[0]
                @xcl[sn]=@xcl[sn-1]+((fixed_offset)*dir_x)
                sn = sn + 1
                n = n -1
              end # while n > 0
              #Debug @xcl.each {|e| UI.messagebox("Fixed CL point = "+ e.to_s)}         
          end #case spacing
          #Debug UI.messagebox("End Spacing = " + spacing.to_s)
        end #cal_xCL_points
      

      the code in the main file is:

      UI.messagebox"Calculations and then Add Features for first part"
                x1=0; e_len=6.0; dir_x=1;spacing="Symetrical"; qty=3
                ArithmeString.cal_xCL_points(x1,e_len,dir_x,spacing,qty)
                UI.messagebox("Center line points = " + @xcl[1].to_s)
      

      I know the file is read because in earlier statements I used:

      todist_input=ArithmeString.string_to_length(results[1].to_s)
          if !todist_input then todist_input=results[1] end
          @@todist=todist_input; ans[1] = @@todist
      

      and this works properly

      As always I appreciate the help. [I do use the SketchUp Book, examples and api code and try lots of things before asking].
      Keith

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

        Where is this 'support-file'... is it auto-loaded or do you 'require' it or 'load' it from a subfolder?
        To test if it's loading add a line in the start of the
        def ArithmeString.cal_xCL_points(x1, e_len, dir_x, spacing, qty)as puts "ArithmeString.cal_xCL_points is here!"
        Then in the Ruby Console type
        ArithmeString.cal_xCL_points(1, 1, 1, 1, 1)
        I know what's passed to it will likely break it... but at least we'll get to the "ArithmeString.cal_xCL_points is here!" in the Ruby Console, IF it's been loaded and it runs...
        πŸ˜•

        TIG

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

          Thanks TIG that got me going. I found that my program was using the Arithmetic methods from an already loaded file.
          However as I got into i farther I found that I was going to have to rewrite to pass several more variables and I am going to leave that for another time. I revised the names and added KK_ to the front so I would know where the methods were that I was using.

          Thanks
          Keith

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

            Your trying to add a module function to an existing module.

            Your method def needs to be wrapped within a:
            module ArithmeString #---- paste method def here end
            block, otherwise the instance var @xcl will be inaccessible.

            I'm not here much anymore.

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

              THIS thread needs to be moved to the Developer's forum.

              I'm not here much anymore.

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

                Moved.

                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