13
$\begingroup$

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.

$\endgroup$

5 Answers 5

7
$\begingroup$

My 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:

Several coloured curves

Of course, a disadvantage may be that this only works for Object Mode and not Edit Mode.

$\endgroup$
3
  • 1
    $\begingroup$ @Aldrik If you are going to make such changes to an answer that the answer is now using a different technique then I suggest you provide your own answer. I have rolled back to my original answer. $\endgroup$ Jul 27, 2013 at 14:09
  • $\begingroup$ I'm aware, but considered it a minor enhancement. ;) $\endgroup$
    – Aldrik
    Jul 27, 2013 at 15:10
  • $\begingroup$ As long as the patch that LeonCheung mentioned isn't implemented I'll use this and the answer from gandalf3. Thanks all together. $\endgroup$
    – Germar
    Jul 27, 2013 at 22:17
6
$\begingroup$

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.

enter image description here

$\endgroup$
7
  • $\begingroup$ This changes the color for all curves. But I want to change just a single curve or several curves in different colors $\endgroup$
    – Germar
    Jul 26, 2013 at 22:49
  • $\begingroup$ As far as I know, you can't apply a color (Material) to a curve object. $\endgroup$
    – SteveW
    Jul 26, 2013 at 23:25
  • $\begingroup$ @Germar If you want this purely for identification purposes, then you can display the name by going to the Properties panel >Object >Display and check the Name box. $\endgroup$
    – SteveW
    Jul 26, 2013 at 23:37
  • $\begingroup$ I've >1000 curves and would like to color them depending on its length during they get created by my python script. Thanks for your help. $\endgroup$
    – Germar
    Jul 27, 2013 at 2:46
  • 2
    $\begingroup$ I bet you are looking for things like this:[projects.blender.org/tracker/… or this: [blenderartists.org/forum/showthread.php?254243-Viewport-FX/… I miss it too. I remember there was a very very old addon that can make this happen (for 2.5x), but I have to admit it cannot be done currently, except some coding work by yourself or others. $\endgroup$ Jul 27, 2013 at 3:20
5
$\begingroup$

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)

Output curves generated by script.

$\endgroup$
1
  • $\begingroup$ Nice! But I rather want to keep them as objects so I can highlight and manipulate them. And the bevel_depth method doesn't slow down the viewport that bad as I assumed before. $\endgroup$
    – Germar
    Jul 28, 2013 at 1:32
2
$\begingroup$

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:

    enter image description here

    Now you can change the color in Object panel > Display > Object color

    enter image description here

  • Cycles:

    Create a Materiel and adjust the Viewport color:

    enter image description here

An advantage to this is it works for Cycles and without changing the rendered view. (Object Color does effect the render in BI though)

$\endgroup$
2
$\begingroup$

In Blender 2.8 you can go Edit > Preferences > Themes > 3D Viewport > Wire Edit and change the color there.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .