2
#----------------------------------------------
3
# (c) jm soler juillet 2004-juin 2005,
4
# released under Blender Artistic Licence
5
# for the Blender 2.34 Python Scripts Bundle.
6
#----------------------------------------------
8
# http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_import_ai_en.htm
9
# Communiquer les problemes et erreurs sur:
10
# http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
12
# 0.1.1 : 2004/08/03, bug in boudingbox reading when Value are negative
13
# 0.1.2 : 2005/06/12, gmove tranformation properties
14
# 0.1.3 : 2005/06/25, added a __name__ test to use the script alone
15
# 0.1.4 : 2005/06/25, closepath improvements
16
# 0.1.5 : 2005/06/25, ...
17
# 0.1.6 : 2005/06/26, warning for compacted file
18
compatibility increased up to AI 10.0 plain text
19
# 0.1.7 : 2005/06/25, two more closepath improvements
21
# 0.1.8 : 2006/07/03, two more closepath improvements
36
BLversion=Blender.Get('version')
56
if pathname.find(os.sep)!=-1:
57
k0=pathname.split(os.sep)
60
k0=pathname.split('\\')
62
k0=pathname.split('/')
64
directory=pathname.replace(k0[len(k0)-1],'')
66
return directory, Name
75
def filtreFICHIER(nom):
80
if len(t)>1 and t[0].find('EPSF')==-1:
83
name = "OK?%t| Not a valid file or an empty file ... " # if no %xN int is set, indices start from 1
84
result = Blender.Draw.PupMenu(name)
88
#===============================
90
#===============================
91
#===============================
93
#===============================
107
self.type = typBEZIER3D,
109
self.resolUV = [32,0]
112
self.Origine = [0.0,0.0]
113
self.beziers_knot = []
117
self.magic_number='3DG3'
118
self.type = objBEZIER
119
self.number_of_items = 0
120
self.ext1_ext2 = [0,0]
121
self.matrix = """0.0 0.0 1.0 0.0
131
BOUNDINGBOX={'rec':[],'coef':1.0}
133
#=====================================================================
134
#======== name of the curve in teh courbes dictionnary ===============
135
#=====================================================================
138
#=====================================================================
139
#====================== current Point ================================
140
#=====================================================================
141
CP=[0.0,0.0] #currentPoint
145
#=====================================================================
146
#====================== current transform ============================
147
#=====================================================================
149
def __init__(self,matrix=[1,0,01],x=0.0,y=0.0):
150
self.matrix=matrix[:]
154
global GSCALE, GTRANSLATE, GSTACK
155
#print GSCALE, GTRANSLATE, GSTACK
156
return str((float(l)+GTRANSLATE[a]+GSTACK[-1].xy[a])*GSCALE[a])
160
#=====================================================================
161
#===== to compare last position to the original move to displacement =
162
#===== needed for cyclic efinition =================================
163
#=====================================================================
164
def test_egalitedespositions(f1,f2):
165
if f1[0]==f2[0] and f1[1]==f2[1]:
171
def Open_GEOfile(dir,nom):
173
in_editmode = Blender.Window.EditMode()
174
if in_editmode: Blender.Window.EditMode(0)
175
Blender.Load(dir+nom+'OOO.obj', 1)
176
BO=Blender.Object.Get()
179
BO[-1].makeDisplayList()
180
Blender.Window.RedrawAll()
182
print "Not yet implemented"
184
def create_GEOtext(courbes):
185
global SCALE, B, BOUNDINGBOX
196
t.append(courbes.magic_number+'\n')
197
t.append(str(courbes.type)+'\n')
198
t.append(str(courbes.number_of_items)+'\n')
199
t.append(str(courbes.ext1_ext2[0])+' '+str(courbes.ext1_ext2[1])+'\n')
200
t.append(courbes.matrix+'\n')
202
for k in courbes.ITEM.keys():
203
if len(courbes.ITEM[k].beziers_knot)>1 :
204
t.append("%s\n"%courbes.ITEM[k].type)
205
t.append("%s %s \n"%(courbes.ITEM[k].pntsUV[0],courbes.ITEM[k].pntsUV[1]))
206
t.append("%s %s \n"%(courbes.ITEM[k].resolUV[0],courbes.ITEM[k].resolUV[1]))
207
t.append("%s %s \n"%(courbes.ITEM[k].orderUV[0],courbes.ITEM[k].orderUV[1]))
208
t.append("%s %s \n"%(courbes.ITEM[k].flagUV[0],courbes.ITEM[k].flagUV[1]))
210
flag =courbes.ITEM[k].flagUV[0]
212
for k2 in range(len(courbes.ITEM[k].beziers_knot)):
214
k1 =courbes.ITEM[k].beziers_knot[k2]
215
t.append("%4f 0.0 %4f \n"%(float(k1.co[2])/SCALE,float(k1.co[3])/SCALE))
216
t.append("%4f 0.0 %4f \n"%(float(k1.co[4])/SCALE,float(k1.co[5])/SCALE))
217
t.append("%4f 0.0 %4f \n"%(float(k1.co[0])/SCALE,float(k1.co[1])/SCALE))
219
t.append(str(k1.ha[0])+' '+str(k1.ha[1])+'\n')
222
def save_GEOfile(dir,nom,t):
223
f=open(dir+nom+'OOO.obj','w')
226
#warning = "REMINDER : %t | Do not forget to rename your blender file NOW ! %x1"
227
#result = Blender.Draw.PupMenu(warning)
230
#=====================================================================
231
#===== AI format : DEBUT =========================
232
#=====================================================================
233
def mouvement_vers(l,n0,CP):
234
if n0 in courbes.ITEM.keys():
237
CP=[l[-3].replace('d',''),l[-2]]
238
courbes.ITEM[n0]=ITEM()
239
courbes.ITEM[n0].Origine=[l[-3].replace('d',''),l[-2]]
242
B.co=[CP[0],CP[1],CP[0],CP[1],CP[0],CP[1]]
246
courbes.ITEM[n0].beziers_knot.append(B)
250
def courbe_vers_c(l,l2, n0,CP): #c,C
253
B.co=[l[4],l[5],l[2],l[3],l[4],l[5]]
257
BP=courbes.ITEM[n0].beziers_knot[-1]
262
courbes.ITEM[n0].beziers_knot.append(B)
268
def courbe_vers_v(l,n0,CP): #v-V
272
B.co=[l[2],l[3],l[0],l[1],l[2],l[3]]
275
courbes.ITEM[n0].beziers_knot.append(B)
280
def courbe_vers_y(l,n0,CP): #y
283
B.co=[l[2],l[3],l[2],l[3],l[2],l[3]]
286
BP=courbes.ITEM[n0].beziers_knot[-1]
290
courbes.ITEM[n0].beziers_knot.append(B)
295
def ligne_tracee_l(l,n0,CP):
298
B.co=[l[0],l[1],l[0],l[1],l[0],l[1]]
301
BP=courbes.ITEM[n0].beziers_knot[-1]
303
courbes.ITEM[n0].beziers_knot.append(B)
307
def ligne_fermee(l,n0,CP):
308
courbes.ITEM[n0].flagUV[0]=1
310
if len(courbes.ITEM[n0].beziers_knot)>1:
311
BP=courbes.ITEM[n0].beziers_knot[-1]
312
BP0=courbes.ITEM[n0].beziers_knot[0]
314
if BP.tag not in ['l','L']:
315
BP.co[0]=BP0.co[0] #4-5 point prec
318
del courbes.ITEM[n0].beziers_knot[0]
324
Actions= { "C" : courbe_vers_c,
330
"m" : mouvement_vers,
331
"l" : ligne_tracee_l,
332
"L" : ligne_tracee_l,
343
TAGcourbe=Actions.keys()
345
def pik_pattern(t,l):
346
global npat, PATTERN, BOUNDINGBOX, AI_VERSION
347
while t[l].find('%%EndSetup')!=0:
348
if t[l].find('%%Creator: Adobe Illustrator(R)')!=-1:
350
AI_VERSION=t[l].split()[-1]
353
if t[l].find('%%BoundingBox:')!=-1:
354
t[l]=t[l][t[l].find(':')+1:]
356
BOUNDINGBOX['rec']=[float(l0[-4]),float(l0[-3]),float(l0[-2]),float(l0[-1])]
358
BOUNDINGBOX['coef']=(r[3]-r[1])/(r[2]-r[0])
360
if t[l].find('BeginPattern')!=-1:
361
nomPattern=t[l][t[l].find('(')+1:t[l].find(')')]
362
PATTERN[nomPattern]={}
364
if t[l].find('BeginPatternLayer')!=-1:
366
PATTERN[nomPattern][npat]=[]
367
while t[l].find('EndPatternLayer')==-1:
369
PATTERN[nomPattern][npat].append(l)
378
global CP, courbes, SCALE, NOTHING_TODO
385
if nom.upper().find('.AI')!=-1 and t!='false':
387
warning = "Select Size : %t| As is %x1 | Scale on Height %x2| Scale on Width %x3"
388
SCALE = Blender.Draw.PupMenu(warning)
395
do,l=pik_pattern(t,l)
396
#print 'len(t)',len(t)
397
t[l].replace('\n','')
398
if t[l].find('%%EOF')==0:
403
if l0[0][0] in ['F','f','N','n','B','b']:
405
courbes,n0,CP=Actions[l3](l3,n0,CP)
408
if l0[-1] in TAGcourbe:
410
if l0[-1] in ['C','c']:
412
courbes,n0,CP=Actions[l0[-1]](l0,l2,n0,CP)
414
courbes,n0,CP=Actions[l0[-1]](l0,n0,CP)
419
courbes.number_of_items=len(courbes.ITEM.keys())
420
for k in courbes.ITEM.keys():
421
courbes.ITEM[k].pntsUV[0] =len(courbes.ITEM[k].beziers_knot)
424
if courbes.number_of_items>0:
425
if len(PATTERN.keys() )>0:
426
#print len(PATTERN.keys() )
427
warning = "Pattern list (for info not used): %t| "
429
for P in PATTERN.keys():
430
warning+="%s %%x%s|"%(P,p0)
432
Padd = Blender.Draw.PupMenu(warning)
434
t=create_GEOtext(courbes)
435
save_GEOfile(dir,name[0],t)
437
# 0.1.8 ---------------------------------
438
# [O.select(0) for O in Blender.Scene.getCurrent().getChildren()]
439
# 0.1.8 ---------------------------------
441
Open_GEOfile(dir,name[0])
443
# 0.1.8 ---------------------------------
444
Blender.Object.Get()[-1].setName(name[0])
445
# 0.1.8 ---------------------------------
449
#=====================================================================
450
#====================== AI format mouvements =========================
451
#=====================================================================
452
#=========================================================
453
# une sorte de contournement qui permet d'utiliser la fonction
454
# et de documenter les variables Window.FileSelector
455
#=========================================================
456
def fonctionSELECT(nom):
457
global NOTHING_TODO,AI_VERSION
460
warning = "AI %s compatible file "%AI_VERSION+" but nothing to do ? %t| Perhaps a compacted file ... "
461
NOTHING = Blender.Draw.PupMenu(warning)
463
if __name__=="__main__":
464
Blender.Window.FileSelector (fonctionSELECT, 'SELECT AI FILE')