Welcome to mirror list, hosted at ThFree Co, Russian Federation.

useless_tools.py « space_view3d_display_tools - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 512fcf2da19869428b85e0eb78287f1d59990f6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# ##### 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": "Useless Tools",
    "description": "Just a little collection of scripts and tools I use daily",
    "author": "Greg Zaal",
    "version": (1, 2, 2),
    "blender": (2, 75, 0),
    "location": "3D View > Tools",
    "warning": "",
    "wiki_url": "",
    "category": "Tools"}


import bpy
from bpy.types import Operator
from bpy.props import BoolProperty


def error_handlers(self, op_name, errors, reports="ERROR"):
    if self and reports:
        self.report({'INFO'},
                    reports + ": some operations could not be performed "
                    "(See Console for more info)")

    str_errors = "\n".join(errors)
    print("\n[Display Tools]\nOperator: {}\nErrors: {}\n".format(op_name, str_errors))


class UTSetSelectable(Operator):
    bl_idname = "ut.set_selectable"
    bl_label = "Set Selectable"
    bl_description = "Sets selectability for the selected objects"

    selectable = BoolProperty()

    def execute(self, context):
        errors = []
        for obj in bpy.context.selected_objects:
            try:
                if self.selectable is True:
                    obj.hide_select = False
                else:
                    obj.hide_select = True
            except Exception as k:
                name = getattr(obj, "name", "Nameless")
                errors.append("Error on {} - {}".format(name, k))
        if errors:
            error_handlers(self, "ut.set_selectable", errors, "Set Selectable")

        return {'FINISHED'}


class UTSetRenderable(Operator):
    bl_idname = "ut.set_renderable"
    bl_label = "Set Renderable"
    bl_description = "Sets renderability for the selected objects"

    renderable = BoolProperty()

    def execute(self, context):
        errors = []
        for obj in bpy.context.selected_objects:
            try:
                if self.renderable is True:
                    obj.hide_render = False
                else:
                    obj.hide_render = True
            except Exception as k:
                name = getattr(obj, "name", "Nameless")
                errors.append("Error on {} - {}".format(name, k))
        if errors:
            error_handlers(self, "ut.set_renderable", errors, "Set Renderable")

        return {'FINISHED'}


class UTAllSelectable(Operator):
    bl_idname = "ut.all_selectable"
    bl_label = "All Selectable"
    bl_description = "Allows all objects to be selected"

    def execute(self, context):
        errors = []
        for obj in bpy.data.objects:
            try:
                obj.hide_select = False
            except Exception as k:
                name = getattr(obj, "name", "Nameless")
                errors.append("Error on {} - {}".format(name, k))
        if errors:
            error_handlers(self, "ut.all_selectable", errors, "All Selectable")

        return {'FINISHED'}


class UTAllRenderable(Operator):
    bl_idname = "ut.all_renderable"
    bl_label = "All Renderable"
    bl_description = "Allow all objects to be rendered"

    def execute(self, context):
        errors = []
        for obj in bpy.data.objects:
            try:
                obj.hide_render = False
            except Exception as k:
                name = getattr(obj, "name", "Nameless")
                errors.append("Error on {} - {}".format(name, k))
        if errors:
            error_handlers(self, "ut.all_renderable", errors, "All Renderable")

        return {'FINISHED'}


class UTSelNGon(Operator):
    bl_idname = "ut.select_ngons"
    bl_label = "Select NGons"
    bl_description = "Select faces with more than 4 vertices"

    @classmethod
    def poll(cls, context):
        if not context.active_object or context.mode != 'EDIT_MESH':
            return False
        return True

    def execute(self, context):
        errors = []
        try:
            context.tool_settings.mesh_select_mode = (False, False, True)
            bpy.ops.mesh.select_face_by_sides(number=4, type='GREATER', extend=True)
        except Exception as k:
            errors.append("Error - {}".format(k))
        if errors:
            error_handlers(self, "ut.select_ngons", errors, "Select NGons")

        return {'FINISHED'}


