DXF-Exporter script update
authorRemigiusz Fiedler <migius@gmx.net>
Mon, 8 Jun 2009 01:29:58 +0000 (01:29 +0000)
committerRemigiusz Fiedler <migius@gmx.net>
Mon, 8 Jun 2009 01:29:58 +0000 (01:29 +0000)
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

release/scripts/export_dxf.py

index 75cbd9d0014d811dfd6199af9faeed627efe5f04..b32962241cc979e9ba1596cf9cc1d8b538f15714 100644 (file)
@@ -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 @@ Version %s
 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 @@ See the homepage for documentation.
 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 @@ v1.33 - 2009.05.25 by migius
 - 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 @@ d2r = math.pi / 180.0
 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_SCALE = 1.0        #(0.0001-1000) global scaling factor for output dxf data
 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 @@ def updateCAMERA():
        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 @@ def       exportMesh(ob, mx, mx_n, me=None, **common):
        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 @@ def       exportMesh(ob, mx, mx_n, me=None, **common):
                                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]
-                                       else:
+                                       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)
@@ -642,17 +639,26 @@ def curve_drawBlender(vertList, org_point=[0.0,0.0,0.0], closed=0, name="dxfCurv
        #return ob
 
 
+#-----------------------------------------------------
+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]
@@ -661,6 +667,36 @@ def exportEmpty(ob, mx, mw, **common):
                entities.append(dxfPOINT)
        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 @@ def exportText(ob, mx, mw, **common):
                                #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 @@ def exportCurve(ob, mx, mw, **common):
 
                                if cur.isCyclic(): closed = 1
                                else: closed = 0
-                               if GUI_A['g_origin_on'].val: #TODO: scale and object orientation
-                                       for p in points:
-                                               p[0] += G_ORIGIN[0]
-                                               p[1] += G_ORIGIN[1]
-                                               p[2] += G_ORIGIN[2]
+                               points = toNewOrigin(points)
+
                                if DEBUG: curve_drawBlender(points,OCS_origin,closed) #deb: draw to scene
                                common['extrusion']= Extrusion
                                ##common['rotation']= ZRotation
@@ -905,11 +935,8 @@ def exportCurve(ob, mx, mw, **common):
                                points = projected_co(points, mx)
                                if cur.isCyclic(): points.append(points[0])
                                #print 'deb: points', points #--------------
-                               if GUI_A['g_origin_on'].val: #TODO: scale and object orientation
-                                       for p in points:
-                                               p[0] += G_ORIGIN[0]
-                                               p[1] += G_ORIGIN[1]
-                                               p[2] += G_ORIGIN[2]
+                               points = toNewOrigin(points)
+
                                if DEBUG: curve_drawBlender(points,WCS_loc,closed) #deb: draw to scene
                                common['extrusion']= Extrusion
                                common['elevation']= Elevation
@@ -977,7 +1004,7 @@ def getClipBox(camera):
                scaleZ = 1.0/float(far - near)
                z3 =  -float(near)/float(far - near)
                
