[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20958] trunk/blender/release/scripts/ export_dxf.py: DXF-Exporter v1.35 - 2009.06.17 by migius

Remigiusz Fiedler migius at gmx.net
Wed Jun 17 16:06:55 CEST 2009


Revision: 20958
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20958
Author:   migius
Date:     2009-06-17 16:06:55 +0200 (Wed, 17 Jun 2009)

Log Message:
-----------
DXF-Exporter v1.35 - 2009.06.17 by migius
- added export Cameras (ortho and persp) to VPORTs, incl. clipping
- added export Cameras (ortho and persp) to  VIEWs, incl. clipping
- export multiple-instances of Mesh-Objects as BLOCK/INSERTs
- on start prints dxfLibrary version

Modified Paths:
--------------
    trunk/blender/release/scripts/export_dxf.py

Modified: trunk/blender/release/scripts/export_dxf.py
===================================================================
--- trunk/blender/release/scripts/export_dxf.py	2009-06-17 12:32:28 UTC (rev 20957)
+++ trunk/blender/release/scripts/export_dxf.py	2009-06-17 14:06:55 UTC (rev 20958)
@@ -1,13 +1,13 @@
 #!BPY
 
 """
- Name: 'Autodesk DXF (.dxf)'
+ Name: 'Autodesk DXF (.dxf/dwg)'
  Blender: 249
  Group: 'Export'
  Tooltip: 'Export geometry to DXF/DWG-r12 (Drawing eXchange Format).'
 """
 
-__version__ = "1.34 - 2009.06.08"
+__version__ = "1.35 - 2009.06.17"
 __author__  = "Remigiusz Fiedler (AKA migius)"
 __license__ = "GPL"
 __url__  = "http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_dxf"
@@ -31,19 +31,27 @@
 - HPGL output, usefull for correct scaled printing of 2d drawings
 		
 TODO:
-- export dupligroups and dupliverts as blocks (option for the user to decide) 
+- export dupligroups and dupliverts as blocks (as option) 
 - optimize POLYFACE routine: remove double-vertices
-- more stable support for X,Y-rotated curves(to POLYLINEs): fix blender negative-matrix.invert()
+- fix support for X,Y-rotated curves(to POLYLINEs): fix blender negative-matrix.invert()
 - support hierarchies: groups, instances, parented structures
 - support n/f-gons as POLYFACEs with invisible edges
 - mapping materials to DXF-styles
 - ProgressBar
+- export rotation of Camera to VIEW/VPORT
+- export parented Cameras to VIEW/VPORT
 - wip: write drawing extends for automatic view positioning in CAD
-- wip: correct text-objects in persp-projection
-- wip: translate Camera to VPORT/VIEW
+- wip: fix text-objects in persp-projection
 - wip: translate current 3D-View to *ACTIVE-VPORT
+- wip: export multiple-instances of Curve-Objects as BLOCK/INSERTs
+- wip: fix support Include-Duplis, cause not conform with INSERT-method
 
 History
+v1.35 - 2009.06.17 by migius
+- added export Cameras (ortho and persp) to VPORTs, incl. clipping
+- added export Cameras (ortho and persp) to  VIEWs, incl. clipping
+- export multiple-instances of Mesh-Objects as BLOCK/INSERTs
+- on start prints dxfLibrary version
 v1.34 - 2009.06.08 by migius
 - export Lamps and Cameras as POINTs
 - export passepartout for perspective projection
@@ -55,7 +63,7 @@
 - support XYmirrored 2d-curves to 2dPOLYLINEs
 - support thickness and elevation for curve-objects
 - fix extrusion 210-code (3d orientation vector)
-- fix POLYFACE export, synchronized with dxfLibrary.py
+- fix POLYFACE export, synchronized also dxfLibrary.py
 - changed to the new 2.49 method Vector.cross()
 - output style manager (first try)
 v1.33 - 2009.05.25 by migius
@@ -139,10 +147,16 @@
 import os
 import subprocess
 
-import dxfLibrary as DXF
-#reload(DXF)
-#reload(dxfLibrary)
-#from dxfLibrary import *
+try:
+	import dxfLibrary as DXF
+	#reload(DXF)
+	#reload(dxfLibrary)
+	#from dxfLibrary import *
+except:
+	DXF=None
+	print "DXF-Exporter: error! found no dxfLibrary.py module in Blender script folder"
+	Draw.PupMenu("Error%t|found no dxfLibrary.py module in script folder")
+	
 
 import math
 from math import atan, atan2, log10, sin, cos
