Set line color using ruby api

I’m new to sketchup ruby api. I can not seem to figure out how to set a line color. I can draw a line but it’s always black. I create a new layer. I set the layer color. I draw a line with a tool similar to linetool.rb but it always shows up as black. I’ve tried manually to set to a specific layer with color blue and use the pencil to draw a line. It too is always black.

If you go to window>styles>edit tab and click on the black square and change the color.
If you want to change individual lines . in the same tab next to color select drop down box and select by material. You can know paint individual lines with paint bucket.

Phl

It’s 3D modeling. They are really edges not lines.

You would need to set the Edge Style’s color to “By Material”. (Materials can be single color and/or textured.)

Then set a Layer’s material.

Open the context-menu for the Layer Inspector, and choose “Color By Layer”:

~

But your headed for problems if you do not leave primitives on Layer0.
Group them, (or make a Component,) and set the Group (or ComponentInstance) to a “color layer”.

Try as I might I still can’t get it in color. The line is drawn, just still black.

material = Sketchup.active_model.materials.add(‘Test’)
material.color = ‘blue’
suEntity = Sketchup.active_model.entities.add_line(pStart, pEnd)
suEntity.material = material

The default styles overrides the edge colors. The style needs to be set to display edges by color:

Which you can do also via:

Sketchup.active_model.rendering_options["EdgeColorMode"] = 0

If you intend to use this for a plugin, take care that this is a modification of the model (!) so it should only be done when the user intends it; it also adds to the undo stack so wrap all your plugin’s action into one single operation. Get a reference (variable) to the model only once at the begin of the action, because Sketchup.active_model points to what ever model is currently active and that could (in theory) change.

2 Likes

That last tip did the trick. Thanks.

I just wish there were more documentation on all the rendering options.

List of rendering options
Topic with an example