[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20973] trunk/blender/release/scripts/ export_dxf.py: DXF-Exporter v1.35 - 2009.06.18 by migius
Remigiusz Fiedler
migius at gmx.net
Thu Jun 18 12:34:16 CEST 2009
Revision: 20973
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20973
Author: migius
Date: 2009-06-18 12:34:16 +0200 (Thu, 18 Jun 2009)
Log Message:
-----------
DXF-Exporter v1.35 - 2009.06.18 by migius
- missing support for multiple-instances of Curve-Objects as BLOCK/INSERTs
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-18 10:34:16 UTC (rev 20972)
+++ trunk/blender/release/scripts/export_dxf.py 2009-06-18 10:34:16 UTC (rev 20973)
@@ -7,7 +7,7 @@
Tooltip: 'Export geometry to DXF/DWG-r12 (Drawing eXchange Format).'
"""
-__version__ = "1.35 - 2009.06.17"
+__version__ = "1.35 - 2009.06.18"
__author__ = "Remigiusz Fiedler (AKA migius)"
__license__ = "GPL"
__url__ = "http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_dxf"
@@ -43,11 +43,11 @@
- wip: write drawing extends for automatic view positioning in CAD
- 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
+v1.35 - 2009.06.18 by migius
+- export multiple-instances of Curve-Objects as BLOCK/INSERTs
- 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
@@ -183,6 +183,7 @@
CAMERA = 1 # selected camera index
PERSPECTIVE = 0 # projection (camera) type: perspective, opposite to orthographic
CAMERAVIEW = 0 # use camera for projection, opposite is 3d-view
+INSTANCES = 1 # Export instances of Mesh/Curve as BLOCK/INSERTs on/off
APPLY_MODIFIERS = 1
INCLUDE_DUPLIS = 0
OUTPUT_DWG = 0 #optional save to DWG with extern converter
@@ -531,7 +532,7 @@
#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 GUI_A['instances_on'].val and me.users>1 and not PROJECTION:
if me.name in BLOCKREGISTRY.keys():
insert_name = BLOCKREGISTRY[me.name]
# write INSERT to entities
@@ -999,131 +1000,195 @@
entities = []
block = None
curve = ob.getData()
- WCS_loc = ob.loc # WCS_loc is object location in WorldCoordSystem
- #WCS_loc = [0.0,0.0,0.0]
- #print 'deb: WCS_loc=', WCS_loc #---------
- sizeX = ob.SizeX
- sizeY = ob.SizeY
- sizeZ = ob.SizeZ
- rotX = ob.RotX
- rotY = ob.RotY
- rotZ = ob.RotZ
- #print 'deb: sizeX=%s, sizeY=%s' %(sizeX, sizeY) #---------
+ #print 'deb: curve=', dir(curve) #---------
+ # TODO: should be: if curve.users>1 and not (PERSPECTIVE or (PROJECTION and HIDDEN_MODE):
+ if GUI_A['instances_on'].val and curve.users>1 and not PROJECTION:
+ if curve.name in BLOCKREGISTRY.keys():
+ insert_name = BLOCKREGISTRY[curve.name]
+ # write INSERT to entities
+ entities = exportInsert(ob, mx,insert_name, **common)
+ else:
+ # generate geom_output in ObjectCS
+ imx = Mathutils.Matrix().identity()
+ WCS_loc = [0,0,0] # WCS_loc is object location in WorldCoordSystem
+ #print 'deb: WCS_loc=', WCS_loc #---------
+ sizeX = sizeY = sizeZ = 1.0
+ rotX = rotY = rotZ = 0.0
+ Thickness,Extrusion,ZRotation,Elevation = None,None,None,None
+ ZRotation,Zrotmatrix,OCS_origin,ECS_origin = None,None,None,None
+ AXaxis = imx[0].copy().resize3D() # = ArbitraryXvector
+ OCS_origin = [0,0,0]
+ if not PROJECTION:
+ #Extrusion, ZRotation, Elevation = getExtrusion(mx)
+ Extrusion, AXaxis = getExtrusion(imx)
+
+ # no thickness/width for POLYLINEs converted into Screen-C-S
+ #print 'deb: curve.ext1=', curve.ext1 #---------
+ if curve.ext1: Thickness = curve.ext1 * sizeZ
+ if curve.ext2 and sizeX==sizeY:
+ Width = curve.ext2 * sizeX
+ if "POLYLINE"==curve_as_list[GUI_A['curve_as'].val]: # export as POLYLINE
+ ZRotation,Zrotmatrix,OCS_origin,ECS_origin = getTargetOrientation(imx,Extrusion,\
+ AXaxis,WCS_loc,sizeX,sizeY,sizeZ,rotX,rotY,rotZ)
- Thickness,Extrusion,ZRotation,Elevation = None,None,None,None
- AXaxis = mx[0].copy().resize3D() # = ArbitraryXvector
- OCS_origin = [0,0,0]
- if not PROJECTION:
- #Extrusion, ZRotation, Elevation = getExtrusion(mx)
- Extrusion, AXaxis = getExtrusion(mx)
+ entities = writeCurveEntities(curve, imx,
+ Thickness,Extrusion,ZRotation,Elevation,AXaxis,Zrotmatrix,
+ WCS_loc,OCS_origin,ECS_origin,sizeX,sizeY,sizeZ,
+ **common)
- # no thickness/width for POLYLINEs converted into ScreenCS
- #print 'deb: curve.ext1=', curve.ext1 #---------
- if curve.ext1: Thickness = curve.ext1 * sizeZ
- if curve.ext2 and sizeX==sizeY:
- Width = curve.ext2 * sizeX
- if "POLYLINE"==curve_as_list[GUI_A['curve_as'].val]: # export as POLYLINE
- ZRotation,Zrotmatrix,OCS_origin,ECS_origin = getTargetOrientation(mx,Extrusion,\
- AXaxis,WCS_loc,sizeX,sizeY,sizeZ,rotX,rotY,rotZ)
+ if entities: # if not empty block
+ # write BLOCK definition and INSERT entity
+ # BLOCKREGISTRY = dictionary 'blender_name':'dxf_name'.append(me.name)
+ BLOCKREGISTRY[curve.name]=validDXFr12name(('CU_'+ curve.name))
+ insert_name = BLOCKREGISTRY[curve.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
+ WCS_loc = ob.loc # WCS_loc is object location in WorldCoordSystem
+ #print 'deb: WCS_loc=', WCS_loc #---------
+ sizeX = ob.SizeX
+ sizeY = ob.SizeY
+ sizeZ = ob.SizeZ
+ rotX = ob.RotX
+ rotY = ob.RotY
+ rotZ = ob.RotZ
+ #print 'deb: sizeX=%s, sizeY=%s' %(sizeX, sizeY) #---------
- for cur in curve:
- #print 'deb: START cur=', cur #--------------
- points = []
- if cur.isNurb():
- for point in cur:
- #print 'deb:isNurb point=', point #---------
- vec = point[0:3]
- #print 'deb: vec=', vec #---------
- pkt = Mathutils.Vector(vec)
- #print 'deb: pkt=', pkt #---------
- points.append(pkt)
- else:
- for point in cur:
- #print 'deb:isBezier point=', point.getTriple() #---------
- vec = point.getTriple()[1]
- #print 'deb: vec=', vec #---------
- pkt = Mathutils.Vector(vec)
- #print 'deb: pkt=', pkt #---------
- points.append(pkt)
+ Thickness,Extrusion,ZRotation,Elevation = None,None,None,None
+ ZRotation,Zrotmatrix,OCS_origin,ECS_origin = None,None,None,None
+ AXaxis = mx[0].copy().resize3D() # = ArbitraryXvector
+ OCS_origin = [0,0,0]
+ if not PROJECTION:
+ #Extrusion, ZRotation, Elevation = getExtrusion(mx)
+ Extrusion, AXaxis = getExtrusion(mx)
+
+ # no thickness/width for POLYLINEs converted into Screen-C-S
+ #print 'deb: curve.ext1=', curve.ext1 #---------
+ if curve.ext1: Thickness = curve.ext1 * sizeZ
+ if curve.ext2 and sizeX==sizeY:
+ Width = curve.ext2 * sizeX
+ if "POLYLINE"==curve_as_list[GUI_A['curve_as'].val]: # export as POLYLINE
+ ZRotation,Zrotmatrix,OCS_origin,ECS_origin = getTargetOrientation(mx,Extrusion,\
+ AXaxis,WCS_loc,sizeX,sizeY,sizeZ,rotX,rotY,rotZ)
+ entities = writeCurveEntities(curve, mx,
+ Thickness,Extrusion,ZRotation,Elevation,AXaxis,Zrotmatrix,
+ WCS_loc,OCS_origin,ECS_origin,sizeX,sizeY,sizeZ,
+ **common)
- #print 'deb: points', points #--------------
- if len(points)>1:
- c = curve_as_list[GUI_A['curve_as'].val]
+ return entities, block
- if c=="POLYLINE": # export Curve as POLYLINE
- if not PROJECTION:
- # recalculate points(2d=X,Y) into Entity-Coords-System
- for p in points: # list of vectors
- p[0] *= sizeX
- p[1] *= sizeY
- p2 = p * Zrotmatrix
- p2[0] += ECS_origin[0]
- p2[1] += ECS_origin[1]
- p[0],p[1] = p2[0],p2[1]
- else:
- points = projected_co(points, mx)
- #print 'deb: points', points #--------------
- if cur.isCyclic(): closed = 1
- else: closed = 0
- points = toGlobalOrigin(points)
+#-------------------------------------------------
+def writeCurveEntities(curve, mx,
+ Thickness,Extrusion,ZRotation,Elevation,AXaxis,Zrotmatrix,
+ WCS_loc,OCS_origin,ECS_origin,sizeX,sizeY,sizeZ,
+ **common):
+ """help routine for exportCurve()
+ """
+ entities = []
+
+ if 1:
+ for cur in curve:
+ #print 'deb: START cur=', cur #--------------
+ points = []
+ if cur.isNurb():
+ for point in cur:
+ #print 'deb:isNurb point=', point #---------
+ vec = point[0:3]
+ #print 'deb: vec=', vec #---------
+ pkt = Mathutils.Vector(vec)
+ #print 'deb: pkt=', pkt #---------
+ points.append(pkt)
+ else:
+ for point in cur:
+ #print 'deb:isBezier point=', point.getTriple() #---------
+ vec = point.getTriple()[1]
+ #print 'deb: vec=', vec #---------
+ pkt = Mathutils.Vector(vec)
+ #print 'deb: pkt=', pkt #---------
+ points.append(pkt)
+
+ #print 'deb: points', points #--------------
+ if len(points)>1:
+ c = curve_as_list[GUI_A['curve_as'].val]
- if DEBUG: curve_drawBlender(points,OCS_origin,closed) #deb: draw to scene
- common['extrusion']= Extrusion
- ##common['rotation']= ZRotation
- ##common['elevation']= Elevation
- common['thickness']= Thickness
- #print 'deb: common=', common #------------------
+ if c=="POLYLINE": # export Curve as POLYLINE
+ if not PROJECTION:
+ # recalculate points(2d=X,Y) into Entity-Coords-System
+ for p in points: # list of vectors
+ p[0] *= sizeX
+ p[1] *= sizeY
+ p2 = p * Zrotmatrix
+ p2[0] += ECS_origin[0]
+ p2[1] += ECS_origin[1]
+ p[0],p[1] = p2[0],p2[1]
+ else:
+ points = projected_co(points, mx)
+ #print 'deb: points', points #--------------
+
+ if cur.isCyclic(): closed = 1
+ else: closed = 0
+ points = toGlobalOrigin(points)
+
+ if DEBUG: curve_drawBlender(points,OCS_origin,closed) #deb: draw to scene
- if 0: #DEBUG
- p=AXaxis[:3]
- entities.append(DXF.Line([[0,0,0], p],**common))
- p=ECS_origin[:3]
- entities.append(DXF.Line([[0,0,0], p],**common))
- common['color']= 5
- p=OCS_origin[:3]
- entities.append(DXF.Line([[0,0,0], p],**common))
- #OCS_origin=[0,0,0] #only debug----------------
+ common['extrusion']= Extrusion
+ ##common['rotation']= ZRotation
+ ##common['elevation']= Elevation
+ common['thickness']= Thickness
+ #print 'deb: common=', common #------------------
+
+ if 0: #DEBUG
+ p=AXaxis[:3]
+ entities.append(DXF.Line([[0,0,0], p],**common))
+ p=ECS_origin[:3]
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list