~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/batch_name_edit.py

Tags: upstream-2.40
ImportĀ upstreamĀ versionĀ 2.40

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
"""
25
25
 
26
26
 
27
 
# $Id: batch_name_edit.py,v 1.4 2004/12/01 04:49:04 ianwill Exp $
 
27
# $Id: batch_name_edit.py,v 1.5 2005/05/17 07:17:52 ianwill Exp $
28
28
#
29
29
# --------------------------------------------------------------------------
30
30
# Batch Name Edit by Campbell Barton (AKA Ideasman)
50
50
 
51
51
from Blender import *
52
52
 
53
 
def new():
54
 
        newname = Draw.PupStrInput('Name: ', '', 32)
55
 
        if newname == None: return
56
 
        for ob in Object.GetSelected():
57
 
                ob.name = newname
58
 
        
59
 
def replace():
60
 
        replace = Draw.PupStrInput('Replace: ', '', 32)
61
 
        if replace == None: return
62
 
                
63
 
        with = Draw.PupStrInput('With: ', '', 32)
64
 
        if with == None: return
65
 
        
66
 
        for ob in Object.GetSelected():
67
 
                
68
 
                if replace in ob.name:
69
 
                        chIdx = ob.name.index(replace)
70
 
                        
71
 
                        # Remove the offending word and replace it with - 'with'
72
 
                        ob.name = ob.name[ :chIdx] + with + ob.name[chIdx + len(replace):]
73
 
                        
74
 
 
75
 
def prefix():
76
 
        prefix = Draw.PupStrInput('prefix: ', '', 32)
77
 
        if prefix == None: return
78
 
        
79
 
        for ob in Object.GetSelected():
80
 
                ob.name = prefix + ob.name
81
 
 
82
 
 
83
 
def suffix():
84
 
        suffix = Draw.PupStrInput('Suffix: ', '', 32)
85
 
        if suffix == None: return
86
 
        
87
 
        for ob in Object.GetSelected():
88
 
                ob.name = ob.name + suffix
89
 
 
90
 
def truncate_start():
91
 
        truncate = Draw.PupIntInput('Truncate Start: ', 0, 0, 31)
92
 
        if truncate != None:
93
 
                for ob in Object.GetSelected():
94
 
                        ob.name = ob.name[truncate: ]
95
 
 
96
 
def truncate_end():
97
 
        truncate = Draw.PupIntInput('Truncate End: ', 0, 0, 31)
98
 
        if truncate == None: return
99
 
        
100
 
        for ob in Object.GetSelected():
101
 
                ob.name = ob.name[ :-truncate]
102
 
 
103
 
 
104
 
 
105
 
 
106
 
name = "Selected Object Names%t|New Name|Replace Text|Add Prefix|Add Suffix|Truncate Start|Truncate End"
107
 
result = Draw.PupMenu(name)
108
 
 
109
 
if result == -1:
110
 
        pass
111
 
elif result == 1:
112
 
        new()
113
 
elif result == 2:
114
 
        replace()
115
 
elif result == 3:
116
 
        prefix()
117
 
elif result == 4:
118
 
        suffix()
119
 
elif result == 5:
120
 
        truncate_start()
121
 
elif result == 6:
122
 
        truncate_end()
123
 
 
 
53
def main():
 
54
        def new():
 
55
                newname = Draw.PupStrInput('Name: ', '', 32)
 
56
                if newname == None: return
 
57
                Window.WaitCursor(1)
 
58
                for ob in Object.GetSelected():
 
59
                        ob.name = newname
 
60
                
 
61
        def replace():
 
62
                replace = Draw.PupStrInput('Replace: ', '', 32)
 
63
                if replace == None: return
 
64
                with = Draw.PupStrInput('With: ', '', 32)
 
65
                if with == None: return
 
66
                Window.WaitCursor(1)
 
67
                for ob in Object.GetSelected():
 
68
                        ob.name = ob.name.replace(replace, with)
 
69
                        
 
70
                        # Use pythons replace, its better.
 
71
                        '''
 
72
                        if replace in ob.name:
 
73
                                chIdx = ob.name.index(replace)
 
74
                                
 
75
                                # Remove the offending word and replace it with - 'with'
 
76
                                ob.name = ob.name[ :chIdx] + with + ob.name[chIdx + len(replace):]
 
77
                        '''
 
78
                        
 
79
        
 
80
        def prefix():
 
81
                prefix = Draw.PupStrInput('prefix: ', '', 32)
 
82
                
 
83
                if prefix == None: return
 
84
                Window.WaitCursor(1)
 
85
                for ob in Object.GetSelected():
 
86
                        ob.name = prefix + ob.name
 
87
        
 
88
        
 
89
        def suffix():
 
90
                suffix = Draw.PupStrInput('Suffix: ', '', 32)
 
91
                if suffix == None: return
 
92
                Window.WaitCursor(1)
 
93
                for ob in Object.GetSelected():
 
94
                        ob.name = ob.name + suffix
 
95
        
 
96
        def truncate_start():
 
97
                truncate = Draw.PupIntInput('Truncate Start: ', 0, 0, 31)
 
98
                if truncate != None:
 
99
                        Window.WaitCursor(1)
 
100
                        for ob in Object.GetSelected():
 
101
                                ob.name = ob.name[truncate: ]
 
102
        
 
103
        def truncate_end():
 
104
                truncate = Draw.PupIntInput('Truncate End: ', 0, 0, 31)
 
105
                if truncate == None: return
 
106
                Window.WaitCursor(1)
 
107
                for ob in Object.GetSelected():
 
108
                        ob.name = ob.name[ :-truncate]
 
109
        
 
110
        
 
111
        name = "Selected Object Names%t|New Name|Replace Text|Add Prefix|Add Suffix|Truncate Start|Truncate End"
 
112
        result = Draw.PupMenu(name)
 
113
        
 
114
        if result == -1:
 
115
                pass
 
116
        elif result == 1:
 
117
                new()
 
118
        elif result == 2:
 
119
                replace()
 
120
        elif result == 3:
 
121
                prefix()
 
122
        elif result == 4:
 
123
                suffix()
 
124
        elif result == 5:
 
125
                truncate_start()
 
126
        elif result == 6:
 
127
                truncate_end()
 
128
        
 
129
        Window.WaitCursor(0)
 
130
 
 
131
main()