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

    Problem with rotation in a Ruby script

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

      Hi everybody,

      I'm new in Ruby but have some experience in other programming languages. At the moment I'm working in a script to create planar sundials to simulate them in SU before making the final device. To do this I need to rotate the style by a certain angle (geographic latitude) that is passed by the user to the script. If I use the variable "incl" in the script nothing happens, but if the variable is replaced by a number (e.g. 45) it works perfectly.

      Does anyone know what can be wrong? I searched in many different sites and foruns, but wasn't able to make it work.

      def teste
        prompts = ["Inclination"]
        values = [0.0]
        results = inputbox prompts, values, "Specs"
        return if not results
        incl = results
        model = Sketchup.active_model
        model.start_operation "Draw"
        entities = model.active_entities
        group = entities.add_group
        entities = group.entities
        circle = entities.add_circle([0,0,0], Z_AXIS, 8.mm, 24)
        cyl_base = entities.add_face(circle)
        cyl_base.pushpull -100
        entities.transform_entities(Geom;;Transformation.rotation([0,0,0],[1,0,0],incl.degrees),group)
      #entities.transform_entities(Geom;;Transformation.rotation([0,0,0],[1,0,0],45.degrees),group)
        model.commit_operation
      end
      if( not file_loaded?("teste.rb") )
        add_separator_to_menu("Draw")
        draw_menu = UI.menu("Draw")
        teste_menu = draw_menu.add_item("teste") { teste }
      end
      file_loaded("teste.rb")
      

      Thanks for any tip.

      Best regards,
      Ricardo

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

        inputbox returns an Array, so incl is an Array and there is no .degrees method for Array.

        
        incl = results[0]
        
        

        Smack - the sound of your palm hitting your forehead.

        Hi

        1 Reply Last reply Reply Quote 0
        • R Offline
          Ricardo
          last edited by

          Jim,

          Thanks for the fast response. I made the change and it works properly, but I'm still confused because the variable "incl" is displayed properly using the UI.messagebox without using the index of the array. The same happens with the variable "factor". If I make the product of "incl" and "factor" and use the result in the rotattion command it works fine as well (see code). Does this mean that only in certain methods (eg. rotation) the index of the matrix must be used?

          def teste
            prompts = ["Inclination", "Factor"]
            values = [0.0, 0.0]
            results = inputbox prompts, values, "Specs"
            return if not results
            incl, factor = results
          
            UI.messagebox(incl.to_s)
            x = incl * 2
            UI.messagebox(x.to_s)
          
            model = Sketchup.active_model
            model.start_operation "Create Cylinder"
            entities = model.active_entities
            group = entities.add_group
            entities = group.entities
          
            circle = entities.add_circle([0,0,0], Z_AXIS, 2.mm, 24)
            cyl_base = entities.add_face(circle)
            cyl_base.pushpull -1000.mm
          
            entities.transform_entities(Geom;;Transformation.rotation([0,0,0],[1,0,0],x.degrees),group)
          #entities.transform_entities(Geom;;Transformation.rotation([0,0,0],[1,0,0],45.degrees),group)
            model.commit_operation
          end
          if( not file_loaded?("teste.rb") )
            add_separator_to_menu("Draw")
            draw_menu = UI.menu("Draw")
            teste_menu = draw_menu.add_item("teste") { teste }
          end
          file_loaded("teste.rb")
          
          

          Thank you,
          Ricardo

          1 Reply Last reply Reply Quote 0
          • Didier BurD Offline
            Didier Bur
            last edited by

            Hi,

            Writing

            incl, factor = results
            

            does the same as that:

            incl = results[0]
            factor = results[1]

            so you can use "results" as an array and incl and factor as strings

            Hope this helps,

            DB

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

              Didier is correct, incl and factor are no longer arrays.

              Hi

              1 Reply Last reply Reply Quote 0
              • R Offline
                Ricardo
                last edited by

                Jim and Didier,

                Thanks for the help.

                BR,
                Ricardo

                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