class UTWireShowHideSelAll(Operator):
    bl_idname = "ut.wire_show_hide"
    bl_label = "Show / Hide Wire Selected or All"
    bl_description = "Change the status of the Wire display on Selected Objects"

    show = BoolProperty(
            default=False
            )
    selected = BoolProperty(
            default=False
            )

    @classmethod
    def poll(cls, context):
        return not context.scene.display_tools.WT_handler_enable

    def execute(self, context):
        errors = []
        objects = bpy.context.selected_objects if self.selected else bpy.data.objects
        for e in objects:
            try:
                e.show_wire = self.show
            except Exception as k:
                name = getattr(e, "name", "Nameless")
                errors.append("Error on {} - {}".format(name, k))
        if errors:
            error_handlers(self, "ut.wire_show_hide", errors,
                           "Show / Hide Wire Selected or All")

        return {'FINISHED'}


class UTSubsurfHideSelAll(Operator):
    bl_idname = "ut.subsurf_show_hide"
    bl_label = "Subsurf Show/Hide"
    bl_description = ("Sets the Subsurf modifier on objects:\n"
                      "Hide and Show operate on Selected Objects only\n"
                      "Hide All and Show All operate on All Objects in the data")

    show = BoolProperty(
            default=False
            )
    selected = BoolProperty(
            default=False
            )

    def execute(self, context):
        errors = []
        objects = bpy.context.selected_objects if self.selected else bpy.data.objects
        for e in objects:
            try:
                if e.type not in {"LAMP", "CAMERA", "EMPTY"}:
                    e.modifiers['Subsurf'].show_viewport = self.show
            except Exception as k:
                name = getattr(e, "name", "Nameless")
                errors.append(
                    "No subsurf on {} or it is not named Subsurf\nError: {}".format(name, k))
        if errors:
            error_handlers(self, "ut.subsurf_show_hide", errors, "Subsurf Show/Hide")

        return {'FINISHED'}


class UTOptimalDisplaySelAll(Operator):
    bl_idname = "ut.optimaldisplay"
    bl_label = "Optimal Display"
    bl_description = "Disables Optimal Display for all Subsurf modifiers on objects"

    on = BoolProperty(
            default=False
            )
    selected = BoolProperty(
            default=False
            )

    def execute(self, context):
        errors = []
        objects = bpy.context.selected_objects if self.selected else bpy.data.objects
        for e in objects:
            try:
                if e.type not in {"LAMP", "CAMERA", "EMPTY"}:
                    e.modifiers['Subsurf'].show_only_control_edges = self.on
            except Exception as k:
                name = getattr(e, "name", "Nameless")
                errors.append(
                    "No subsurf on {} or it is not named Subsurf\nError: {}".format(name, k))
        if errors:
            error_handlers(self, "ut.optimaldisplay", errors, "Optimal Display")

        return {'FINISHED'}


class UTAllEdges(Operator):
    bl_idname = "ut.all_edges"
    bl_label = "All Edges"
    bl_description = "Change the status of All Edges overlay on all objects"

    on = BoolProperty(
            default=False
            )

    def execute(self, context):
        errors = []
        for e in bpy.data.objects:
            try:
                e.show_all_edges = self.on
            except Exception as k:
                name = getattr(e, "name", "Nameless")
                errors.append(
                    "Enabling All Edges  on {} \nError: {}".format(name, k))
        if errors:
            error_handlers(self, "ut.all_edges", errors, "All Edges")

        return {'FINISHED'}


class UTDoubleSided(Operator):
    bl_idname = "ut.double_sided"
    bl_label = "Double Sided Normals"
    bl_description = "Disables Double Sided Normals for all objects"

    on = BoolProperty(
            default=False
            )

    def execute(self, context):
        errors = []
        for e in bpy.data.meshes:
            try:
                e.show_double_sided = self.on
            except Exception as k:
                name = getattr(e, "name", "Nameless")
                errors.append(
                    "Applying Double Sided Normals on {} \nError: {}".format(name, k))
        if errors:
            error_handlers(self, "ut.double_sided", errors, "Double Sided Normals")

        return {'FINISHED'}


# Register
def register():
    bpy.utils.register_module(__name__)


def unregister():
    bpy.utils.unregister_module(__name__)


if __name__ == "__main__":
    register()