-               matr = Mathutils.Matrix(  [scaleX, 0.0, 0.0, x3],
+               matrix = Mathutils.Matrix(  [scaleX, 0.0, 0.0, x3],
                                                [0.0, scaleY, 0.0, y3],
                                                [0.0, 0.0, scaleZ, z3],
                                                [0.0, 0.0, 0.0, 1.0])
@@ -1014,7 +1041,7 @@ def getClipBox(camera):
                                                #[0.0,    scaleY, y2,    0.0],
                                                #[0.0,    0.0,  scaleZ, wZ],
                                                #[0.0,    0.0,  -1.0,   0.0])
-               matr = Mathutils.Matrix(  [(2.0 * near)/float(right - left), 0.0, float(right + left)/float(right - left), 0.0],
+               matrix = Mathutils.Matrix(  [(2.0 * near)/float(right - left), 0.0, float(right + left)/float(right - left), 0.0],
                                                [0.0, (2.0 * near)/float(top - bottom), float(top + bottom)/float(top - bottom), 0.0],
                                                [0.0, 0.0, -float(far + near)/float(far - near), -(2.0 * far * near)/float(far - near)],
                                                [0.0, 0.0, -1.0, 0.0])
@@ -1028,7 +1055,7 @@ def getClipBox(camera):
                clip1_Z, clip2_Z]
        #print 'deb: clip_box=\n', clip_box #------------------
        #drawClipBox(clip_box)
-       return clip_box, matr
+       return clip_box, matrix
 
 
 #-----------------------------------------------------
@@ -1143,19 +1170,19 @@ def getCommons(ob):
 
 #-----------------------------------------------------
 def do_export(export_list, filepath):
-       global PERSPECTIVE
+       global PERSPECTIVE, CAMERAVIEW
        Window.WaitCursor(1)
        t = Blender.sys.time()
 
-       #init Drawing ---------------------
+       # init Drawing ---------------------
        d=DXF.Drawing()
-       #add Tables -----------------
+       # add Tables -----------------
        #d.blocks.append(b)                              #table blocks
        #goes automatic: d.styles.append(DXF.Style())                   #table styles
        #d.views.append(DXF.View('Normal'))       #table view
-       d.views.append(DXF.ViewByWindow('BF_TOPVIEW',leftBottom=(-10,-6),rightTop=(10,6)))  #idem
+       d.views.append(DXF.ViewByWindow('BF_TOPVIEW',leftBottom=(-100,-60),rightTop=(100,60)))  #idem
 
-       #add Entities --------------------
+       # add Entities --------------------
        something_ready = 0
        selected_len = len(export_list)
        sce = Scene.GetCurrent()
@@ -1165,38 +1192,47 @@ def do_export(export_list, filepath):
                                                [0.0, 0.0, 1.0, 0.0],
                                                [0.0, 0.0, 0.0, 1.0])
        if PROJECTION:
-               if CAMERA<len(CAMERAS)+1: #the biggest number is the current view
+               if CAMERA<len(CAMERAS)+1: # the biggest number is the current 3d-view
                        act_camera =    Object.Get(CAMERAS[CAMERA-1])
-                       context = sce.getRenderingContext()
+                       #context = sce.getRenderingContext()
                        #print 'deb: context=\n', context #------------------
                        #print 'deb: context=\n', dir(context) #------------------
                        #act_camera = sce.objects.camera
                        #print 'deb: act_camera=', act_camera #------------------
                        if act_camera:
+                               CAMERAVIEW = 1
                                mc0 = act_camera.matrix.copy()
                                #print 'deb: camera.Matrix=\n', mc0 #------------------
                                camera = Camera.Get(act_camera.getData(name_only=True))
                                #print 'deb: camera=', dir(camera) #------------------
                                if camera.type=='persp': PERSPECTIVE = 1
                                elif camera.type=='ortho': PERSPECTIVE = 0
+                               # mcp is matrix.camera.perspective
                                clip_box, mcp = getClipBox(camera)
-       
-                               #mcp = getPerspMatrix(camera)
+                               if PERSPECTIVE:
+                                       # get border
+                                       # lens = camera.lens
+                                       min_X1, max_X1, min_Y1, max_Y1,\
+                                       min_X2, max_X2, min_Y2, max_Y2,\
+                                               min_Z, max_Z = clip_box
+                                       verts = []
+                                       verts.append([min_X1, min_Y1, min_Z])
+                                       verts.append([max_X1, min_Y1, min_Z])
+                                       verts.append([max_X1, max_Y1, min_Z])
+                                       verts.append([min_X1, max_Y1, min_Z])
+                                       border=verts
                                mw = mc0.copy().invert()
        
-               else: # get 3D-View instead of camera           
+               else: # get 3D-View instead of camera-view      
                        #ViewVector = Mathutils.Vector(Window.GetViewVector())
                        #print 'deb: ViewVector=\n', ViewVector #------------------
-                       #TODO: for what is Window.GetViewOffset() ??
+                       #TODO: what is Window.GetViewOffset() for?
                        #print 'deb: Window.GetViewOffset():', Window.GetViewOffset() #---------
                        #Window.SetViewOffset([0,0,0])
-                       #print 'deb: Window.GetViewOffset():', Window.GetViewOffset() #---------
                        mw0 = Window.GetViewMatrix()
                        #print 'deb: mwOrtho    =\n', mw0        #---------
