sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Help!

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 220 Views 2 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.
    • B Offline
      Builder Boy
      last edited by

      I made this code in the Web Console

      
      model = Sketchup.active_model
      entities = model.active_entities
      selection = model.selection
      
      if selection.empty?
      
        UI.messagebox("No Selection")
      
      else
      
       prompts   = ["X", "Y", "Z"]
       defaults  = ["1.0", "1.0", "1.0"]
       list      = ["", "", ""]
       input     = UI.inputbox prompts, defaults, list, "Size"
      
        group = entities.add_group selection
      
       if (group)
        selection.add group
       else
        UI.messagebox "Failure"
       end
      
       Xsize = input[0].to_f
       Ysize = input[1].to_f
       Zsize = input[2].to_f
      
       e = selection[0]
       tr1 = e.transformation
       tr2 = Geom;;Transformation.scaling(Xsize, Ysize, Zsize)
      
       e.transform!(tr1.inverse)
       e.transform!(tr2)
       e.transform!(tr1)
      
       status = group.explode
      
      end
      
      

      But, every time I run the script, I get this message in the ruby console:

      
      warning; already initialized constant Xsize
      warning; already initialized constant Ysize
      warning; already initialized constant Zsize
      
      

      How do I fix this?

      All my plugins

      1 Reply Last reply Reply Quote 0
      • dereiD Offline
        derei
        last edited by

        @unknownuser said:

        
        >  Xsize = input[0].to_f
        >  Ysize = input[1].to_f
        >  Zsize = input[2].to_f
        > 
        

        But, every time I run the script, I get this message in the ruby console:

        
        > warning; already initialized constant Xsize
        > warning; already initialized constant Ysize
        > warning; already initialized constant Zsize
        > 
        

        How do I fix this?

        Well, for start, you could type in lowercase πŸ˜„ Because if your variable name starts with capital letter, ruby takes it as CONSTANT. You are lucky that ruby lets to redefine constants, most of programming languages don't allow πŸ˜„. This is why you get the warning.
        use something like this, it's easier to read and those are local variables, not constants:

        
        x_size = input[0].to_f
        y_size = input[1].to_f
        z_size = input[2].to_f
        
        

        DESIGNER AND ARTIST [DEREI.UK](http://derei.uk/l)

        1 Reply Last reply Reply Quote 0
        • B Offline
          Builder Boy
          last edited by

          @unknownuser said:

          Well, for start, you could type in lowercase πŸ˜„ Because if your variable name starts with capital letter, ruby takes it as CONSTANT. You are lucky that ruby lets to redefine constants, most of programming languages don't allow πŸ˜„. This is why you get the warning.
          use something like this, it's easier to read and those are local variables, not constants:

          
          > x_size = input[0].to_f
          > y_size = input[1].to_f
          > z_size = input[2].to_f
          > 
          

          Thanks! it works perfectly now!

          All my plugins

          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