Merge branch 'cb/fixs'
[plumiferos.git] / release / scripts / renameobjectbyblock.py
blob403aa32717e6c369a7301cf62c4596d700850377
1 #!BPY
3 """ Registration info for Blender menus: <- these words are ignored
4 Name: 'Object Name Editor'
5 Blender: 232
6 Group: 'Object'
7 Tip: 'GUI to select and rename objects.'
8 """
10 __author__ = "Jean-Michel Soler (jms)"
11 __url__ = ("blender", "elysiun",
12 "Script's homepage, http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_renameobjectgui.htm",
13 "Communicate problems and errors, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender")
14 __version__ = "233"
16 __bpydoc__ = """\
17 This script offers a GUI to rename selected objects according to a given
18 rule.
20 Usage:
22 Open it from the 3d View's "Object->Scripts" menu and select the objects to
23 rename and the rule from the buttons in its GUI.
24 """
26 # ----------------------------------------------------------
27 # Name OBJECT changer
28 # (c) 2004 jean-michel soler
29 # -----------------------------------------------------------
30 #----------------------------------------------
31 # Page officielle/offcial page du blender python Name OBJECT changer:
32 # http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_renameobjectgui.htm
33 # Communiquer les problemes et erreurs sur:
34 # To Communicate problems and errors on:
35 # http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
36 #---------------------------------------------
37 # Blender Artistic License
38 # http://download.blender.org/documentation/html/x21254.html
39 #---------------------------------------------
41 CVS=0
43 import Blender
44 from Blender import *
45 from Blender.Draw import *
46 from Blender.BGL import *
50 O = list(Scene.GetCurrent().objects)
51 stringlist=[[],[]]
54 def renew():
55 global O
57 #O = Object.Get()
58 O = list(Scene.GetCurrent().objects)
59 #param= [ [p.name, i, p.getType()] for i, p in enumerate(O) ]
61 PARAM={}
62 evt=9
63 stringlist=[[],[],[]]
64 for i, ob in enumerate(O):
65 obname= ob.name
66 PARAM[obname] = [Create(ob.sel), evt, i, ob.getType(), Create(obname), evt+1, ob]
68 stringlist[0].append(evt+1)
69 stringlist[1].append(obname)
70 stringlist[2].append(evt)
71 evt+=2
72 return PARAM,stringlist
74 NEWNAME=Create('Name')
76 alignment={'BEGIN' : [Create(1),5],
77 'END' : [Create(0),6],
78 'POINT' : [Create(0),7],
79 'FULL' : [Create(0),8]}
81 def rename():
82 global NEWNAME, alignment, O, PARAM, stringlist
83 newname= NEWNAME.val
84 for obname, value in PARAM.iteritems():
85 if value[0].val: # Selected
86 if alignment['END'][0].val:
87 value[6].setName(obname+newname)
88 elif alignment['BEGIN'][0].val:
89 value[6].setName(newname+obname)
90 elif alignment['FULL'][0].val:
91 value[6].setName(newname)
92 PARAM, stringlist = renew()
94 PARAM, stringlist = renew()
96 def EVENT(evt,val):
97 pass
99 def BUTTON(evt):
100 global PARAM , alignment, O, stringlist, CVS
101 if (evt==1):
102 Exit()
103 elif (evt==2):
104 rename()
105 elif (evt==3):
106 PARAM, stringlist = renew()
108 elif (evt in [5,6,7,8]):
109 for k in alignment.iterkeys():
110 if alignment[k][1]!=evt:
111 alignment[k][0].val=0
114 elif (evt in stringlist[0]):
115 O[PARAM[stringlist[1][(evt-9)/2]][2]].setName(PARAM[stringlist[1][(evt-9)/2]][4].val)
116 PARAM, stringlist = renew()
118 elif (evt in stringlist[2]):
119 try:
120 O[PARAM[stringlist[1][(evt-9)/2]][2]].select(PARAM[stringlist[1][(evt-9)/2]][0].val)
121 except:
122 pass
124 Blender.Redraw()
126 def DRAW():
127 global PARAM, O, NEWNAME, alignment
130 #glColor3f(0.7, 0.7, 0.7)
131 glClear(GL_COLOR_BUFFER_BIT)
132 glColor3f(0.1, 0.1, 0.15)
134 size=Buffer(GL_FLOAT, 4)
135 glGetFloatv(GL_SCISSOR_BOX, size)
136 size= size.list
137 for s in [0,1,2,3]: size[s]=int(size[s])
138 ligne=20
140 Button ("Exit",1,20,1,80,ligne)
141 Button ("Rename",2,102,1,80,ligne)
142 Button ("Renew",3,184,1,80,ligne)
144 glRasterPos2f(20, ligne*2-10)
145 Text("Object Name Editor")
146 NEWNAME=String('Add String: ', 4, 150, ligne*2-16, 150, 18, NEWNAME.val,120 )
148 key= alignment.keys()
149 key.sort()
150 n=150+150+4
151 for k in key:
152 alignment[k][0]= Toggle(k,alignment[k][1],n,ligne*2-16, 40, 18, alignment[k][0].val)
153 n+=40+4
155 max=size[3] / 22 -2
156 pos = 0
157 decal = 20
159 keys=[[PARAM[k][1],k] for k in PARAM.iterkeys()]
160 keys.sort()
163 for p_ in keys:
164 p=p_[1]
165 if pos==max:
166 decal+=152
167 pos=1
168 else:
169 pos+=1
170 PARAM[p][0]=Toggle('S',PARAM[p][1],decal,pos*22+22,20,20, PARAM[p][0].val,"Select this one for a group renaming")
171 PARAM[p][4]=String('',PARAM[p][5],decal+20,pos*22+22,90,20, PARAM[p][4].val,200, "string button to rename immediately but only this object")
173 glRasterPos2f(decal+115,pos*22+24)
174 Text(PARAM[p][3][:4])
176 if __name__=='__main__':
177 Register(DRAW,EVENT,BUTTON)