-                       mwp = Window.GetPerspMatrix() #TODO: how get it working?
+                       mwp = Window.GetPerspMatrix() #TODO: how to get it working?
                        #print 'deb: mwPersp    =\n', mwp        #---------
-                       #mw0 = mwp
-                       #clip_box = getClipBox(camera, context)
                        mw = mw0.copy()
        
        #print 'deb: ViewMatrix=\n', mw #------------------
@@ -1204,12 +1240,15 @@ def do_export(export_list, filepath):
        if APPLY_MODIFIERS: tmp_me = Mesh.New('tmp')
        else: tmp_me = None
 
+       if GUI_A['paper_space_on'].val==1: espace=1
+       else: espace=None
+
        layernames = []
        for ob,mx in export_list:
                entities = []
                #mx = ob.matrix.copy()
                #print 'deb: ob =', ob   #---------
-               #print 'deb: ob.type    =', ob.type      #---------
+               print 'deb: ob.type     =', ob.type      #---------
                #print 'deb: mx =\n', mx         #---------
                #print 'deb: mw0        =\n', mw0        #---------
                #mx_n is trans-matrix for normal_vectors for front-side faces
@@ -1221,12 +1260,12 @@ def do_export(export_list, filepath):
                #print 'deb: mx =\n', mx         #---------
                #print 'deb: mx_inv=\n', mx_inv #---------
 
-               if ob.type in ('Mesh', 'Curve', 'Empty', 'Text'):
-                       if GUI_A['paper_space_on'].val==1: espace=1
-                       else: espace=None
+               if ob.type in ('Mesh','Curve','Empty','Text','Camera','Lamp'):
                        elayer,ecolor,eltype = getCommons(ob)
                        #print 'deb: elayer,ecolor,eltype =', elayer,ecolor,eltype #--------------
 
+                       #TODO: use ob.boundBox for drawing extends
+
                        if elayer!=None:
                                if elayer not in layernames:
                                        layernames.append(elayer)
@@ -1246,6 +1285,12 @@ def do_export(export_list, filepath):
                        elif (ob.type == 'Text') and GUI_B['text'].val:
                                entities = exportText(ob, mx, mw, \
                                        paperspace=espace, color=ecolor, layer=elayer, lineType=eltype)
+                       elif (ob.type == 'Camera') and GUI_B['camera'].val:
+                               entities = exportCamera(ob, mx, mw, \
+                                       paperspace=espace, color=ecolor, layer=elayer, lineType=eltype)
+                       elif (ob.type == 'Lamp') and GUI_B['lamp'].val:
+                               entities = exportLamp(ob, mx, mw, \
+                                       paperspace=espace, color=ecolor, layer=elayer, lineType=eltype)
        
                        if entities:
                                something_ready += 1
@@ -1253,8 +1298,19 @@ def do_export(export_list, filepath):
                                        d.append(e)
        
        if something_ready:
+               if PERSPECTIVE: # draw view border
+                       mw2 = Mathutils.Matrix().identity()
+                       points = projected_co(border, mw2)
+                       closed = 1
+                       points = toNewOrigin(points)
+
+                       dxfPLINE = DXF.PolyLine(points,points[0],closed,\
+                               paperspace=espace, color=LAYERCOLOR_DEF)
+                       d.append(dxfPLINE)
+
+
                if not GUI_A['outputDWG_on'].val:
-                       print 'exporting to %s' % filepath
+                       print 'writing to %s' % filepath
                        try:
                                d.saveas(filepath)
                                Window.WaitCursor(0)
@@ -1517,10 +1573,10 @@ parent_as_menu = prepareMenu("export to: %t", parent_as_list)
 proxy_as_list = ["..BLOCK","..XREF","..ungroup","..POINT"]
 proxy_as_menu = prepareMenu("export to: %t", proxy_as_list) 
 
-camera_as_list = ["..BLOCK","..A_CAMERA","..VPORT","..VIEW","..POINT"]
+camera_as_list = ["..BLOCK","..A_CAMERA","..VPORT","..VIEW","POINT"]
 camera_as_menu = prepareMenu("export to: %t", camera_as_list) 
        
