# Changing color programatically

**URL:** <https://forums.sketchup.com/t/changing-color-programatically/137440>\
**Category:** Ruby API\
**Created:** [September 28, 2020, 11:47pm UTC](https://forums.sketchup.com/t/changing-color-programatically/137440 "2020-09-28T23:47:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AhClem](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@AhClem](https://forums.sketchup.com/u/AhClem)\
**Post date:** [September 28, 2020, 11:47pm UTC](https://forums.sketchup.com/t/changing-color-programatically/137440/1 "2020-09-28T23:47:24Z")

</div>

I’m trying to calculate point locations by converting spherical coordinates to Cartesian coordinates by calculating the X,Y,Z coordinates and using add\_line to connect them. I would like to have different colors for the different lines as they are computed, but I can’t figure out if there is any methods to change the color of the lines (edges?) being drawn by add\_line.  
Is this possible and is there any sample code showing the correct technique to call a function or method (or whatever) to change the current drawing color from inside my Ruby code?  
Thanks

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [September 29, 2020, 6:59am UTC](https://forums.sketchup.com/t/changing-color-programatically/137440/2 "2020-09-29T06:59:37Z")

</div>

You create a material or use one that is ready in a library.  
SketchUp comes with quite a number of material libraries, one of which is “Colors-Named”.

```ruby
# Firstly, set the rendering options to edge color by material:
model = Sketchup.active_model
opts = model.rendering_options
opts["EdgeColorMode"]= 0

# If using scene pages then update the current scene's style:
if model.pages.size > 0
  page = model.pages.selected_page
  page.use_rendering_options= true
  page.style.update(2)
end

# Load a particular material into the model's materials collection:
matls = model.materials
matlpath = "Materials/Colors-Named/0019_Crimson.skm"
filepath = Sketchup.find_support_file(matlpath)
# The API's material load method raises an exception on failure:
begin
  matl = matls.load(filepath)
rescue RuntimeError = err
  matl = nil
end

# It's a good idea to check for failure which would be nil,
# which in Ruby evaluates falsely:
if matl && matl.valid?
  # Assign a material object as an entity's material property:
  edge.material= matl
end
```
