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

    Push Pull direction?

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

      I have put your post's 'code' inside 'code' []braces[/] - it's impossible to read meaningfully otherwise.
      Please learn to use these...

      A few general comments...
      I know the class is not currently activated but it should be **P**olley
      The menu item should be something like
      UI.menu("PlugIns").add_item("Kileremskive"){KSOR::Polley.draw_pulley()}
      Put require 'sketchup.rb'
      before the module starts - it only gets used if sketchup.rb hasn't been loaded before - it is a failsafe, if you are using any methods that this system script might need to have loaded...
      Why do you need to check whether this is a PC or MAC tool ?
      Most scripts/tools run just fine on both platforms you only need to check when some code is platform specific...
      Please learn to use @ NOT $ variables.
      Also
      if ($diaP < MINDIAP) then $diaP = MINDIAP
      will work without and 'end' IF it's this way round
      $diaP = MINDIAP if $diaP < MINDIAP
      [although you do need to test if the variable is set with
      $diaP = MINDIAP if not @diaP or @diaP < MINDIAP
      also use @diaP NOT $diaP!]
      You don't normally use/need a 'then' in an 'if' test in Ruby, although it won't beak anything, BUT you do need the 'end' unless the result is place before the 'if' as I have shown...
      Also learn to enclose arguments inside () with no space between the opening ( and its method - 'loose' arguments may be deprecated in future Ruby updates and therefore the API docs are all pretty much out of date...
      You could probably do with less transformations/exploding etc if you placed objects where you wanted them initially. I'd recommend you put all of your new geometry inside a group [or component] as it means there are no unexpected clashes with existing geometry... I haven't changed much of this though...

      I've recast your code into a working example for you [attached] - see how I have adjusted parts and then feel free to ask us more questions...


      !!!.rb

      TIG

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

        OK - nice with your comments and alternative if's and I'll study that closely BUT

        What about my WHILE-problem ?
        Do you mean that IF I DO like you said then this problem will disappear or .. ?

        Best regards
        KSor, Denmark
        Skype: keldsor

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

          Read my edited post and the attachment...
          The end was because the 'if' aren't properly formed and the first one 'steals' the while's end.
          BUT my example shows how to avoid this 'while' loop altogether !
          There were a number of overlaid issues - it's best to see my alternative reworking on how some things are just avoided/omitted or alternative forms will work as you hope...

          TIG

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

            OH, sorry I didn't see there was an attachment - sorry !

            Best regards
            KSor, Denmark
            Skype: keldsor

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

              @tig said:

              Read my edited post and the attachment...
              The end was because the 'if' aren't properly formed and the first one 'steals' the while's end.
              BUT my example shows how to avoid this 'while' loop altogether !
              There were a number of overlaid issues - it's best to see my alternative reworking on how some things are just avoided/omitted or alternative forms will work as you hope...

              Yeah, but now you took it a little further than I can cope with !

              AND

              😆 you should have tried to input a lower value than the minimum allowed - if you do you get this error:

              Error: #<NoMethodError: private method initialize' called for #<KSOR::Polley:0xa9cd790>> C:/Program Files/Google/Google SketchUp 8/Plugins/RemSkive.rb:43:in dialog'
              C:/Program Files/Google/Google SketchUp 8/Plugins/RemSkive.rb:25:in initialize' C:/Program Files/Google/Google SketchUp 8/Plugins/RemSkive.rb:5:in new'
              C:/Program Files/Google/Google SketchUp 8/Plugins/RemSkive.rb:5

              and NO re-asking of new input but that's surely caused by the error.

              Best regards
              KSor, Denmark
              Skype: keldsor

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

                OK simple typo - simple fix.
                THIS version recalls the dialog on an invalid entry...
                See how I split a 'draw_pulley' method off from the un-callable 'initialize' that I had inadvertently typed....
                You should recognize much of your code/steps in the reworked version - I've just avoided the pitfalls of your while-loop, un-ended if's etc etc...


                !!!.rb

                TIG

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

                  $exStrings.GetString("Specifikationer") will NOT work. All LanguageHandler keys are English. The values that are returned, are in the other language.

                  You can open the strings files Notepad++ to see what the English key are.

                  Or at the console:
                  $exStrings.GetStrings.each_pair{|k,v| puts( %[key: "#{k}" = "#{v}"] )}

                  You can only access $exStrings if the Examples extension is enabled by the user. You should not rely upon it.

                  I'm not here much anymore.

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

                    @dan rathbun said:

                    $exStrings.GetString("Specifikationer") will NOT work. All LanguageHandler keys are English. The values that are returned, are in the other language.

                    You can open the strings files Notepad++ to see what the English key are.

                    Or at the console:
                    $exStrings.GetStrings.each_pair{|k,v| puts( %[key: "#{k}" = "#{v}"] )}

                    You can only access $exStrings if the Examples extension is enabled by the user. You should not rely upon it.
                    I've removed these from my test code as he doesn't need them, neither does he need to test for 'platform' either...
                    I think that he's trying to apply methods and ideas from several sources and thereby making a script that's much more convoluted that it needs to be...
                    At the moment it's actually a simple script to ask for some dimensions and create a 3d pulley wheel from them...

                    TIG

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

                      I'll study the code and compare it with my thinking of Class, Objects, properties ect.

                      But I beleave this is "the right! structure or ... ?

                      The next Object - let's a a drivebelt - should use this code as "template" (the structure) or ...?

                      Best regards
                      KSor, Denmark
                      Skype: keldsor

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

                        I think you are being over analytical.
                        There are many things you can do with Ruby, but in your case checking 'platform', 'translating' strings and so on... are far more than you need to do yo complete what you are trying for.
                        Meanwhile there are a few things that you are not doing, which we'll skim over for now as 'sufficient is fit'... it works without them and they are 'nice-to-haves'...

                        TIG

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

                          Ha, ha, too analytical - you can't be when working with OOP, I beleave.

                          😄 I'm just trying to get a nice structure from begining of my Ruby eara.

                          Dan

                          ???? I don't know what you mean:
                          "$exStrings.GetString("Specifikationer") will NOT work. All LanguageHandler keys are English. The values that are returned, are in the other language."

                          It DID work fine, eventhough I can see TIG changed it - in fact it did work.

                          My test for Mac or PC was code I found and I thought that code for Mac WAS special so why not make a test - but OK it's obsolete.

                          Now I'll try to finish the pulley thing !

                          Best regards
                          KSor, Denmark
                          Skype: keldsor

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

                            The 'getStings' coded parts won't 'work' because it won't find your Danish word to translate in the standard '.stings' file, which is in English !
                            Adding that code does no real harm, other than slowing things down slightly, because every time it checks for a translation it doesn't find it and uses the original string anyway...
                            The principal of a 'language translator' tool is that the strings in the script-file also exist in a 'look-up' file - typically a '.strings' file [or for purpose made translators like my deBabelizer.rb it a .lingvo files]; the English word is matched against the foreign word FR Cat<==>Chat or ES Cat<==>Gato etc. I don't think Danish is a Sketchup 'locale' though. However if you are using an EN-US locale with a script using my deBabelizer lingvos appropriately then taking the standard ...EN-US.lingvo and swapping the Cat<==>Cat for Cat<==>Kat etc etc would display menus,prompts,dialogs etc in Danish strings rather than English...
                            I suspect this is something not high on your agenda...

                            The issue of testing for PC/MAC only arises when you do something that is platform specific - most simple API code is cross-platform; however, you might one day move on to Tools which for example involve key-presses, and these key-codes can vary between PC and MAC so you need to use different code depending on the platform test results; there are also add-ons like Win32ole.so and Win32api.so that add links from Ruby into the Windows system and even other app's like Excel - these cannot be used on a MAC so again you need to trap for that possibility... BUT your relatively simple code needs no sure 'traps'...
                            🤓

                            TIG

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

                              @ksor said:

                              Dan
                              ???? I don't know what you mean:
                              "$exStrings.GetString("Specifikationer") will NOT work. All LanguageHandler keys are English. The values that are returned, are in the other language."

                              It DID work fine, eventhough I can see TIG changed it - in fact it did work.

                              What TIG said is true.

                              You don't need to worry about translating plugins just yet.

                              $exStrings.GetString("khbgjubgeg663buib")
                              returns >> "khbgjubgeg663buib"
                              ... because the key "khbgjubgeg663buib" does not exist in the hash, and the LanguageHandler just echos the key (assuming it would be a valid English string.)

                              It is a fallback feature. (I suppose Google should have output a "Key not found" warning to the console.)

                              I'm not here much anymore.

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

                                OK - I see it's for internationalization of the code - I misunderstood this in the first place.

                                Best regards
                                KSor, Denmark
                                Skype: keldsor

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

                                  @tig said:

                                  OK simple typo - simple fix.
                                  THIS version recalls the dialog on an invalid entry...
                                  See how I split a 'draw_pulley' method off from the un-callable 'initialize' that I had inadvertently typed....
                                  You should recognize much of your code/steps in the reworked version - I've just avoided the pitfalls of your while-loop, un-ended if's etc etc...

                                  Now I'm a little over analytical again 😄 - I think your code here contains a bomb:

                                  			def draw_pulley()
                                                  # default MINIMUM values
                                                  @diaP = MINDIAP if not @diaP or (@diaP < MINDIAP) 
                                                  @diaA = MINDIAA if not @diaA or (@diaA < MINDIAA) 
                                                  @krvD = MINKRVD if not @krvD or (@krvD < MINKRVD) 
                                                  @krvB = MINKRVB if not @krvB or (@krvB < MINKRVB)
                                  				return nil unless self.dialog()
                                  				self.draw_beltProfile()
                                                  self.set_beltProfileOnWheel()
                                                  self.pull_pulley()
                                                  self.pull_krave()
                                  		    end
                                  			
                                  		    def dialog()
                                  					prompts = ["Skivediameter (mm) ;",
                                                             "Akseldiameter (mm) ;",
                                                             "Kravediameter (mm) ;",
                                                             "Kravebredde   (mm) ;"]
                                                      values = [@diaP, @diaA, @krvD, @krvB]
                                                      results = inputbox(prompts, values, "Specifikationer")
                                                      return nil if not results
                                  					diaP, diaA, krvD, krvB = results
                                  					if (diaP < MINDIAP) || (diaA < MINDIAA) || (krvD < MINKRVD) || (krvB<MINKRVB)
                                                          UI.messagebox("Mindsteværdi er genindsat - de(n) SKAL overholdes !", MB_OK)
                                  						self.draw_pulley()
                                  						return nil
                                  					else
                                  					    @diaP, @diaA, @krvD, @krvB = results
                                  						return true
                                                      end
                                              end    
                                  
                                  

                                  The call to self.draw_pulley is a sort of recursive - just returning nil would be better and then this in the initializing method:

                                  				until self.draw_pulley() != nil 
                                              end
                                  
                                  

                                  Right ?

                                  Best regards
                                  KSor, Denmark
                                  Skype: keldsor

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

                                    Sorry, I don't quite understand your point... 😕

                                    The tool initializes, it runs self.draw_pulley(), which runs self.dialog() and tests for the validity of its ' return'.
                                    If the user cancels the dialog ' nil' is returned and it stops.
                                    If the user enters valid inputs it returns ' true' and the remaining steps are executed to completion.
                                    If the user enters invalid input it then re-runs self.draw_pulley() [], which in turn runs self.dialog() and tests for its validity in its ' return' etc etc in a loop until either the user cancels or enters valid input...
                                    [
                                    after it re-calls the method it immediately returns ' nil' to the previously executing version of the method, so that one goes no further]
                                    Note how two sets of references are taken from the ' results', one to test their validity and if OK then another @ set to be used in the next methods and also remembered for the next time...
                                    I left it this way because that's what you originally showed... personally I feel that a simple
                                    UI.messagebox("Values outside limits !\nExiting.") return nil
                                    would do, but at least this way the user does get chances to try again with a valid input in a new dialog - if they want to give up they can just cancel the dialog at any time...

                                    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