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

obdatacopier.py « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2f5617951de78c5dd1b1359cd67487e302f9bfd5 (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
#!BPY

""" Registration info for Blender menus: <- these words are ignored
Name: 'Data Copier'
Blender: 232
Group: 'Object'
Tip: 'Copy data from active object to other selected ones.'
"""

__author__ = "Jean-Michel Soler (jms), Campbell Barton (Ideasman42)"
__url__ = ("blender", "blenderartists.org",
"Script's homepage, http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_lampdatacopier.htm",
"Communicate problems and errors, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender")
__version__ = "0.1.2"

__bpydoc__ = """\
Use "Data Copier" to copy attributes from the active object to other selected ones of
its same type.

This script is still in an early version but is already useful for copying
attributes for some types of objects like lamps and cameras.

Usage:

Select the objects that will be updated, select the object whose data will
be copied (they must all be of the same type, of course), then run this script.
Toggle the buttons representing the attributes to be copied and press "Copy".
"""

# ----------------------------------------------------------
# Object DATA copier 0.1.2
# (c) 2004 jean-michel soler
# -----------------------------------------------------------
#----------------------------------------------
# Page officielle/official page du blender python Object DATA copier:
#   http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_lampdatacopier.htm
# Communiquer les problemes et erreurs sur:
# To Communicate problems and errors on:
#   http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
#---------------------------------------------
# Blender Artistic License
# http://download.blender.org/documentation/html/x21254.html
#---------------------------------------------

import Blender
from Blender import *
from Blender.Draw import *
from Blender.BGL import *


scn= Blender.Scene.GetCurrent()

type_func_method= type(dir)
type_func= type(lambda:i)
type_dict= type({})
# type_list= type([])

IGNORE_VARS = 'users', 'fakeUser', 'edges', 'faces', 'verts',  'elements'

def renew():
	scn= Blender.Scene.GetCurrent()
	act_ob= scn.objects.active
	if act_ob==None:
		return {}

	act_ob_type= act_ob.getType()
	act_ob_data= act_ob.getData(mesh=1)

	if act_ob_data==None: # Surf?
		return {}
	
	PARAM={}
	evt=4
	doc='doc' 
	
	for prop_name in dir(act_ob_data):
		if not prop_name.startswith('__') and prop_name not in IGNORE_VARS:
			# Get the type
			try:		exec 'prop_type= type(act_ob_data.%s)' % prop_name
			except:		prop_type= None
			
			if prop_type != None and prop_type not in (type_func_method, type_func, type_dict):
				
				# Now we know that the attribute can be listed in the UI Create a button and tooltip.
				
				# Tooltip
				try:
					if prop_name=='mode':
						try:
							exec "doc=str(%s.Modes)+' ; value : %s'"%( act_ob_type, str(act_ob_data.mode) )
						except:
							exec """doc= '%s'+' value = '+ str(act_ob.getData(mesh=1).%s)"""%(prop_name, prop_name) 
					elif prop_name=='type':
						try:
							exec "doc=str(%s.Types)+' ; value : %s'"%( act_ob_type, str(act_ob_data.type) )
						except:
							exec """doc= '%s'+' value = '+ str(act_ob.getData(mesh=1).%s)"""%(prop_name, prop_name) 
					else:
						exec """doc= '%s'+' value = '+ str(act_ob_data.%s)"""%(prop_name, prop_name)
						if doc.find('built-in')!=-1:
							exec """doc= 'This is a function ! Doc = '+ str(act_ob_data.%s.__doc__)"""% prop_name
				except:    
					 doc='Doc...' 
				
				# Button
				PARAM[prop_name]= [Create(0), evt, doc]
				evt+=1

	return PARAM

def copy():
	global PARAM
	
	scn= Blender.Scene.GetCurrent()
	act_ob= scn.getActiveObject()
	if act_ob==None:
		Blender.Draw.PupMenu('Error|No Active Object.')
		return
	
	act_ob_type= act_ob.getType()
	
	if act_ob_type in ('Empty', 'Surf'):
		Blender.Draw.PupMenu('Error|Copying Empty or Surf object data isnt supported.')
		return   
	
	act_ob_data= act_ob.getData(mesh=1)
	
	print '\n\nStarting copy for object "%s"' % act_ob.name
	some_errors= False
	for ob in scn.objects.context:
		if ob != act_ob and ob.getType() == act_ob_type:
			ob_data= None
			for prop_name, value in PARAM.iteritems():
				if value[0].val==1:
					
					# Init the object data if we havnt alredy
					if ob_data==None:
						ob_data= ob.getData(mesh=1)
					
					try:
						exec "ob_data.%s = act_ob_data.%s"%(prop_name, prop_name) 
					except:
						some_errors= True
						print 'Cant copy property "%s" for type "%s"' % (prop_name, act_ob_type)
	if some_errors:
		Blender.Draw.PupMenu('Some attributes could not be copied, see console for details.')
	
PARAM= renew()

def EVENT(evt,val):
   pass

def BUTTON(evt):
	global PARAM   
	if (evt==1):
		Exit()

	if (evt==2):
		copy()
		Blender.Redraw()

	if (evt==3):
		PARAM= renew()
		Blender.Redraw()

def DRAW():
	global PARAM
	
	scn= Blender.Scene.GetCurrent()
	act_ob= scn.objects.active
	
	glColor3f(0.7, 0.7, 0.7)
	glClear(GL_COLOR_BUFFER_BIT)
	glColor3f(0.1, 0.1, 0.15)    

	size=Buffer(GL_FLOAT, 4)
	glGetFloatv(GL_SCISSOR_BOX, size)
	size= size.list
	for s in [0,1,2,3]: size[s]=int(size[s])
	ligne=20

	Button("Exit",1,20,4,80,ligne)
	Button("Copy",2,102,4,80,ligne)
	Button("Renew",3,184,4,80,ligne)

	glRasterPos2f(20, ligne*2-8)
	if act_ob:
		Text(act_ob.getType()+" DATA copier")
	else:
		Text("Please select an object")


	max=size[3] / 22 -2
	pos   = 0
	decal = 20
	key=PARAM.keys()
	key.sort()
	for p in key:
		if  pos==max:
			decal+=102
			pos=1
		else:
			pos+=1       
		
		PARAM[p][0]=Toggle(p,
			PARAM[p][1],
			decal,
			pos*22+22,
			100,
			20, 
			PARAM[p][0].val,
			str(PARAM[p][2]))

  
Register(DRAW,EVENT,BUTTON)