@@ -152,9 +166,8 @@
 r2d = 180.0 / math.pi
 d2r = math.pi / 180.0
 #note: d2r * angle == math.radians(angle)
+#note: r2d * angle == math.degrees(angle)
 
-print '\n\n\n'
-print 'DXF-Exporter v%s *** start ***' %(__version__)   #---------------------
 
 #DEBUG = True #activates debug mode
 
@@ -187,6 +200,7 @@
 ENTITYLAYER_DEF = LAYERNAME_DEF #default entity color index
 ENTITYCOLOR_DEF = BYLAYER #default entity color index
 ENTITYLTYPE_DEF = BYLAYER #default entity lineType
+
 E_M = 0
 LAB = "scroll MMB/WHEEL           . wip   .. todo" #"*) parts under construction"
 M_OBJ = 0
@@ -198,6 +212,7 @@
 INIFILE_HEADER = '#ExportDXF.py ver.1.0 config data'
 INFFILE_HEADER = '#ExportDXF.py ver.1.0 analyze of DXF-data'
 
+BLOCKREGISTRY = {} # registry and map for BLOCKs
 SCENE = None
 WORLDX = Mathutils.Vector((1,0,0))
 WORLDY = Mathutils.Vector((0,1,0))
@@ -496,92 +511,136 @@
 def	exportMesh(ob, mx, mx_n, me=None, **common):
 	"""converts Mesh-Object to desired projection and representation(DXF-Entity type)
 	"""
+	global BLOCKREGISTRY
 	entities = []
-	#print 'deb:exportMesh() common=', common #---------
-	if me==None:
+	block = None
+	#print 'deb:exportMesh() given common=', common #---------
+	if 1: #temp off, debug only! #me==None:
 		me = ob.getData(mesh=1)
 	else:
 		me.getFromObject(ob)
-	# me.transform(mx); get verts data; me.transform(mx_inv)= back to the origin state
-	# above .transform method is faster, but bad, cause invasive:
+	# idea: me.transform(mx); get verts data; me.transform(mx_inv)= back to the origin state
+	# the .transform-method is fast, but bad, cause invasive:
 	# it manipulates original geometry and by retransformation lefts back rounding-errors
 	# we dont want to manipulate original data!
 	#temp_verts = me.verts[:] #doesn't work on ubuntu(Yorik), bug?
 	if me.verts:
 		#print 'deb:exportMesh() started' #---------
-		allpoints = [v.co for v in me.verts]
-		allpoints = projected_co(allpoints, mx)
-		allpoints = toNewOrigin(allpoints)
-		faces=[]
-		edges=[]
-		if me.faces and PROJECTION and HIDDEN_LINES:
-			#if DEBUG: print 'deb:exportMesh HIDDEN_LINES mode' #---------
-			faces, edges = hidden_status(me.faces, mx, mx_n)
-			faces = [[v.index for v in me.faces[f_nr].verts] for f_nr in faces]
-		else:
-			#if DEBUG: print 'deb:exportMesh STANDARD mode' #---------
-			for e in me.edges: edges.append(e.key)
-			#faces = [f.index for f in me.faces]
-			faces = [[v.index for v in f.verts] for f in me.faces]
-			#faces = [[allpoints[v.index] for v in f.verts] for f in me.faces]
-		#print 'deb: allpoints=\n', allpoints #---------
-		#print 'deb: edges=\n', edges #---------
-		#print 'deb: faces=\n', faces #---------
-		if isLeftHand(mx): # then change vertex-order in every face
-			for f in faces:
-				f.reverse()
-				#f = [f[-1]] + f[:-1] #TODO: might be needed
-		#print 'deb: faces=\n', faces #---------
 
