Directly apply a material
-
Hi,
I am working on a script that activates the paint bucket tool with a predefined material of a certain colour and transparency. The code I have written works fine except on every use it creates a copy of the material eg. 'window1', 'window2' etc. which makes a bit of a mess of the materials palette.I think it just needs a simple if statement to avoid creating the material if it already exists. Does anyone know how to do this?
Thanks Ross
toolbar = UI;;Toolbar.new "Window" cmd = UI;;Command.new("Test") { window } cmd.small_icon = "CBG/window_sm.png" cmd.large_icon = "CBG/window.png" cmd.tooltip = "Paint Window" toolbar = toolbar.add_item cmd toolbar.show def window model = Sketchup.active_model materials = model.materials m = materials.add "Window" # Adds a material to the "in-use" material pallet. m.color = Sketchup;;Color.new(100, 150, 240) # Specify the colour color = m.color alpha = m.alpha=0.5 # Set transparency materials.current = materials["Window"] # Set to the current material Sketchup.send_action "selectPaintTool;" # Start the paint tool end -
Try something like this:
m=materials.add("Window") unless m=materials["Window"]
Which sets 'm' to be an existing material named 'Window', but if it fails [unlessor should you prefer it useif not]... then it sets it to a new material named 'Window' [add]... -
Hi, that worked perfectly
Thanks TIG
-
Can also be written like so:
m = materials['Door'] || materials.add('Door')
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