[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20723] trunk/blender/release/scripts/ export_dxf.py: DXF-Exporter script update

Remigiusz Fiedler migius at gmx.net
Mon Jun 8 03:30:09 CEST 2009


Revision: 20723
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20723
Author:   migius
Date:     2009-06-08 03:29:58 +0200 (Mon, 08 Jun 2009)

Log Message:
-----------
DXF-Exporter script update
v1.34 - 2009.06.08
- export Lamps and Cameras as POINTs
- export passepartout for perspective projection
- added option for export objects only from visible layers

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-08 01:07:19 UTC (rev 20722)
+++ trunk/blender/release/scripts/export_dxf.py	2009-06-08 01:29:58 UTC (rev 20723)
@@ -7,7 +7,7 @@
  Tooltip: 'Export geometry to DXF/DWG-r12 (Drawing eXchange Format).'
 """
 
-__version__ = "1.34 - 2009.06.07"
+__version__ = "1.34 - 2009.06.08"
 __author__  = "Remigiusz Fiedler (AKA migius)"
 __license__ = "GPL"
 __url__  = "http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_dxf"
@@ -17,7 +17,7 @@
 Copyright %s
 License %s
 
-extern dependances: dxfLibrary.py, (optionaly: DConvertCon.exe)
+extern dependances: dxfLibrary.py, dxfColorMap.py (optionaly: DConvertCon.exe)
 
 CONTRIBUTORS:
 Remigiusz Fiedler (AKA migius)
@@ -28,21 +28,27 @@
 url: %s
 
 IDEAs:
-- HPGL output, especially usefull for correct scaled printing of 2d drawings
+- HPGL output, usefull for correct scaled printing of 2d drawings
 		
 TODO:
 - export dupligroups and dupliverts as blocks (option for the user to decide) 
 - optimize POLYFACE routine: remove double-vertices
-- optimize POLYFACE routine: remove loose vertices
-- stable support X,Y-rotated curves(to POLYLINEs): fix blender negative-matrix.invert()
+- more stable support for X,Y-rotated curves(to POLYLINEs): fix blender negative-matrix.invert()
 - support hierarchies: groups, instances, parented structures
-- write drawing extends for automatic view positioning in CAD
+- support n/f-gons as POLYFACEs with invisible edges
 - mapping materials to DXF-styles
-- wip: corrected text-objects in persp-projection
-- wip: fix filter out objects from inactive(off) layers
+- ProgressBar
+- wip: write drawing extends for automatic view positioning in CAD
+- wip: correct text-objects in persp-projection
+- wip: translate Camera to VPORT/VIEW
+- wip: translate current 3D-View to *ACTIVE-VPORT
 
 History
-v1.34 - 2009.06.07 by migius
+v1.34 - 2009.06.08 by migius
+- export Lamps and Cameras as POINTs
+- export passepartout for perspective projection
+- added option for export objects only from visible layers
+- optimized POLYFACE output: remove loose vertices in back-faces-mode
 - cleaning code
 - fix nasty bug in getExtrusion()
 - support text-objects, also in ortho/persp-projection
@@ -58,7 +64,7 @@
 - support curve objects in projection-2d mode
 - UI stuff: camera selector/manager
 v1.32 - 2009.05.22 by migius
-- debug mode for curve-objects: output pass to Blender
+- debug mode for curve-objects: output redirect to Blender
 - wip support 210-code(extrusion) calculation
 - default settings for 2D and 3D export
 v1.31 - 2009.05.18 by migius
@@ -150,18 +156,20 @@
 print '\n\n\n'
 print 'DXF-Exporter v%s *** start ***' %(__version__)   #---------------------
 
-#DEBUG = True #activets debug mode
+#DEBUG = True #activates debug mode
 
 
 #----globals------------------------------------------
 ONLYSELECTED = 1 # 0/1 = False/True
+ONLYVISIBLE = 1 # ignore objects on invisible layers
 POLYLINES = 1 # prefer POLYLINEs not LINEs
 POLYFACES = 1 # prefer POLYFACEs not 3DFACEs
-PROJECTION = 0 # flatten output geometry to Z = 0.0
+PROJECTION = 0 # output geometry will be projected to XYplane with Z=0.0
 HIDDEN_LINES = 0 #filter out hidden geometry
 SHADOWS = 0 # sun/shadows simulation
-CAMERA = 1 # view from active camera or from 3d-view
-PERSPECTIVE = 0 #perspective camera
+CAMERA = 1 # selected camera index
+PERSPECTIVE = 0 # projection (camera) type: perspective, opposite to orthographic
+CAMERAVIEW = 0 # use camera for projection, opposite is 3d-view
 APPLY_MODIFIERS = 1
 INCLUDE_DUPLIS = 0
 OUTPUT_DWG = 0 #optional save to DWG with extern converter
@@ -170,13 +178,6 @@
 G_ORIGIN = [0.0,0.0,0.0]   #global translation-vector (x,y,z) in Blender units
 ELEVATION = 0.0 #standard elevation = coordinate Z value in Blender units
 
-MIN_DIST = 0.001	#cut-off value for sort out short-distance polyline-"duoble_vertex"
-CURV_RESOLUTION = 12 #(1-128) Bezier curves U-resolution
-CURVARC_RESOLUTION = 4 #(3-32) resolution of circle represented as Bezier curve 
-THIN_RESOLUTION = 8   #(4-64) thin_cylinder arc_resolution - number of segments
-MIN_THICK = MIN_DIST * 10.0  #minimal thickness by forced thickness
-MIN_WIDTH = MIN_DIST * 10.0  #minimal width by forced width
-
 BYBLOCK = 0 #DXF-attribute: assign property to BLOCK defaults
 BYLAYER = None #256 #DXF-attribute: assign property to LAYER defaults
 PREFIX = 'BF_' #used as prefix for DXF names
@@ -266,7 +267,7 @@
 	if currcam: currcam = currcam.getName()
 	if currcam in CAMERAS:
 		CAMERA = CAMERAS.index(currcam)+1
-	GUI_A['camera_on'].val = CAMERA
+	GUI_A['camera_selected'].val = CAMERA
 
 #----------------------------------------------
 def gotoCAMERA():
@@ -502,27 +503,23 @@
 	else:
 		me.getFromObject(ob)
 	# me.transform(mx); get verts data; me.transform(mx_inv)= back to the origin state
-	# above is eventualy faster, but bad, cause
-	# invasive: directly transforms origin geometry and write back rounding errors
-	#we dont want to manipulate origin data
+	# above .transform method is faster, 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)
-		if GUI_A['g_origin_on'].val:
-			for p in allpoints:
-				p[0] += G_ORIGIN[0]
-				p[1] += G_ORIGIN[1]
-				p[2] += G_ORIGIN[2]
+		allpoints = toNewOrigin(allpoints)
 		faces=[]
 		edges=[]
 		if me.faces and PROJECTION and HIDDEN_LINES:
-			if DEBUG: print 'deb:exportMesh HIDDEN_LINES mode' #---------
+			#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' #---------
+			#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]
@@ -553,23 +550,23 @@
 				if allpoints:
 					#TODO: purge allpoints: left only vertices used by faces
 					if DEBUG: mesh_drawBlender(allpoints, None, faces) #deb: draw to scene
-#					faces = [[v+1 for v in f] for f in faces]
-
-					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,new_position,newverts=0,[],[]
-						for used_i,used in enumerate(verts_state):
-							if used:
-								newverts.append(allpoints[used_i])	
-								new_position.append(i)
-								i+=1
-						allpoints = newverts
-						faces = [[new_position[v]+1 for v in f] for f in faces]
+					if not (PROJECTION and HIDDEN_LINES):
+						faces = [[v+1 for v in f] for f in faces]
 					else:
-						faces = [[v+1 for v in f] for f in faces]
+						# 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)
@@ -643,16 +640,25 @@
 
 
 #-----------------------------------------------------
+def toNewOrigin(points):
+	"""relocates points to the new location
+	needs a list of points [x,y,z]
+	"""
+	if GUI_A['g_origin_on'].val:
+		for p in points:
+			p[0] += G_ORIGIN[0]
+			p[1] += G_ORIGIN[1]
+			p[2] += G_ORIGIN[2]
+	return points
+
+
+#-----------------------------------------------------
 def exportEmpty(ob, mx, mw, **common):
 	"""converts Empty-Object to desired projection and representation(DXF-Entity type)
 	"""
 	p =  Mathutils.Vector(ob.loc)
-	#print 'deb: is it a vector?:', p #---------------
 	[p] = projected_co([p], mx)
-	if GUI_A['g_origin_on'].val: #TODO: scale and object orientation
-		p[0] += G_ORIGIN[0]
-		p[1] += G_ORIGIN[1]
-		p[2] += G_ORIGIN[2]
+	[p] = toNewOrigin([p])
 
 	entities = []
 	c = empty_as_list[GUI_A['empty_as'].val]
@@ -662,6 +668,36 @@
 	return entities
 
 #-----------------------------------------------------
+def exportCamera(ob, mx, mw, **common):
+	"""converts Camera-Object to desired projection and representation(DXF-Entity type)
+	"""
+	p =  Mathutils.Vector(ob.loc)
+	[p] = projected_co([p], mx)
+	[p] = toNewOrigin([p])
+
+	entities = []
+	c = camera_as_list[GUI_A['camera_as'].val]
+	if c=="POINT": # export as POINT
+		dxfPOINT = DXF.Point(points=[p],**common)
+		entities.append(dxfPOINT)
+	return entities
+
+#-----------------------------------------------------
+def exportLamp(ob, mx, mw, **common):
+	"""converts Lamp-Object to desired projection and representation(DXF-Entity type)
+	"""
+	p =  Mathutils.Vector(ob.loc)
+	[p] = projected_co([p], mx)
+	[p] = toNewOrigin([p])
+
+	entities = []
+	c = lamp_as_list[GUI_A['lamp_as'].val]
+	if c=="POINT": # export as POINT
+		dxfPOINT = DXF.Point(points=[p],**common)
+		entities.append(dxfPOINT)
+	return entities
+
+#-----------------------------------------------------
 def exportText(ob, mx, mw, **common):
 	"""converts Text-Object to desired projection and representation(DXF-Entity type)
 	"""
@@ -719,13 +755,10 @@
 				#print 'deb: coef=', coef #--------------
 	
 		#print 'deb: point=', point #--------------
-		if GUI_A['g_origin_on'].val: #TODO: scale and object orientation
-			point[0] += G_ORIGIN[0]
-			point[1] += G_ORIGIN[1]
-			point[2] += G_ORIGIN[2]
+		[point] = toNewOrigin([point])
 		point2 = point
 
-		if 0: pass #DEBUG: text_drawBlender(textstr,points,OCS_origin) #deb: draw to scene
+		#if DEBUG: text_drawBlender(textstr,points,OCS_origin) #deb: draw to scene
 		common['extrusion']= Extrusion
 		#common['elevation']= Elevation
 		common['thickness']= Thickness
@@ -870,11 +903,8 @@
 
 				if cur.isCyclic(): closed = 1
 				else: closed = 0

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list