Convert Array into Integer
-
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 arrayUI.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` -
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])
Ruby Arrays - RubyLearning
Learn about Ruby arrays - how to create them, iterate with each, parallel assignment, environment variables, and command-line arguments.
(rubylearning.com)
You should also check result to see if the user hit Cancel in the inputbox.
-
Hi, that has sorted it.
Thank you
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement