Is there a way to change the color of a curve object in 3D view? (change the black lines only for this object to green).
I've got over 1000 curves generated by a python script and would like to change their color depending on length.
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityMy suggestion would be to:
Increase the bevel Depth value of the curve on the curve properties to give thickness to the curve
Make sure the Fill type for the curve is set to Full instead of half. So that the curve is a cylinder instead of a half cylinder. (Increase bevel Resolution for a smoother curve profile)
Assign separate materials with different colours to each curve. The curve now has a thickness so that materials can be displayed.
You should be able to incorporate the steps above into your script:
Something like the image below can be achieved:
Of course, a disadvantage may be that this only works for Object Mode and not Edit Mode.
Update: This answer is now obsolete based on OP's comments below.
Go to File >User Preferences >Themes and click on the 'Wire' swatch. You can change this to any color. If you want to change the color in Edit Mode then use the 'Wire Edit' swatch.
Note: Both of these also change the color of objects in Wireframe Mode.
If your curves are just for visualization, you could draw them using bgl.
import math
import bpy
from bpy_extras.view3d_utils import location_3d_to_region_2d
from bgl import glEnable, glDisable, glBegin, glEnd, glVertex2f, glColor4f, \
glLineWidth, GL_LINE_STRIP, GL_LINE_STIPPLE, GL_BLEND
class ExampleLines(bpy.types.Operator):
bl_idname = "view3d.bgl_example"
bl_label = "Example drawing lines in 3D View"
def invoke(self, context, event):
area = context.area
if context.area.type == "VIEW_3D":
region = context.region
self._handle = region.callback_add(self.draw_callback, (context,), "POST_PIXEL")
area.tag_redraw()
return {"FINISHED"}
return {"CANCELLED"}
def draw_callback(self, context):
region = context.region
region_data = context.region_data
current_frame = context.scene.frame_current
glEnable(GL_BLEND)
glLineWidth(2)
glColor4f(1, 0, 0, 0.5)
glBegin(GL_LINE_STRIP)
for i in range(current_frame):
glVertex2f(*location_3d_to_region_2d(region, region_data, (math.sin(i / 10), 0, i / 10)).to_tuple())
glEnd()
glColor4f(0, 1, 0, 0.5)
glBegin(GL_LINE_STRIP)
for i in range(current_frame):
glVertex2f(*location_3d_to_region_2d(region, region_data, (0, -1 + math.cos(i / 10), i / 10)).to_tuple())
glEnd()
glColor4f(0, 0, 1, 0.5)
glBegin(GL_LINE_STRIP)
for i in range(current_frame):
glVertex2f(*location_3d_to_region_2d(region, region_data, (0, math.sqrt(i / 10), i / 10)).to_tuple())
glEnd()
glDisable(GL_BLEND)
# restore opengl defaults
glColor4f(0.0, 0.0, 0.0, 1.0)
glLineWidth(1)
glDisable(GL_LINE_STIPPLE)
bpy.utils.register_class(ExampleLines)
In addition to Ray Mairlot's answer of making materials with different colors, you can use the viewport drawing color settings: (Still requires materials, and still requires a bevel on the curve to be seen)
Blender Internal:
Create a material and enable Object Color:
Now you can change the color in Object panel > Display > Object color
Cycles:
Create a Materiel and adjust the Viewport color:
An advantage to this is it works for Cycles and without changing the rendered view. (Object Color does effect the render in BI though)
In Blender 2.8 you can go Edit > Preferences > Themes > 3D Viewport > Wire Edit and change the color there.