-		c = mesh_as_list[GUI_A['mesh_as'].val]
-		if 'POINTs'==c: # export Mesh as multiple POINTs
-			for p in allpoints:
-				dxfPOINT = DXF.Point(points=[p],**common)
-				entities.append(dxfPOINT)
-		elif 'LINEs'==c or (not faces):
-			if edges and allpoints:
-				if DEBUG: mesh_drawBlender(allpoints, edges, None) #deb: draw to blender scene
-				for e in edges:
-					points = [allpoints[e[0]], allpoints[e[1]]]
-					dxfLINE = DXF.Line(points, **common)
-					entities.append(dxfLINE)
-		elif faces:
-			if c in ('POLYFACE','POLYLINE'):
-				if allpoints:
-					#TODO: purge allpoints: left only vertices used by faces
-					if DEBUG: mesh_drawBlender(allpoints, None, faces) #deb: draw to scene
-					if not (PROJECTION and HIDDEN_LINES):
-						faces = [[v+1 for v in f] for f in faces]
-					else:
-						# for back-Faces-mode remove face-free verts
-						map=verts_state= [0]*len(allpoints)
-						for f in faces:
-							for v in f:
-								verts_state[v]=1
-						if 0 in verts_state: # if dirty state
-							i,newverts=0,[]
-							for used_i,used in enumerate(verts_state):
-								if used:
-									newverts.append(allpoints[used_i])	
-									map[used_i]=i
-									i+=1
-							allpoints = newverts
-							faces = [[map[v]+1 for v in f] for f in faces]
-					dxfPOLYFACE = DXF.PolyLine([allpoints, faces], flag=64, **common)
-					#print '\n deb: dxfPOLYFACE=',dxfPOLYFACE #-------------
-					entities.append(dxfPOLYFACE)
-			elif '3DFACEs'==c:
+		#print 'deb:exportMesh() ob.name=', ob.name #---------
+		#print 'deb:exportMesh() me.name=', me.name #---------
+		#print 'deb:exportMesh() me.users=', me.users #---------
+		# check if there are more instances of this mesh (if used by other objects), then write to BLOCK/INSERT
+		if me.users>1 and not PROJECTION:
+			if me.name in BLOCKREGISTRY.keys():
+				insert_name = BLOCKREGISTRY[me.name]
+				# write INSERT to entities
+				entities = exportInsert(ob, mx,insert_name, **common)
+			else:
+				# generate geom_output in ObjectCS
+				allpoints = [v.co for v in me.verts]
+				identity_matrix = Mathutils.Matrix().identity()
+				allpoints = projected_co(allpoints, identity_matrix)
+				#allpoints = toGlobalOrigin(allpoints)
+				faces=[]
+				edges=[]
+				for e in me.edges: edges.append(e.key)
+				faces = [[v.index for v in f.verts] for f in me.faces]
+				entities = writeMeshEntities(allpoints, edges, faces, **common)
+				if entities: # if not empty block
+					# write BLOCK definition and INSERT entity
+					# BLOCKREGISTRY = dictionary 'blender_name':'dxf_name'.append(me.name)
+					BLOCKREGISTRY[me.name]=validDXFr12name(('ME_'+ me.name))
+					insert_name = BLOCKREGISTRY[me.name]
+					block = DXF.Block(insert_name,flag=0,base=(0,0,0),entities=entities)
+					# write INSERT as entity
+					entities = exportInsert(ob, mx, insert_name, **common)
+
+		else: # no other instances, so go the standard way
+			allpoints = [v.co for v in me.verts]
+			allpoints = projected_co(allpoints, mx)
+			allpoints = toGlobalOrigin(allpoints)
+			faces=[]
+			edges=[]
+			if me.faces and PROJECTION and HIDDEN_LINES:
+				#if DEBUG: print 'deb:exportMesh HIDDEN_LINES mode' #---------
+				faces, edges = hidden_status(me.faces, mx, mx_n)
+				faces = [[v.index for v in me.faces[f_nr].verts] for f_nr in faces]
+			else:
+				#if DEBUG: print 'deb:exportMesh STANDARD mode' #---------
+				for e in me.edges: edges.append(e.key)
+				#faces = [f.index for f in me.faces]
+				faces = [[v.index for v in f.verts] for f in me.faces]
+				#faces = [[allpoints[v.index] for v in f.verts] for f in me.faces]
+			#print 'deb: allpoints=\n', allpoints #---------
+			#print 'deb: edges=\n', edges #---------
+			#print 'deb: faces=\n', faces #---------
+			if isLeftHand(mx): # then change vertex-order in every face
+				for f in faces:
+					f.reverse()
+					#f = [f[-1]] + f[:-1] #TODO: might be needed
+				#print 'deb: faces=\n', faces #---------
+			entities = writeMeshEntities(allpoints, edges, faces, **common)
+
+	return entities, block
+	
+
+#-------------------------------------------------
+def writeMeshEntities(allpoints, edges, faces, **common):
+	"""help routine for exportMesh()
+	"""
+	entities = []
+	
+	c = mesh_as_list[GUI_A['mesh_as'].val]
+	if 'POINTs'==c: # export Mesh as multiple POINTs
+		for p in allpoints:
+			dxfPOINT = DXF.Point(points=[p],**common)
+			entities.append(dxfPOINT)
+	elif 'LINEs'==c or (not faces):
+		if edges and allpoints:

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list