mod :
but does not work :
‘SpaceView3D’ object has no attribute ‘color_wire_solid’
I’m not sure you can setup a particular wire color to an object in 258
you can change globally in the theme :
bpy.context.user_preferences.themes[‘Default’].view_3d.wire.r = 1
but it doesn’t help here. I don’t find something about wire color for a particular object (and there’s nothing in the ui btw…)
it looks like one can use :
bpy.context.active_object.color[0] # 012 = rgb
as a replacement.
but the script would have to unwrap each mesh, add an object_color flag to each face, check if bpy.context.active_object.draw_type is solid / viewport shading solid…
# -*- coding: utf-8 -*-
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
'name': 'Color Wire',
'description': '',
'author': 'chromoly',
'version': (0, 158),
'blender': (2, 5, 8),
'api': 37702,
'location': 'View3D > Ctrl + Shift + D',
'warning': '',
'wiki_url': '',
'tracker_url': '',
'category': '3D View'}
import math
import bpy
from bpy.props import *
#import mathutils as Math
#from mathutils import Matrix, Vector, Quaternion
dtdict = {'BOUNDBOX':0, 'WIREFRAME':1, 'SOLID':2, 'TEXTURED':3}
class VIEW3D_OT_color_wire_toggle(bpy.types.Operator):
bl_idname = 'view3d.color_wire_toggle'
bl_label = 'Toggle Color Wire'
#bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
v3d = bpy.context.space_data
print(v3d)
dt = v3d.viewport_shade
if dtdict[dt] <= dtdict['WIREFRAME']:
v3d.color_wire ^= 1
else:
v3d.color_wire_solid ^= 1
return {'FINISHED'}
#def invoke(self, context, event):
# return {'FINISHED'}
class VIEW3D_OT_color_wire_copy_color(bpy.types.Operator):
bl_idname = 'view3d.color_wire_copy_color'
bl_label = 'Copy Wire Color'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.active_object != None
def execute(self, context):
if not (context.active_object and context.selected_objects):
return {'FINISHED'}
usewcol = context.active_object.color_wire
wcol = context.active_object.wire_color
for ob in context.selected_objects:
ob.color_wire = usewcol
for i in range(3):
ob.wire_color[i] = wcol[i]
return {'FINISHED'}
#def invoke(self, context, event):
# return {'FINISHED'}
class VIEW3D_OT_color_wire_select_same_color(bpy.types.Operator):
bl_idname = 'view3d.color_wire_select_same_color'
bl_label = 'select by Wire Color'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.active_object != None
def execute(self, context):
if not (context.active_object and context.selected_objects):
return {'FINISHED'}
usewcol = context.active_object.color_wire
wcol = context.active_object.wire_color
for ob in context.visible_objects:
if not ob.select:
for i in range(3):
if ob.wire_color[i] != wcol[i]:
break
else:
ob.select = True
return {'FINISHED'}
#def invoke(self, context, event):
# return {'FINISHED'}
class VIEW3D_MT_color_wire(bpy.types.Menu):
#bl_idname = 'view3d.color_wire_menu'
bl_label = 'Color Wire'
def draw(self, context):
v3d = context.space_data
cwstate = [v3d.color_wire, v3d.color_wire_solid]
ls = ['', '']
ls[0] = 'ON' if cwstate[0] else 'OFF'
ls[1] = 'ON' if cwstate[1] else 'OFF'
dt = v3d.viewport_shade
if dtdict[dt] <= dtdict['WIREFRAME']:
ls[0] = '[' + ls[0] + ']'
else:
ls[1] = '[' + ls[1] + ']'
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator('view3d.color_wire_toggle',
text='Toggle ({0}, {1})'.format(*ls))
layout.operator('view3d.color_wire_copy_color',
text='Copy wire color')
layout.operator('view3d.color_wire_select_same_color',
text='Select same color')
# Register
def register():
#km = bpy.context.window_manager.keyconfigs.active.keymaps["3D View"]
#kmi = km.items.new('wm.call_menu', 'D', 'PRESS', shift=True, ctrl=True)
#kmi.properties.name = 'VIEW3D_MT_color_wire'
bpy.utils.register_class(VIEW3D_MT_color_wire)
bpy.utils.register_class(VIEW3D_OT_color_wire_select_same_color)
bpy.utils.register_class(VIEW3D_OT_color_wire_copy_color)
bpy.utils.register_class(VIEW3D_OT_color_wire_toggle)
def unregister():
#km = bpy.context.window_manager.keyconfigs.active.keymaps["3D View"]
#for kmi in km.items:
# if kmi.idname == 'wm.call_menu':
# if kmi.properties.name == 'VIEW3D_MT_color_wire':
# km.items.remove(kmi)
bpy.utils.unregister_class(VIEW3D_MT_color_wire)
bpy.utils.unregister_class(VIEW3D_OT_color_wire_select_same_color)
bpy.utils.unregister_class(VIEW3D_OT_color_wire_copy_color)
bpy.utils.unregister_class(VIEW3D_OT_color_wire_toggle)
if __name__ == '__main__':
register()