[Bf-python] svg2obj script.

Campbell Barton cbarton at metavr.com
Thu Mar 29 06:28:24 CEST 2007


Heres the unflipped patch, I just made this from meld 
(http://meld.sourceforge.net)


--- /bs_/bpymodules/svg2obj.py
+++ /tmp/svg2obj_059-1.py
@@ -291,7 +291,7 @@
  	# ----------
  	# 0.4.7
  	# ----------
-	if '.SVGZ' in nom.upper(): #.find('.SVGZ')!=-1:
+	if nom.upper().endswith('.SVGZ'):
  		try :
  			import gzip
  			tz=gzip.GzipFile(nom)
@@ -424,7 +424,7 @@
  			del val.beziers_knot[-1]
  			#print 'remove last point', rmp
  			#rmp+=1
-		for k2 in range(0,len(val.beziers_knot)):
+		for k2 in xrange(0,len(val.beziers_knot)):
  			bz= [co for co in val.beziers_knot[k2].co]
  			if bzn==0:
  				cp1 =  bz[4],bz[5],0.0 , bz[0],bz[1],0.0, bz[2],bz[3],0.0,
@@ -487,15 +487,15 @@
  	except:
  		pxUNIT['%']=(BOUNDINGBOX['rec'][3]-BOUNDINGBOX['rec'][1])/100.0	
  		for key in pxUNIT:#.keys():
-			if key in prp['height']:
-				 height=float(prp['height'].replace(key,''))*pxUNIT[key]
+			if key in prp['height']:
+				height=float(prp['height'].replace(key,''))*pxUNIT[key]
  	try:
  		width=float(prp['width'])
  	except:
  		pxUNIT['%']=(BOUNDINGBOX['rec'][2]-BOUNDINGBOX['rec'][0])/100.0
  		for key in pxUNIT:#.keys():
  			if key in prp['width']:
-					width=float(prp['width'].replace(key,''))*pxUNIT[key]
+				width=float(prp['width'].replace(key,''))*pxUNIT[key]
  	#--------------------
  	# 0.5.8, end
  	#--------------------
@@ -671,7 +671,7 @@
  		ang_arc-=2.0*PI
  	n_segs=int(ceil(abs(ang_arc*2.0/(PI*0.5+0.001))))
  	P=[]
-	for i in range(n_segs):
+	for i in xrange(n_segs):
  		ang0=ang_0+i*ang_arc/n_segs
  		ang1=ang_0+(i+1)*ang_arc/n_segs
  		ang_demi=0.25*(ang1-ang0)
@@ -991,7 +991,7 @@
  			if i==-1: break
  			tagplace.append(i)
  			b1=i+1
-
+	
  	# ----------------------------------------
  	#     reset the list in the presentation order
  	#     of the  data
@@ -1014,7 +1014,7 @@
  		if DATA2[-1] not in ['z','Z'] and len(DATA)-1>=tagplace[t+1]+1:
  			ndata=DATA[tagplace[t+1]+1:]
  			ndata=wash_DATA(ndata)
-			for n in ndata : DATA2.append(n)
+			DATA2.extend(ndata)
  	else:
  		#--------------------	
  		# 0.3.5 : short data,only one tag
@@ -1104,7 +1104,7 @@
  		nt0=txt[t0:t1+1]
  		t2=nt0[nt0.find('(')+1:-1]
  		val=nt0[:nt0.find('(')]
-		while t2.find('  ')!=-1:
+		while '  ' in t2:
  			t2=t2.replace('  ',' ')
  		t2=t2.replace(' ',',')
  		t2=t2.split(',')
@@ -1162,14 +1162,13 @@
  				bez=bez0.co
  				for b in [0,2,4]:
  					for t in ST:
-						 v=Mathutils.Vector([bez[b],bez[b+1],1.0])
-						 v=t * v
+						 v = t * Mathutils.Vector([bez[b],bez[b+1],1.0])
  						 bez[b]=v[0]
  						 bez[b+1]=v[1]

  def filter(d):
  	for nn in d:
-		if '0123456789.'.find(nn)==-1:
+		if nn not in '0123456789.':
  			d=d.replace(nn,"")
  	return d

@@ -1226,8 +1225,8 @@

  	TRANSFORM=0
  	t=t.replace('\t',' ')
-	while t.find('  ')!=-1: t=t.replace('  ',' ')
-	n0=0
+	while '  ' in t: t=t.replace('  ',' ')
+	n0=0
  	t0=t1=0
  	baliste=[]
  	balisetype=['?','?','/','/','!','!']





More information about the Bf-python mailing list