-lamp_as_list  = ["..BLOCK","..A_LAMP","..POINT"]
+lamp_as_list  = ["..BLOCK","..A_LAMP","POINT"]
 lamp_as_menu = prepareMenu("export to: %t", lamp_as_list) 
        
 material_to_list= ["COLOR","LAYER","..LINESTYLE","..BLOCK","..XDATA","..INI-File"]
@@ -1534,7 +1590,7 @@ ltype_map_menu = prepareMenu("export to: %t", ltype_map_list)
 layername_from_list = [LAYERNAME_DEF,"drawing_name","scene_name"]
 layername_from_menu = prepareMenu("defaultLAYER: %t", layername_from_list)
 
-layerltype_def_list = ["CONTINUOUS","..DOT","..DASHED","..DASHDOT","..BORDER","..HIDDEN"]
+layerltype_def_list = ["CONTINUOUS","DOT","DASHED","DASHDOT","BORDER","HIDDEN"]
 layerltype_def_menu = prepareMenu("LINETYPE set to: %t",layerltype_def_list)
 
 entitylayer_from_list = ["default_LAYER","obj.name","obj.layer","obj.material","obj.data.name","obj.data.material","..vertexgroup","..group","..map_table"]
@@ -1544,7 +1600,7 @@ entitylayer_from_menu = prepareMenu("entityLAYER from: %t", entitylayer_from_lis
 entitycolor_from_list = ["default_COLOR","BYLAYER","BYBLOCK","obj.layer","obj.color","obj.material","obj.data.material","..map_table"]
 entitycolor_from_menu = prepareMenu("entityCOLOR set to: %t",entitycolor_from_list)
 
-entityltype_from_list = ["default_LTYPE","BYLAYER","BYBLOCK","CONTINUOUS","..DOT","..DASHED","..DASHDOT","..BORDER","..HIDDEN"]
+entityltype_from_list = ["default_LTYPE","BYLAYER","BYBLOCK","CONTINUOUS","DOT","DASHED","DASHDOT","BORDER","HIDDEN"]
 entityltype_from_menu = prepareMenu("entityCOLOR set to: %t",entityltype_from_list)
 
 #dxf-LINE,ARC,CIRCLE,ELLIPSE
@@ -1591,6 +1647,7 @@ keywords_org = {
        'groupFilter_on': 0,
 
        'only_selected_on': ONLYSELECTED,
+       'only_visible_on': ONLYVISIBLE,
        'projection_on' : PROJECTION,
        'hidden_lines_on': HIDDEN_LINES,
        'shadows_on'  : SHADOWS,
@@ -1600,7 +1657,7 @@ keywords_org = {
        'to_polyface_on': POLYFACES,
        'apply_modifiers_on': APPLY_MODIFIERS,
        'include_duplis_on': INCLUDE_DUPLIS,
-       'camera_on': CAMERA,
+       'camera_selected': CAMERA,
 
        'g_originX'   : G_ORIGIN[0],
        'g_originY'   : G_ORIGIN[1],
@@ -1634,8 +1691,8 @@ keywords_org = {
        'group_as' : 0,
        'parent_as' : 0,
        'proxy_as' : 0,
-       'camera_as': 1,
-       'lamp_as' : 1,
+       'camera_as': 4,
+       'lamp_as' : 2,
        }
 
 drawTypes_org = {
@@ -1875,8 +1932,8 @@ def resetDefaultConfig_3D():  #-----------------------------------------------
                'group' : 1,
                'parent' : 1,
                #'proxy' : 0,
-               'camera': 1,
-               'lamp'  : 1,
+               #'camera': 1,
+               #'lamp'  : 1,
                }
        presetConfig_polyline(1)
        updateConfig(keywords3d, drawTypes3d)
@@ -1921,7 +1978,7 @@ def inputOriginVector():
 def update_globals():  #-----------------------------------------------------------------
        """ update globals if GUI_A changed
        """
-       global  ONLYSELECTED, DEBUG,\
+       global  ONLYSELECTED,ONLYVISIBLE, DEBUG,\
        PROJECTION, HIDDEN_LINES,       CAMERA, \
        G_SCALE, G_ORIGIN,\
        PREFIX, LAYERNAME_DEF, LAYERCOLOR_DEF, LAYERLTYPE_DEF,\
@@ -1930,6 +1987,7 @@ def update_globals():  #--------------------------------------------------------
        #global POLYLINES
        
        ONLYSELECTED = GUI_A['only_selected_on'].val
+       ONLYVISIBLE = GUI_A['only_visible_on'].val
        """
        POLYLINES = GUI_A['to_polyline_on'].val
        if GUI_A['curve_as'].val==1: POLYLINES=1
@@ -1940,9 +1998,9 @@ def update_globals():  #--------------------------------------------------------
        else: DEBUG = 0
        PROJECTION = GUI_A['projection_on'].val
        HIDDEN_LINES = GUI_A['hidden_lines_on'].val
-       CAMERA = GUI_A['camera_on'].val
+       CAMERA = GUI_A['camera_selected'].val
        G_SCALE = GUI_A['g_scale'].val
-       if GUI_A['g_origin_on'].val: #TODO: scale and object orientation
+       if GUI_A['g_origin_on'].val:
                G_ORIGIN[0] = GUI_A['g_originX'].val
                G_ORIGIN[1] = GUI_A['g_originY'].val
                G_ORIGIN[2] = GUI_A['g_originZ'].val
@@ -2117,14 +2175,14 @@ def draw_UI():  #---------------------------------------------------------------
 
                y -= 20
                Draw.BeginAlign()
-               GUI_B['camera'] = Draw.Toggle('..Camera', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['camera'].val, "(*todo) Export Camera-Objects   on/off")
+               GUI_B['camera'] = Draw.Toggle('Camera', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['camera'].val, "(*wip) Export Camera-Objects   on/off")
                if GUI_B['camera'].val:
                        GUI_A['camera_as'] = Draw.Menu(camera_as_menu, EVENT_NONE, b1, y, b1_, 20, GUI_A['camera_as'].val, "Select target DXF-object")
                Draw.EndAlign()
 
                y -= 20
                Draw.BeginAlign()
-               GUI_B['lamp'] = Draw.Toggle('..Lamp', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['lamp'].val, "(*todo) Export Lamp-Objects   on/off")
+               GUI_B['lamp'] = Draw.Toggle('Lamp', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['lamp'].val, "(*wip) Export Lamp-Objects   on/off")
                if GUI_B['lamp'].val:
                        GUI_A['lamp_as'] = Draw.Menu(lamp_as_menu, EVENT_NONE, b1, y, b1_, 20, GUI_A['lamp_as'].val, "Select target DXF-object")
                Draw.EndAlign()
@@ -2140,13 +2198,13 @@ def draw_UI():  #---------------------------------------------------------------
                but_ = menu_w / 6
                b0 = but0c + (menu_w - but_*6)/2
                Draw.BeginAlign()
-               GUI_A['paper_space_on'] = Draw.Toggle('paper', EVENT_NONE, b0+but_*0, y, but_, 20, GUI_A['paper_space_on'].val, "Export to Paper-Space, otherwise to Model-Space   on/off")
+               #GUI_A['dummy_on'] = Draw.Toggle('-', EVENT_NONE, b0+but_*0, y, but_, 20, GUI_A['dummy_on'].val, "placeholder only   on/off")
+               GUI_A['paper_space_on'] = Draw.Toggle('Paper', EVENT_NONE, b0+but_*0, y, but_, 20, GUI_A['paper_space_on'].val, "Export to Paper-Space, otherwise to Model-Space   on/off")
                GUI_A['layFrozen_on'] = Draw.Toggle ('..frozen', EVENT_NONE, b0+but_*1, y, but_, 20, GUI_A['layFrozen_on'].val, "(*todo) Support LAYER.frozen status   on/off")
                GUI_A['materialFilter_on'] = Draw.Toggle('..material', EVENT_NONE, b0+but_*2, y, but_, 20, GUI_A['materialFilter_on'].val, "(*todo) Material filtering   on/off")
                GUI_A['colorFilter_on'] = Draw.Toggle('..color', EVENT_NONE, b0+but_*3, y, but_, 20, GUI_A['colorFilter_on'].val, "(*todo) Color filtering   on/off")
                GUI_A['groupFilter_on'] = Draw.Toggle('..group', EVENT_NONE, b0+but_*4, y, but_, 20, GUI_A['groupFilter_on'].val, "(*todo) Group filtering   on/off")
                GUI_A['objectFilter_on'] = Draw.Toggle('..object', EVENT_NONE, b0+but_*5, y, but_, 20, GUI_A['objectFilter_on'].val, "(*todo) Object filtering   on/off")
-               #GUI_A['dummy_on'] = Draw.Toggle('-', EVENT_NONE, but3c, y, but_3c, 20, GUI_A['dummy_on'].val, "dummy   on/off")
                Draw.EndAlign()
 
                # -----end filters--------------------------------------
@@ -2281,34 +2339,39 @@ def draw_UI():  #---------------------------------------------------------------
        b0, b0_ = but0c, but_0c + butt_margin +but_1c
        GUI_A['only_selected_on'] = Draw.Toggle('Export Selection', EVENT_NONE, b0, y, b0_, 20, GUI_A['only_selected_on'].val, "Export only selected geometry   on/off")
        b0, b0_ = but2c, but_2c + butt_margin + but_3c
+       Draw.BeginAlign()
+       GUI_A['projection_on'] = Draw.Toggle('2d Projection', EVENT_REDRAW, b0, y, b0_, 20, GUI_A['projection_on'].val, "Export a 2d Projection according 3d-View or Camera-View   on/off")
+       if GUI_A['projection_on'].val:
+               GUI_A['camera_selected'] = Draw.Menu(MenuCAMERA, EVENT_CAMERA, b0, y-20, b0_-20, 20, GUI_A['camera_selected'].val, 'Choose the camera to be rendered')          
+               Draw.PushButton('>', EVENT_setCAMERA, b0+b0_-20, y-20, 20, 20, 'switch to selected Camera - make it active')
+               GUI_A['hidden_lines_on'] = Draw.Toggle('Remove backFaces', EVENT_NONE, b0, y-40, b0_, 20, GUI_A['hidden_lines_on'].val, "Filter out backFaces   on/off")
+               #GUI_A['shadows_on'] = Draw.Toggle('..Shadows', EVENT_REDRAW, b0, y-60, but_2c, 20, GUI_A['shadows_on'].val, "(*todo) Shadow tracing   on/off")
+               #GUI_A['light_on'] = Draw.Menu(MenuLIGHT, EVENT_LIGHT, but3c, y-60, but_3c, 20, GUI_A['light_on'].val, '(*todo) Choose the light source(sun) to be rendered')           
+       Draw.EndAlign()
 
        y -= 20
        b0, b0_ = but0c, but_0c + butt_margin +but_1c
-       GUI_A['to_polyline_on'] = Draw.Toggle('POLYLINE', EVENT_PRESETPLINE, b0, y, b0_, 20, GUI_A['to_polyline_on'].val, "Export to POLYLINEs, otherwise to LINEs/3DFACEs   on/off")
-       b0, b0_ = but2c, but_2c + butt_margin + but_3c
+       GUI_A['only_visible_on'] = Draw.Toggle('Visible only', EVENT_PRESETPLINE, b0, y, b0_, 20, GUI_A['only_visible_on'].val, "Export only from visible layers   on/off")
+       #b0, b0_ = but2c, but_2c + butt_margin + but_3c
 
-       Draw.BeginAlign()
-       GUI_A['projection_on'] = Draw.Toggle('2d Projection', EVENT_REDRAW, b0, y+20, b0_, 20, GUI_A['projection_on'].val, "Export a 2d Projection according 3d-View or Camera-View   on/off")
-       if GUI_A['projection_on'].val:
-               GUI_A['camera_on'] = Draw.Menu(MenuCAMERA, EVENT_CAMERA, b0, y, b0_-20, 20, GUI_A['camera_on'].val, 'Choose the camera to be rendered')         
-               Draw.PushButton('>', EVENT_setCAMERA, b0+b0_-20, y, 20, 20, 'switch to selected Camera - make it active')
-               GUI_A['hidden_lines_on'] = Draw.Toggle('Hide back-Faces', EVENT_NONE, b0, y-20, b0_, 20, GUI_A['hidden_lines_on'].val, "Filter out back-Faces   on/off")
-               #GUI_A['shadows_on'] = Draw.Toggle('..Shadows', EVENT_REDRAW, b0, y-40, but_2c, 20, GUI_A['shadows_on'].val, "(*todo) Shadow tracing   on/off")
-               #GUI_A['light_on'] = Draw.Menu(MenuLIGHT, EVENT_LIGHT, but3c, y-40, but_3c, 20, GUI_A['light_on'].val, '(*todo) Choose the light source(sun) to be rendered')           
-       Draw.EndAlign()
+       y -= 20
+       b0, b0_ = but0c, but_0c + butt_margin +but_1c
+       GUI_A['to_polyline_on'] = Draw.Toggle('POLYLINE-Mode', EVENT_PRESETPLINE, b0, y, b0_, 20, GUI_A['to_polyline_on'].val, "Export to POLYLINE/POLYFACEs, otherwise to LINEs/3DFACEs   on/off")
+       #b0, b0_ = but2c, but_2c + butt_margin + but_3c
 
        y -= 20
        b0, b0_ = but0c, but_0c + butt_margin +but_1c
        GUI_A['apply_modifiers_on'] = Draw.Toggle('Apply Modifiers', EVENT_NONE, b0, y, b0_, 20, GUI_A['apply_modifiers_on'].val, "Apply modifier stack to mesh objects before export   on/off")
-       b0, b0_ = but2c, but_2c + butt_margin + but_3c
+       #b0, b0_ = but2c, but_2c + butt_margin + but_3c
 
        y -= 20
        b0, b0_ = but0c, but_0c + butt_margin +but_1c
        GUI_A['include_duplis_on'] = Draw.Toggle('Include Duplis', EVENT_NONE, b0, y, b0_, 20, GUI_A['include_duplis_on'].val, "Export Duplicates (dupliverts, dupliframes, dupligroups)   on/off")
-       b0, b0_ = but2c, but_2c + butt_margin + but_3c
+       #b0, b0_ = but2c, but_2c + butt_margin + but_3c
        
+
        
-       y -= 50
+       y -= 30
        Draw.PushButton('EXIT', EVENT_EXIT, but0c, y, but_0c+bm, 20, '' )
        Draw.PushButton('HELP', EVENT_HELP, but1c, y, but_1c+bm, 20, 'goes to online-Manual on wiki.blender.org')
        GUI_A['optimization'] = Draw.Number('', EVENT_NONE, but2c, y, 40, 20, GUI_A['optimization'].val, 0, 3, "Optimization Level: 0=Debug/Draw-in, 1=Verbose, 2=ProgressBar, 3=SilentMode")
@@ -2541,11 +2604,11 @@ def bevent(evt):
                resetDefaultConfig_3D()
                Draw.Redraw()
        elif evt in (EVENT_CAMERA,EVENT_LIGHT):
-               CAMERA = GUI_A['camera_on'].val
+               CAMERA = GUI_A['camera_selected'].val
                if CAMERA==len(CAMERAS)+1:
                        doAllCameras = True
                else:
-                       print 'deb: CAMERAS=',CAMERAS #----------------
+                       pass #print 'deb: CAMERAS=',CAMERAS #----------------
                Draw.Redraw()
        elif (evt==EVENT_setCAMERA):
                if CAMERA<len(CAMERAS)+1:
@@ -2616,12 +2679,22 @@ http://wiki.blender.org/index.php?title=Scripts/Manual/Export/autodesk_dxf')
                        else:
                                Draw.Redraw()
                elif dxfFile.lower()[-4:] in ('.dxf','.dwg'): # and Blender.sys.exists(dxfFile):
-                       print '\nStandard Mode: active'
+                       print 'preparing for export ---' #Standard Mode: activated
                        filepath = dxfFile
                        sce = Scene.GetCurrent()
                        if ONLYSELECTED: sel_group = sce.objects.selected
                        else: sel_group = sce.objects
-                       
+                               
+                       if ONLYVISIBLE:
+                               sel_group_temp = []
+                               layerlist = sce.getLayers()
+                               for ob in sel_group:
+                                       for lay in ob.layers:
+                                         if lay in layerlist:
+                                                       sel_group_temp.append(ob)
+                                                       break
+                               sel_group = sel_group_temp
+                                                               
                        export_list = getObjectsAndDuplis(sel_group,MATRICES=True)
                
                        if export_list: do_export(export_list, filepath)