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!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Convert Array into Integer

    Scheduled Pinned Locked Moved Plugins
    3 Posts 2 Posters 169 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.
    • R Offline
      rossthompson
      last edited by

      Hi,

      I am trying to use a simple bit of code that allows me to set the color alpha value in SketchUp 7.

      I use this version as its the last one with a free DWG importer.

      Anyway the problem is I can only get an array from 'UI.inputbox' and I need an integer to set the color.alpha value.

      Can anyone correct the code?

      Thanks

      Ross

      ` def translucent
      model = Sketchup.active_model
      materials = model.materials
      m=materials.add("translucent") unless m=materials["translucent"] # Adds a material to the "in-use" material pallet.

      title = 'Opacity'
      prompt = 'Opacity'
      default = 0.5
      result = UI.inputbox([prompt], [default], "text") # need to use array

      UI.messagebox(result)

      m.color = Sketchup::Color.new(100, 100, 100, result) # Specify the colour.opacity
      color = m.color
      alpha = m.alpha=0.5 # Set material transparency
      materials.current = materials["translucent"] # Set to the current material
      Sketchup.send_action "selectPaintTool:" # Start the paint tool
      end`

      1 Reply Last reply Reply Quote 0
      • tt_suT Offline
        tt_su
        last edited by

        You need to access the items inside the array. In your case you only have one item so it would be: result[0].

        m.color = Sketchup::Color.new(100, 100, 100, result[0])

        http://rubylearning.com/satishtalim/ruby_arrays.html

        You should also check result to see if the user hit Cancel in the inputbox.

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

          Hi, that has sorted it.

          Thank you

          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