Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'release/scripts/import_dxf.py')
-rw-r--r--release/scripts/import_dxf.py3330
1 files changed, 2368 insertions, 962 deletions
diff --git a/release/scripts/import_dxf.py b/release/scripts/import_dxf.py
index 2a1081420e4..bb0119a9a81 100644
--- a/release/scripts/import_dxf.py
+++ b/release/scripts/import_dxf.py
@@ -2,88 +2,166 @@
"""
Name: 'Autodesk DXF (.dxf)'
-Blender: 244
+Blender: 246
Group: 'Import'
Tooltip: 'Import for DXF geometry data (Drawing eXchange Format).'
"""
__author__ = 'Kitsu(Ed Blake) & migius(Remigiusz Fiedler)'
-__version__ = '1.0.11 - 2007.11.17 by migius'
+__version__ = '1.12 - 2008.08.03 by migius'
__url__ = ["http://blenderartists.org/forum/showthread.php?t=84319",
"http://wiki.blender.org/index.php/Scripts/Manual/Import/DXF-3D"]
-__email__ = ["Kitsune_e(at)yahoo.com", "migius(at)4d-vectors.de"]
+__email__ = ["migius(at)4d-vectors.de","Kitsune_e(at)yahoo.com"]
__bpydoc__ = """\
-This script imports DXF objects (2d/3d) into Blender.
+This script imports objects from DXF (2d/3d) into Blender.
-This script imports 2d and 3d Geometery from DXFr12 format files.
-This version is focused on import of 3d-objects.
+This script imports 2d and 3d geometery from DXF files.
+Supported DXF format versions: from (r2.5) r12 up to 2008.
+Enhanced features are:
+- configurable object filtering and geometry manipulation,
+- configurable material pre-processing,
+- DXF-code analyze and reporting.
-Supported DXF Objects:
+Supported DXF r12 objects:
LINE,
POINT,
SOLID,
TRACE,
TEXT,
INSERT (=block),
-MINSERT (=arrays of blocks),
+MINSERT (=array of blocks),
CIRCLE,
ARC,
3DFACE,
2d-POLYLINE (=plane, incl. arc, variable-width, curve, spline),
-3d-POLYLINE (=non-plane polylines),
+3d-POLYLINE (=non-plane),
3d-POLYMESH,
-3d-POLYFACE
-
-under construction, partly supported DXF>r12 Objects:
-LWPOLYLINE (LightWeight), MLINE, MTEXT, ELLIPSE
-
-Unsupported DXF Objects:
-DXF r12: DIMENSION, XREF (External Reference),
-DXF>r12: SPLINE, GROUP, RAY/XLINE, LEADER, 3DSOLID, BODY, REGION, dynamic BLOCK
-
-Supported Properties:
-Hierarchy: Entire DXF BLOCKs hierarchy is preserved after import into Blender
-visibility, frozen,
-COLOR, LAYER,
-thickness, width,
-(todo: grouped, XDATA)
-It is recommended to use DXF-object properties for coding Blender materials.
+3d-POLYFACE,
+VIEW, VPORT
+XREF (External Reference).
+
+Supported DXF>r12 objects:
+ELLIPSE,
+LWPOLYLINE (LightWeight Polyline),
+SPLINE,
+(wip v1.13) MLINE,
+(wip v1.13) MTEXT
+
+Unsupported objects:
+DXF r12: DIMENSION.
+DXF>r12: GROUP, RAY/XLINE, LEADER, 3DSOLID, BODY, REGION, dynamic BLOCK
+
+Supported geometry: 2d and 3d DXF-objects.
+Curves imported as Blender curves or meshes optionally.
+
+Supported layout modes:
+"model space" is default,
+"paper space" as option (= "layout views")
+
+Supported scene definition objescts produced with AVE_RENDER:
+scene: selection of lights assigned to the camera,
+lights: DIRECT, OVERHEAD, SH_SPOT,
+(wip v1.13 import of AVE_RENDER material definitions)
+
+Hierarchy:
+Entire DXF BLOCK hierarchy is preserved after import into Blender
+(BLOCKs as groups on layer19, INSERTs as dupliGroups on target layer).
+
+Supported properties:
+visibility status,
+frozen status,
+thickness,
+width,
+color,
+layer,
+(wip v1.13: XDATA, grouped status)
+It is recommended to use DXF-object properties for assign Blender materials.
Notes:
- Recommend that you run 'RemoveDoubles' on each imported mesh after using this script
- Blocks are created on layer 19 then referenced at each insert point.
-- Big DXF-files (over 1500 objects) decrease import performance. The problem is not the inefficiency of python-scripting but Blenders performance in creating new objects in his database - probably a database management problem.
-
-TODO:
-- the new style object visibility
-- support for real 3d-solids (ACIS)
-- (to see more, search for "-todo-" in script)
+- support for DXF-files up to 160MB on systems with 1GB RAM
+- DXF-files with over 1500 objects decrease import performance.
+The problem is not the inefficiency of python-scripting but Blenders performance
+in creating new objects in scene database - probably a database management problem.
"""
"""
History:
- v1.0 - 2007.11. by migius: "full 3d"-release
+ v1.0 - 2007/2008 by migius
planned tasks:
+ -- (to see more, search for "--todo--" in script code)
-- command-line-mode/batch-mode
-- in-place-editing for dupliGroups
- -- filtering of unused/not-inserted BLOCKs
- -- support for MLine
- -- support for Ellipse
- -- support for Mtext
- -- blender_object.ID.properties[dxf_layer_name]
+ -- support for MLINE (is exported to r12 as BLOCK*Unnamed with LINEs)
+ -- support for MTEXT (is exported to r12 as TEXT???)
+ -- blender_object.properties['dxf_layer_name']
-- better support for long dxf-layer-names
- -- Configuration files(.ini) should/can handle various material setups
+ -- add configuration file.ini handles multiple material setups
-- added f_layerFilter
-- to-check: obj/mat/group/_mapping-idea from ideasman42:
-- curves: added "fill/non-fill" option for closed curves: CIRCLEs,ELLIPSEs,POLYLINEs
- -- bug:? object = Object.Get(obname) -> = SCENE.getChildren(obname)
-- "normalize Z" option to correct non-planar figures
-- LINEs need "width" in 3d-space incl vGroups
-- support width_force for LINEs/ELLIPSEs = "solidify"
- -- bug: dxf-files without layer-section missing layersmap{}
- -- color BYLAYER=256,BYBLOCK=0
- -- blocknames conventions length
- v1.0.11: 2007.11.17 by migius
+ -- add better support for color_index BYLAYER=256, BYBLOCK=0
+ -- bug: "oneMesh" produces irregularly errors
+ -- bug: Registry recall from hd_cache ?? only win32 bug??
+ -- support DXF-definitions of scene, lights and cameras
+ -- support ortho mode for VIEWs and VPORTs as cameras
+
+
+ v1.12 - 2008.08.03 by migius
+ c2 warningfix: relocating of globals: layersmap, oblist
+ c2 modif UI: buttons newScene+targetLayer moved to start panel
+ v1.12 - 2008.07.04 by migius
+ c1 added control Curve's OrderU parameter
+ c1 modif UI: preset buttons X-2D-3D moved to start panel
+ b6 added handling exception of not registered LAYERs (Hammer-HL-editor DXF output)
+ b5 rebuild UI: global preset 2D for Curve-Import
+ b5 added UI-options: PL-MESH N+N plmesh_flip and normals_out
+ b5 added support for SPLINEs, added control OrderU parameter
+ b5 rewrote draw module for NURBS_curve and Bezier_curve
+ v1.12 - 2008.06.22 by migius
+ b4 change versioning system 1.0.12 -> 1.12
+ b4 print at start version-info to console
+ b3 bugfix: ob.name conflict with existing meshes (different ob.name/mesh.name)
+ v1.0.12: 2008.05.24 by migius
+ b2 added support for LWPOLYLINEs
+ b2 added support for ProE in readerDXF.py
+ v1.0.12: 2008.02.08 by migius
+ b1 update: object = Object.Get(obname) -> f_getSceChild().getChildren()
+ a9 bugfix by non-existing tables views, vports, layers (Kai reported)
+ v1.0.12: 2008.01.17 by migius
+ a8 lately used INI-dir/filename persistently stored in Registry
+ a8 lately used DXF-dir/filename persistently stored in Registry
+ a7 fix missing layersmap{} for dxf-files without "section:layer"
+ a6 added support for XREF external referenced BLOCKs
+ a6 check for bug in AutoCAD2002:DXFr12export: ELLIPSE->POLYLINE_ARC fault angles
+ a6 support VIEWs and VPORTs as cameras: ortho and perspective mode
+ a6 save resources through ignoring unused BLOCKs (not-inserted or on frozen/blocked layers)
+ a6 added try_finally: f.close() for all IO-files
+ a6 added handling for TypeError raise
+ a5 bugfix f_getOCS for (0,0,z!=1.0) (ellipse in Kai's dxf)
+ a4 added to analyzeTool: report about VIEWs, VPORTs, unused/xref BLOCKs
+ a4 bugfix: individual support for 2D/3DPOLYLINE/POLYMESH
+ a4 added to UI: (*wip)BLOCK-(F): name filtering for BLOCKs
+ a4 added to UI: BLOCK-(n): filter anoname/hatch BLOCKs *X...
+ a2 g_scale_as is no more GUI_A-variable
+ a2 bugfix "material": negative sign color_index
+ a2 added support for BLOCKs defined with origin !=(0,0,0)
+ a1 added 'global.reLocation-vector' option
+
+ v1.0.11: 2007.11.24 by migius
+ c8 added 'curve_resolution_U' option
+ c8 added context_sensitivity for some UI-buttons
+ c8 bugfix ELLIPSE rotation, added closed_variant and caps
+ c7 rebuild UI: new layout, grouping and meta-buttons
+ c6 rewritten support for ELLIPSE mesh & curve representation
+ c6 restore selector-buttons for DXF-drawTypes: LINE & Co
+ c6 change header of INI/INF-files: # at begin
+ c6 apply scale(1,1,1) after glob.Scale for all mesh objects, not for curve objects.
+ c5 fixing 'material_on' option
c4 added "analyze DXF-file" UI-option: print LAYER/BLOCK-dependences into a textfile
c3 human-formating of data in INI-Files
c2 added "caps" for closed Bezier-curves
@@ -101,17 +179,19 @@ History:
b2 fixing material assignment by LAYER+COLOR
b1 fixing Bezier curves representation of POLYLINEs-arc-segments
b0 added global_scale_presets: "yard/feet/inch to meter"
+
v1.0.10: 2007.10.18 by migius
a6 bugfix CircleDrawCaps for OSX
a5 added two "curve_res" UI-buttons for Bezier curves representation
a5 improved Bezier curves representation of circles/arcs: correct handlers
- a4 first try to fix malformed endpoints of Blender curves of imported ARCs and POLYLINE-arc segments.
- a3 bugfix: open POLYLINEs with end_point.loc==start_point.loc
+ a4 try to fix malformed endpoints of Blender curves of ARC/POLYLINE-arc segments.
+ a3 bugfix: open-POLYLINEs with end_point.loc==start_point.loc
a2 bugfix: f_transform for OCS=(0,0,-1) oriented objects
- a1 added "fill_on" option to draw top and bottom sides of CIRCLEs and ELLIPSEs
+ a1 added "fill_on=caps" option to draw top and bottom sides of CIRCLEs and ELLIPSEs
a1 rewrite f_CIRCLE.Draw: from Mesh.Primitive to Mesh
- a1 bugfix "newScene"-mode: Cylinders/Arcs were drawn at <0,0,0>location
- beta09: 2007.09.02 by migius
+ a1 bugfix "newScene"-mode: all Cylinders/Arcs were drawn at <0,0,0>location
+
+ v1.0.beta09: 2007.09.02 by migius
g5 redesign UI: grouping of buttons
g3 update multi-import-mode: <*.*> button
g- added multi-import-mode: (path/*) for importing many dxf-files at once
@@ -124,7 +204,7 @@ History:
f- added import POLYLINE-arc-segments into Blender-BezierCurves
f- added import POLYLINE-Bezier-curves into Blender-Curves
d5 rewrite: Optimization Levels, added 'directDrawing'
- d4 added: f_set_thick(cntrolled by ini-parameters)
+ d4 added: f_set_thick(controlled by ini-parameters)
d4 bugfix: face-normals in objects with minus thickness
d4 added: placeholder'Empty'-size in f_Insert.draw
d3 rewrite f_Text.Draw: added support for all Text's parameters
@@ -139,23 +219,24 @@ History:
a- added support for 2d-POLYLINE: splines, fitted curves, fitted surfaces
a- redesign f_Drawer for block_definitions
a- rewrite import into Blender-Curve-Object
- beta08: 2007.07.27 by migius
+
+ v1.0.beta08 - 2007.07.27 by migius: "full 3d"-release
l- bugfix: solid_vgroups, clean:scene.objects.new()
l- redesign UI to standard Draw.Register+FileSelector, advanced_config_option
k- bugfix UI:fileSelect() for MacOSX os.listdir()
k- added reset/save/load for config-data
k- redesign keywords/drawTypes/Draw.Create_Buttons
- j- new interface using UIBlock() with own FileSelector, cause Window.FileSelector() too buggy
+ j- new UI using UIBlock() with own FileSelector, cause problem Window.FileSelector()
i- rewritten Class:Settings for better config-parameter management
h- bugfix: face-normals in objects with minus thickness
- h- added Vertex-Groups in polylines and solids generated Meshes, for easier material assignment
+ h- added Vertex-Groups in POLYLINE and SOLID meshes, for easy material assignment
h- beautify code, whitespace->tabs
h- added settings.thic_force switch for forcing thickness
- h- added one Object/Mesh for all simple-entities from the same Layer,
- sorted in Vertex-Groups(color_name) (fewer objects = better import performance)
+ h- added "one Mesh" option for all entities from the same Layer, sorted in<br>
+ Vertex-Groups(color_name) (fewer objects = better import performance)
g- rewrote: insert-point-handle-object is a small tetrahedron
e- bugfix: closed-polymesh3d
- - rewrote: startUI, type_map.keys, f_drawer, for all class_f_draw(added "settings" as attribut)
+ - rewrote: UI, type_map.keys, f_drawer, all class_f_draw(added "settings" as attribut)
- added 2d/3d-support for Polyline_Width incl. angle intersection
beta07: 2007.06.19 by migius
- added 3d-support for LWPolylines
@@ -167,7 +248,7 @@ History:
- added 2d/3d-support for 3d-PolyLine, PolyMesh and PolyFace
- added Global-Scale for size control of imported scenes
beta04: 2007.06.12 by migius
- - rewrote the f_calcBulge for correct import the arc-segments of Polylines
+ - rewrote the f_drawBulge for correct import the arc-segments of Polylines
beta03: 2007.06.10 by migius
- rewrote interface
beta02: 2007.06.09 by migius
@@ -180,13 +261,16 @@ History:
- added 2d+3d-support for Solids and Traces
v0.9 - 2007.01 by kitsu: (for 2.43)
+ - first draft of true POLYLINE import
-
v0.8 - 2006.12 by kitsu:
+ - first draft of object space coordinates OCS import
-
v0.5b - 2006.10 by kitsu: (for 2.42a)
- -
+ - dxfReader.py
+ - color_map.py
"""
@@ -213,9 +297,9 @@ History:
# --------------------------------------------------------------------------
import Blender
-#import bpy
from Blender import *
#from Blender.Mathutils import Vector, Matrix
+import bpy
#import BPyMessages
from dxfReader import readDXF
@@ -239,8 +323,10 @@ except ImportError:
#print 'psyco not imported'
pass
-print '\n\n\n\n'
-print 'Import DXF to Blender *** start ***' #---------------------
+#try: Curve.orderU
+
+print '\n\n\n'
+print 'DXF-Importer v%s *** start ***' %(__version__) #---------------------
SCENE = None
WORLDX = Mathutils.Vector((1,0,0))
@@ -248,10 +334,13 @@ WORLDY = Mathutils.Vector((1,1,0))
WORLDZ = Mathutils.Vector((0,0,1))
G_SCALE = 1.0 #(0.0001-1000) global scaling factor for all dxf data
+G_ORIGIN_X = 0.0 #global translation-vector (x,y,z) in DXF units
+G_ORIGIN_Y = 0.0
+G_ORIGIN_Z = 0.0
MIN_DIST = 0.001 #cut-off value for sort out short-distance polyline-"duoble_vertex"
ARC_RESOLUTION = 64 #(4-500) arc/circle resolution - number of segments
ARC_RADIUS = 1.0 #(0.01-100) arc/circle radius for number of segments algorithm
-CURV_RESOLUTION = 12 #(3-50) Bezier curves resolution
+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
@@ -259,119 +348,232 @@ MIN_WIDTH = MIN_DIST * 10.0 #minimal width by forced width
TRIM_LIMIT = 3.0 #limit for triming of polylines-wide-segments (values:0.0 - 5.0)
ELEVATION = 0.0 #standard elevation = coordinate Z
+BYBLOCK = 0
+BYLAYER = 256
TARGET_LAYER = 3 #target blender_layer
GROUP_BYLAYER = 0 #(0/1) all entities from same layer import into one blender-group
+LAYER_DEF_NAME = 'AAAA' #default layer name
+LAYER_DEF_COLOR = 4 #default layer color
+E_M = 0
+LAB = "*) parts under construction"
+M_OBJ = 0
FILENAME_MAX = 180 #max length of path+file_name string (FILE_MAXDIR + FILE_MAXFILE)
MAX_NAMELENGTH = 17 #max_effective_obnamelength in blender =21=17+(.001)
INIFILE_DEFAULT_NAME = 'importDXF'
INIFILE_EXTENSION = '.ini'
-INIFILE_HEADER = 'ImportDXF.py ver.1.0 config data'
-INFFILE_HEADER = 'ImportDXF.py ver.1.0 analyze of DXF-data'
+INIFILE_HEADER = '#ImportDXF.py ver.1.0 config data'
+INFFILE_HEADER = '#ImportDXF.py ver.1.0 analyze of DXF-data'
AUTO = BezTriple.HandleTypes.AUTO
FREE = BezTriple.HandleTypes.FREE
VECT = BezTriple.HandleTypes.VECT
ALIGN = BezTriple.HandleTypes.ALIGN
-cur_COUNTER = 0 #counter for progress_bar
-"""This module provides wrapper objects for dxf entities.
+class View: #-----------------------------------------------------------------
+ """Class for objects representing dxf VIEWs.
+ """
+ def __init__(self, obj, active=None):
+ """Expects an object of type VIEW as input.
+ """
+ if not obj.type == 'view':
+ raise TypeError, "Wrong type %s for VIEW object!" %obj.type
- The wrappers expect a "dxf object" as input. The dxf object is
- an object with a type and a data attribute. Type is a lowercase
- string matching the 0 code of a dxf entity. Data is a list containing
- dxf objects or lists of [code, data] pairs.
+ self.type = obj.type
+ self.name = obj.get_type(2)[0]
+# self.data = obj.data[:]
- This module is not general, and is only for dxf import.
-"""
-# from Stani's dxf writer v1.1 (c)www.stani.be (GPL)
-#---color values
-BYBLOCK = 0
-BYLAYER = 256
+ self.centerX = getit(obj, 10, 0.0) #view center pointX (in DCS)
+ self.centerY = getit(obj, 20, 0.0) #view center pointY (in DCS)
+ self.height = obj.get_type(40)[0] #view height (in DCS)
+ self.width = obj.get_type(41)[0] #view width (in DCS)
-#---block-type flags (bit coded values, may be combined):
-ANONYMOUS =1 # This is an anonymous block generated by hatching, associative dimensioning, other internal operations, or an application
-NON_CONSTANT_ATTRIBUTES =2 # This block has non-constant attribute definitions (this bit is not set if the block has any attribute definitions that are constant, or has no attribute definitions at all)
-XREF =4 # This block is an external reference (xref)
-XREF_OVERLAY =8 # This block is an xref overlay
-EXTERNAL =16 # This block is externally dependent
-RESOLVED =32 # This is a resolved external reference, or dependent of an external reference (ignored on input)
-REFERENCED =64 # This definition is a referenced external reference (ignored on input)
-
-#---polyline flags
-CLOSED =1 # This is a closed polyline (or a polygon mesh closed in the M direction)
-CURVE_FIT =2 # Curve-fit vertices have been added
-SPLINE_FIT =4 # Spline-fit vertices have been added
-POLYLINE_3D =8 # This is a 3D polyline
-POLYGON_MESH =16 # This is a 3D polygon mesh
-CLOSED_N =32 # The polygon mesh is closed in the N direction
-POLYFACE_MESH =64 # The polyline is a polyface mesh
-CONTINOUS_LINETYPE_PATTERN =128 # The linetype pattern is generated continuously around the vertices of this polyline
-
-#---text flags
-#horizontal
-LEFT = 0
-CENTER = 1
-RIGHT = 2
-ALIGNED = 3 #if vertical alignment = 0
-MIDDLE = 4 #if vertical alignment = 0
-FIT = 5 #if vertical alignment = 0
-#vertical
-BASELINE = 0
-BOTTOM = 1
-MIDDLE = 2
-TOP = 3
-
-#---mtext flags
-#attachment point
-TOP_LEFT = 1
-TOP_CENTER = 2
-TOP_RIGHT = 3
-MIDDLE_LEFT = 4
-MIDDLE_CENTER = 5
-MIDDLE_RIGHT = 6
-BOTTOM_LEFT = 7
-BOTTOM_CENTER = 8
-BOTTOM_RIGHT = 9
-#drawing direction
-LEFT_RIGHT = 1
-TOP_BOTTOM = 3
-BY_STYLE = 5 #the flow direction is inherited from the associated text style
-#line spacing style (optional):
-AT_LEAST = 1 #taller characters will override
-EXACT = 2 #taller characters will not override
+ self.dir = [0,0,0]
+ self.dir[0] = getit(obj, 11, 0.0) #view directionX from target (in WCS)
+ self.dir[1] = getit(obj, 21, 0.0) #
+ self.dir[2] = getit(obj, 31, 0.0) #
+ self.target = [0,0,0]
+ self.target[0] = getit(obj, 12, 0.0) #target pointX(in WCS)
+ self.target[1] = getit(obj, 22, 0.0) #
+ self.target[2] = getit(obj, 32, 0.0) #
+ self.length = obj.get_type(42)[0] #Lens length
+ self.clip_front = getit(obj, 43) #Front clipping plane (offset from target point)
+ self.clip_back = getit(obj, 44) #Back clipping plane (offset from target point)
+ self.twist = obj.get_type(50)[0] #view twist angle in degrees
-class Layer: #-----------------------------------------------------------------
- """Class for objects representing dxf LAYERs.
+ self.flags = getit(obj, 70, 0)
+ self.paperspace = self.flags & 1 #
+
+ self.mode = obj.get_type(71)[0] #view mode (VIEWMODE system variable)
+
+ def __repr__(self):
+ return "%s: name - %s, focus length - %s" %(self.__class__.__name__, self.name, self.length)
+
+
+ def draw(self, settings):
+ """for VIEW: generate Blender_camera.
+ """
+ obname = 'vw_%s' %self.name # create camera object name
+ #obname = 'ca_%s' %self.name # create camera object name
+ obname = obname[:MAX_NAMELENGTH]
+
+ if self.target == [0,0,0] and Mathutils.Vector(self.dir).length == 1.0:
+ cam= Camera.New('ortho', obname)
+ ob= SCENE.objects.new(cam)
+ cam.type = 'ortho'
+ cam.scale = 1.0 # for ortho cameras
+ else:
+ cam= Camera.New('persp', obname)
+ ob= SCENE.objects.new(cam)
+ cam.type = 'persp'
+ cam.angle = 60.0 # for persp cameras
+ if self.length:
+ #cam.angle = 2 * atan(17.5/self.length) * 180/pi
+ cam.lens = self.length #for persp cameras
+ # hack to update Camera>Lens setting (inaccurate as a focal length)
+ #curLens = cam.lens; cam.lens = curLens
+ # AutoCAD gets clip distance from target:
+ dist = Mathutils.Vector(self.dir).length
+ cam.clipEnd = dist - self.clip_back
+ cam.clipStart = dist - self.clip_front
+
+ cam.drawLimits = 1
+ cam.drawSize = 10
+
+ v = Mathutils.Vector(self.dir)
+# print 'deb:view cam:', cam #------------
+# print 'deb:view self.target:', self.target #------------
+# print 'deb:view self.dir:', self.dir #------------
+# print 'deb:view self.twist:', self.twist #------------
+# print 'deb:view self.clip_front=%s, self.clip_back=%s, dist=%s' %(self.clip_front, self.clip_back, dist) #------------
+ transform(v.normalize(), -self.twist, ob)
+ ob.loc = Mathutils.Vector(self.target) + Mathutils.Vector(self.dir)
+ return ob
+
+
+class Vport: #-----------------------------------------------------------------
+ """Class for objects representing dxf VPORTs.
"""
- def __init__(self, obj, name=None, color=None, frozen=None):
- """Expects an object of type layer as input.
+ def __init__(self, obj, active=None):
+ """Expects an object of type VPORT as input.
"""
+ if not obj.type == 'vport':
+ raise TypeError, "Wrong type %s for VPORT object!" %obj.type
+
self.type = obj.type
- self.data = obj.data[:]
+ self.name = obj.get_type(2)[0]
+# self.data = obj.data[:]
+ #print 'deb:vport name, data:', self.name #-------
+ #print 'deb:vport data:', self.data #-------
+
+ self.height = obj.get_type(40)[0] #vport height (in DCS)
+ self.centerX = getit(obj, 12, 0.0) #vport center pointX (in DCS)
+ self.centerY = getit(obj, 22, 0.0) #vport center pointY (in DCS)
+ self.width = self.height * obj.get_type(41)[0] #vport aspect ratio - width (in DCS)
+
+ self.dir = [0,0,0]
+ self.dir[0] = getit(obj, 16, 0.0) #vport directionX from target (in WCS)
+ self.dir[1] = getit(obj, 26, 0.0) #
+ self.dir[2] = getit(obj, 36, 0.0) #
+
+ self.target = [0,0,0]
+ self.target[0] = getit(obj, 17, 0.0) #target pointX(in WCS)
+ self.target[1] = getit(obj, 27, 0.0) #
+ self.target[2] = getit(obj, 37, 0.0) #
+
+ self.length = obj.get_type(42)[0] #Lens length
+ self.clip_front = getit(obj, 43) #Front clipping plane (offset from target point)
+ self.clip_back = getit(obj, 44) #Back clipping plane (offset from target point)
+ self.twist = obj.get_type(51)[0] #view twist angle
- if name:
- self.name = name
- #self.bfname = name #--todo---see layernamesmap in f_getLayersmap ---
- else:
- self.name = obj.get_type(2)[0] #layer name of object
+ self.flags = getit(obj, 70, 0)
+ self.paperspace = self.flags & 1 #
- if color:
- self.color = color
- else:
- self.color = obj.get_type(62)[0] #color of object
+ self.mode = obj.get_type(71)[0] #view mode (VIEWMODE system variable)
- if frozen:
- self.frozen = frozen
+ def __repr__(self):
+ return "%s: name - %s, focus length - %s" %(self.__class__.__name__, self.name, self.length)
+
+ def draw(self, settings):
+ """for VPORT: generate Blender_camera.
+ """
+ obname = 'vp_%s' %self.name # create camera object name
+ #obname = 'ca_%s' %self.name # create camera object name
+ obname = obname[:MAX_NAMELENGTH]
+
+ if self.target == [0,0,0] and Mathutils.Vector(self.dir).length == 1.0:
+ cam= Camera.New('ortho', obname)
+ ob= SCENE.objects.new(cam)
+ cam.type = 'ortho'
+ cam.scale = 1.0 # for ortho cameras
else:
- self.flags = obj.get_type(70)[0]
- self.frozen = self.flags & 1
+ cam= Camera.New('persp', obname)
+ ob= SCENE.objects.new(cam)
+ cam.type = 'persp'
+ cam.angle = 60.0 # for persp cameras
+ if self.length:
+ #cam.angle = 2 * atan(17.5/self.length) * 180/pi
+ cam.lens = self.length #for persp cameras
+ # hack to update Camera>Lens setting (inaccurate as a focal length)
+ #curLens = cam.lens; cam.lens = curLens
+ # AutoCAD gets clip distance from target:
+ dist = Mathutils.Vector(self.dir).length
+ cam.clipEnd = dist - self.clip_back
+ cam.clipStart = dist - self.clip_front
+
+ cam.drawLimits = 1
+ cam.drawSize = 10
+
+ v = Mathutils.Vector(self.dir)
+# print 'deb:view cam:', cam #------------
+# print 'deb:view self.target:', self.target #------------
+# print 'deb:view self.dir:', self.dir #------------
+# print 'deb:view self.twist:', self.twist #------------
+# print 'deb:view self.clip_front=%s, self.clip_back=%s, dist=%s' %(self.clip_front, self.clip_back, dist) #------------
+ transform(v.normalize(), -self.twist, ob)
+ ob.loc = Mathutils.Vector(self.target) + Mathutils.Vector(self.dir)
+ return ob
+
+class Layer: #-----------------------------------------------------------------
+ """Class for objects representing dxf LAYERs.
+ """
+ def __init__(self, obj, name=None, color=None, frozen=None):
+ """Expects an dxfobject of type layer as input.
+ if no dxfobject - creates surogate layer with default parameters
+ """
+
+ if obj==None:
+ self.type = 'layer'
+ if name: self.name = name
+ else: self.name = LAYER_DEF_NAME
+
+ if color: self.color = color
+ else: self.color = LAYER_DEF_COLOR
+
+ if frozen!=None: self.frozen = frozen
+ else: self.frozen = 0
+ else:
+ if obj.type=='layer':
+ self.type = obj.type
+ #self.data = obj.data[:]
+ if name: self.name = name
+ #self.bfname = name #--todo---see layernamesmap in f_getLayersmap ---
+ else: self.name = obj.get_type(2)[0] #layer name of object
+
+ if color: self.color = color
+ else: self.color = obj.get_type(62)[0] #color of object
+
+ if frozen!=None: self.frozen = frozen
+ else:
+ self.flags = obj.get_type(70)[0]
+ self.frozen = self.flags & 1
+
def __repr__(self):
return "%s: name - %s, color - %s" %(self.__class__.__name__, self.name, self.color)
@@ -415,6 +617,14 @@ def get_extrusion(data): #-------------------------------------------------
return vec
+#------------------------------------------
+def getSceneChild(name):
+ dudu = [i for i in SCENE.objects if i.name==name]
+# dudu = [i for i in SCENE.getChildren() if i.name==name]
+ #print 'deb:getSceneChild %s -result: %s:' %(name,dudu) #-----------------
+ if dudu!=[]: return dudu[0]
+ return None
+
class Solid: #-----------------------------------------------------------------
"""Class for objects representing dxf SOLID or TRACE.
@@ -426,16 +636,17 @@ class Solid: #-----------------------------------------------------------------
obj.type = 'solid'
if not obj.type == 'solid':
raise TypeError, "Wrong type \'%s\' for solid/trace object!" %obj.type
+
self.type = obj.type
- self.data = obj.data[:]
+# self.data = obj.data[:]
self.space = getit(obj, 67, 0)
self.thic = getit(obj, 39, 0)
self.color_index = getit(obj, 62, BYLAYER)
- self.layer = getit(obj.data, 8, None)
- self.extrusion = get_extrusion(obj.data)
- self.points = self.get_points(obj.data)
+ self.layer = getit(obj, 8, None)
+ self.extrusion = get_extrusion(obj)
+ self.points = self.get_points(obj)
@@ -516,16 +727,16 @@ class Solid: #-----------------------------------------------------------------
if l == 4: faces = [[0,1,3,2]]
elif l == 3: faces = [[0,1,2]]
elif l == 2: edges = [[0,1]]
-
-
-
- me = Mesh.New(obname) # create a new mesh
+
+ if M_OBJ: obname, me, ob = makeNewObject()
+ else:
+ me = Mesh.New(obname) # create a new mesh
+ ob = SCENE.objects.new(me) # create a new mesh_object
me.verts.extend(points) # add vertices to mesh
if faces: me.faces.extend(faces) # add faces to the mesh
if edges: me.edges.extend(edges) # add faces to the mesh
- ob = SCENE.objects.new(me) # create a new mesh_object
- if settings.var['vGroup_on']:
+ if settings.var['vGroup_on'] and not M_OBJ:
# each MeshSide becomes vertexGroup for easier material assignment ---------------------
replace = Blender.Mesh.AssignModes.ADD #or .AssignModes.ADD/REPLACE
if vg_left: me.addVertGroup('side.left') ; me.assignVertsToGroup('side.left', vg_left, 1.0, replace)
@@ -539,9 +750,6 @@ class Solid: #-----------------------------------------------------------------
return ob
-
-
-
class Line: #-----------------------------------------------------------------
"""Class for objects representing dxf LINEs.
"""
@@ -551,16 +759,16 @@ class Line: #-----------------------------------------------------------------
if not obj.type == 'line':
raise TypeError, "Wrong type \'%s\' for line object!" %obj.type
self.type = obj.type
- self.data = obj.data[:]
+# self.data = obj.data[:]
self.space = getit(obj, 67, 0)
self.thic = getit(obj, 39, 0)
#print 'deb:self.thic: ', self.thic #---------------------
self.color_index = getit(obj, 62, BYLAYER)
- self.layer = getit(obj.data, 8, None)
- self.extrusion = get_extrusion(obj.data)
- self.points = self.get_points(obj.data)
+ self.layer = getit(obj, 8, None)
+ self.extrusion = get_extrusion(obj)
+ self.points = self.get_points(obj)
def get_points(self, data):
@@ -597,10 +805,10 @@ class Line: #-----------------------------------------------------------------
if settings.var['lines_as'] == 4: # as thin_box
thic = settings.var['thick_min']
width = settings.var['width_min']
- if settings.var['lines_as'] == 3: # as thin cylinder
+ elif settings.var['lines_as'] == 3: # as thin cylinder
cyl_rad = 0.5 * settings.var['width_min']
- if settings.var['curves_on']: # LINE curve representation-------------------------
+ elif settings.var['lines_as'] == 5: # LINE curve representation-------------------------
obname = 'li_%s' %self.layer # create object name from layer name
obname = obname[:MAX_NAMELENGTH]
@@ -610,6 +818,7 @@ class Line: #-----------------------------------------------------------------
for point in curve:
point.handleTypes = [VECT, VECT]
curve.flagU = 0 # 0 sets the curve not cyclic=open
+ c.setResolu(settings.var['curve_res'])
c.update() #important for handles calculation
ob = SCENE.objects.new(c) # create a new curve_object
@@ -633,20 +842,23 @@ class Line: #-----------------------------------------------------------------
global activObjectName
#print 'deb:draw:line.ob IN activObjectName: ', activObjectName #---------------------
- if activObjectLayer == self.layer and settings.var['one_mesh_on']:
- obname = activObjectName
- #print 'deb:line.draw obname from activObjectName: ', obname #---------------------
- ob = Object.Get(obname) # open an existing mesh_object
- #ob = SCENE.getChildren(obname) # open an existing mesh_object
- me = Mesh.Get(ob.name) # open objects mesh data
- else:
- obname = 'li_%s' %self.layer # create object name from layer name
- obname = obname[:MAX_NAMELENGTH]
- me = Mesh.New(obname) # create a new mesh
- ob = SCENE.objects.new(me) # create a new mesh_object
- activObjectName = ob.name
- activObjectLayer = self.layer
- #print ('deb:line.draw new line.ob+mesh:"%s" created!' %ob.name) #---------------------
+ if M_OBJ: obname, me, ob = makeNewObject()
+ else:
+ if activObjectLayer == self.layer and settings.var['one_mesh_on']:
+ obname = activObjectName
+ #print 'deb:line.draw obname from activObjectName: ', obname #---------------------
+ ob = getSceneChild(obname) # open an existing mesh_object
+ #ob = SCENE.getChildren(obname) # open an existing mesh_object
+ #me = Mesh.Get(ob.name) # open objects mesh data
+ me = ob.getData(name_only=False, mesh=True)
+ else:
+ obname = 'li_%s' %self.layer # create object name from layer name
+ obname = obname[:MAX_NAMELENGTH]
+ me = Mesh.New(obname) # create a new mesh
+ ob = SCENE.objects.new(me) # create a new mesh_object
+ activObjectName = ob.name
+ activObjectLayer = self.layer
+ #print ('deb:line.draw new line.ob+mesh:"%s" created!' %ob.name) #---------------------
faces, edges = [], []
n = len(me.verts)
@@ -665,7 +877,7 @@ class Line: #-----------------------------------------------------------------
if faces: me.faces.extend(faces) # add faces to the mesh
if edges: me.edges.extend(edges) # add faces to the mesh
- if settings.var['vGroup_on']:
+ if settings.var['vGroup_on'] and not M_OBJ:
# entities with the same color build one vertexGroup for easier material assignment ----
ob.link(me) # link mesh to that object
vG_name = 'color_%s' %self.color_index
@@ -694,16 +906,16 @@ class Point: #-----------------------------------------------------------------
if not obj.type == 'point':
raise TypeError, "Wrong type %s for point object!" %obj.type
self.type = obj.type
- self.data = obj.data[:]
+# self.data = obj.data[:]
self.space = getit(obj, 67, 0)
self.thic = getit(obj, 39, 0)
#print 'deb:self.thic: ', self.thic #---------------------
self.color_index = getit(obj, 62, BYLAYER)
- self.layer = getit(obj.data, 8, None)
- self.extrusion = get_extrusion(obj.data)
- self.points = self.get_points(obj.data)
+ self.layer = getit(obj, 8, None)
+ self.extrusion = get_extrusion(obj)
+ self.points = self.get_points(obj)
def get_points(self, data):
@@ -733,13 +945,13 @@ class Point: #-----------------------------------------------------------------
thic = settings.var['thick_min']
if thic < settings.var['dist_min']: thic = settings.var['dist_min']
- if points_as in [1,3,4]:
- if points_as == 1: # as 'empty'
+ if points_as in [1,3,4,5]:
+ if True: # points_as in [1,5]: # as 'empty'
c = 'Empty'
- if points_as == 3: # as 'thin sphere'
+ elif points_as == 3: # as 'thin sphere'
res = settings.var['thin_res']
c = Mesh.Primitives.UVsphere(res,res,thic)
- if points_as == 4: # as 'thin box'
+ elif points_as == 4: # as 'thin box'
c = Mesh.Primitives.Cube(thic)
ob = SCENE.objects.new(c, obname) # create a new object
transform(self.extrusion, 0, ob)
@@ -749,156 +961,23 @@ class Point: #-----------------------------------------------------------------
global activObjectLayer
global activObjectName
#print 'deb:draw:point.ob IN activObjectName: ', activObjectName #---------------------
- if activObjectLayer == self.layer and settings.var['one_mesh_on']:
- obname = activObjectName
- #print 'deb:draw:point.ob obname from activObjectName: ', obname #---------------------
- ob = Object.Get(obname) # open an existing mesh_object
- #ob = SCENE.getChildren(obname) # open an existing mesh_object
- me = Mesh.Get(ob.name) # open objects mesh data
- else:
- me = Mesh.New(obname) # create a new mesh
- ob = SCENE.objects.new(me) # create a new mesh_object
- activObjectName = ob.name
- activObjectLayer = self.layer
- #print ('deb:draw:point new point.ob+mesh:"%s" created!' %ob.name) #---------------------
- me.verts.extend(points) # add vertices to mesh
-
- return ob
-
-
-
-
-class LWpolyline: #-----------------------------------------------------------------
- """Class for objects representing dxf LWPOLYLINEs.
- """
- def __init__(self, obj):
- """Expects an entity object of type lwpolyline as input.
- """
- #print 'deb:LWpolyline.START:----------------' #------------------------
- if not obj.type == 'lwpolyline':
- raise TypeError, "Wrong type %s for polyline object!" %obj.type
- self.type = obj.type
- self.data = obj.data[:]
-
- # required data
- self.num_points = obj.get_type(90)[0]
-
- # optional data (with defaults)
- self.space = getit(obj, 67, 0)
-
- self.color_index = getit(obj, 62, BYLAYER)
-
- self.elevation = getit(obj, 30, 0)
- self.thic = getit(obj, 39, 0)
- self.flags = getit(obj, 70, 0)
-
- self.closed = self.flags&1 # byte coded, 1 = closed, 128 = plinegen
-
- self.layer = getit(obj.data, 8, None)
- self.points = self.get_points(obj.data)
- self.extrusion = get_extrusion(obj.data)
-
- #print 'deb:LWpolyline.obj.data:\n', obj.data #------------------------
- #print 'deb:LWpolyline.ENDinit:----------------' #------------------------
-
-
- def get_points(self, data):
- """Gets points for a polyline type object.
-
- LW-Polylines have no fixed number of verts, and
- each vert can have a number of properties.
- Verts should be coded as
- 10:xvalue
- 20:yvalue
- 40:startwidth or 0
- 41:endwidth or 0
- 42:bulge or 0
- for each vert
- """
- num = self.num_points
- point = None
- points = []
- for item in data:
- if item[0] == 10: # 10 = x
- if point:
- points.append(point)
- point = Vertex()
- point.x = item[1]
- elif item[0] == 20: # 20 = y
- point.y = item[1]
- elif item[0] == 40: # 40 = start width
- point.swidth = item[1]
- elif item[0] == 41: # 41 = end width
- point.ewidth = item[1]
- elif item[0] == 42: # 42 = bulge
- point.bulge = item[1]
- points.append(point)
- return points
-
-
-
- def __repr__(self):
- return "%s: layer - %s, points - %s" %(self.__class__.__name__, self.layer, self.points)
-
-
- def draw(self, settings):
- """for LWPOLYLINE: generate Blender_geometry.
- """
- #print 'deb:LWpolyline.draw.START:----------------' #------------------------
- points = []
- obname = 'lw_%s' %self.layer # create object name from layer name
- obname = obname[:MAX_NAMELENGTH]
- #settings.var['curves_on'] == True
- #print 'deb:index_len: ', len(self.points) #------------------
- for i, point in enumerate(self.points):
- #print 'deb:index: ', i #------------------
- if not point.bulge:
- points.append(point.loc)
- elif point.bulge and not self.closed and i == len(self.points)-1:
- points.append(point.loc)
- elif point.bulge: #
- if i == len(self.points)-1:
- point2 = self.points[0]
+ if M_OBJ: obname, me, ob = makeNewObject()
+ else:
+ if activObjectLayer == self.layer and settings.var['one_mesh_on']:
+ obname = activObjectName
+ #print 'deb:draw:point.ob obname from activObjectName: ', obname #---------------------
+ ob = getSceneChild(obname) # open an existing mesh_object
+ #ob = SCENE.getChildren(obname) # open an existing mesh_object
+ me = ob.getData(name_only=False, mesh=True)
+ #me = Mesh.Get(ob.name) # open objects mesh data
else:
- point2 = self.points[i+1]
- arc_res = settings.var['arc_res']/sqrt(settings.var['arc_rad'])
- verts, center = calcBulge(point, point2, arc_res)
-# if i == len(self.points)-1:
-# if self.closed:
-# verts.pop() #remove last(=first) vertex
-# else:
-# verts.pop() #remove last vertex, because this point will be writen as the next vertex
- points.extend(verts)
-
- thic = self.thic
- if settings.var['thick_force'] and thic == 0: thic = settings.var['thick_min']
- if settings.var['thick_on'] and thic != 0:
- len1 = len(points)
- points.extend([[point[0], point[1], point[2]+thic] for point in points])
- faces = []
- #print 'deb:len1:', len1 #-----------------------
- faces = [[num, num+1, num+len1+1, num+len1] for num in xrange(len1 - 1)]
- if self.closed:
- faces.append([len1-1, 0, len1, 2*len1-1])
- #print 'deb:faces_list:\n', faces #-----------------------
- me = Mesh.New(obname) # create a new mesh
- ob = SCENE.objects.new(me) # create a new mesh_object
+ me = Mesh.New(obname) # create a new mesh
+ ob = SCENE.objects.new(me) # create a new mesh_object
+ activObjectName = ob.name
+ activObjectLayer = self.layer
+ #print ('deb:draw:point new point.ob+mesh:"%s" created!' %ob.name) #---------------------
me.verts.extend(points) # add vertices to mesh
- me.faces.extend(faces) # add faces to the mesh
- else:
- edges = [[num, num+1] for num in xrange(len(points)-1)]
- if self.closed:
- edges.append([len(points)-1, 0])
- #print 'deb:edges_list:\n', edges #-----------------------
- me = Mesh.New(obname) # create a new mesh
- ob = SCENE.objects.new(me) # create a new mesh_object
- me.verts.extend(points) # add vertices to mesh
- me.edges.extend(edges) # add edges to the mesh
- ob.LocZ = self.elevation
- transform(self.extrusion, 0, ob)
-
- #print 'deb:LWpolyline.draw.END:----------------' #------------------------
return ob
@@ -913,11 +992,8 @@ class Polyline: #--------------------------------------------------------------
if not obj.type == 'polyline':
raise TypeError, "Wrong type %s for polyline object!" %obj.type
self.type = obj.type
- self.data = obj.data[:]
- #print 'deb:polyline.obj.data[:]:\n', obj.data[:] #------------------------
- self.points = []
+# self.data = obj.data[:]
- # optional data (with defaults)
self.space = getit(obj, 67, 0)
self.elevation = getit(obj, 30, 0)
#print 'deb:elevation: ', self.elevation #---------------
@@ -927,17 +1003,17 @@ class Polyline: #--------------------------------------------------------------
self.flags = getit(obj, 70, 0)
self.closed = self.flags & 1 # closed in the M direction
self.curved = self.flags & 2 # Bezier-curve-fit vertices have been added
- self.spline = self.flags & 4 # Bspline-fit vertices have been added
+ self.spline = self.flags & 4 # NURBS-curve-fit vertices have been added
self.poly3d = self.flags & 8 # 3D-polyline
self.plmesh = self.flags & 16 # 3D-polygon mesh
self.closeN = self.flags & 32 # closed in the N direction
self.plface = self.flags & 64 # 3D-polyface mesh
self.contin = self.flags & 128 # the linetype pattern is generated continuously
- if self.poly3d or self.plface or self.plmesh:
- self.poly2d = False # its not a 2D-polyline
- else:
- self.poly2d = True # it is a 2D-polyline
+ self.pltype='poly2d' # default is a 2D-polyline
+ if self.poly3d: self.pltype='poly3d'
+ elif self.plface: self.pltype='plface'
+ elif self.plmesh: self.pltype='plmesh'
self.swidth = getit(obj, 40, 0) # default start width
self.ewidth = getit(obj, 41, 0) # default end width
@@ -946,18 +1022,18 @@ class Polyline: #--------------------------------------------------------------
self.vectorsN = getit(obj, 72, None) # PolyMesh: expansion in M-direction / PolyFace: number of faces
#self.resolM = getit(obj, 73, None) # resolution of surface in M direction
#self.resolN = getit(obj, 74, None) # resolution of surface in N direction
- self.curvetyp = getit(obj, 75, 0) # type of curve/surface: 0=None/5=Quadric/6=Cubic/8=Bezier
- self.curvNormal = False
- self.curvQBspline = False
- self.curvCBspline = False
+ self.curvNoFitted = False
+ self.curvQuadrati = False
+ self.curvCubicBsp = False
self.curvBezier = False
- if self.curvetyp == 0: self.curvNormal = True
- elif self.curvetyp == 5: self.curvQBspline = True
- elif self.curvetyp == 6: self.curvCBspline = True
- elif self.curvetyp == 8: self.curvBezier = True
+ curvetype = getit(obj, 75, 0) # type of curve/surface: 0=None/5=Quadric/6=Cubic/8=Bezier
+ if curvetype == 0: self.curvNoFitted = True
+ elif curvetype == 5: self.curvQuadrati = True
+ elif curvetype == 6: self.curvCubicBsp = True
+ elif curvetype == 8: self.curvBezier = True
- self.layer = getit(obj.data, 8, None)
- self.extrusion = get_extrusion(obj.data)
+ self.layer = getit(obj, 8, None)
+ self.extrusion = get_extrusion(obj)
self.points = [] #list with vertices coordinats
self.faces = [] #list with vertices assigment to faces
@@ -970,29 +1046,100 @@ class Polyline: #--------------------------------------------------------------
+ def doubles_out(self, settings, d_points):
+ """routine to sort out of double.vertices-----------------------------
+ """
+ minimal_dist = settings.var['dist_min'] * 0.1
+ dv_count = 0
+ temp_points = []
+ for i in xrange(len(d_points)-1):
+ point = d_points[i]
+ point2 = d_points[i+1]
+ #print 'deb:double.vertex p1,p2', point, point2 #------------------------
+ delta = Mathutils.Vector(point2.loc) - Mathutils.Vector(point.loc)
+ if delta.length > minimal_dist:
+ temp_points.append(point)
+ else:
+ dv_count+=1
+ #print 'deb:drawPoly2d double.vertex sort out! count=', dv_count #------------------------
+ temp_points.append(d_points[-1]) #------ incl. last vertex -------------
+ #if self.closed: temp_points.append(d_points[1]) #------ loop start vertex -------------
+ d_points = temp_points #-----vertex.list without "double.vertices"
+ #print 'deb:drawPoly2d d_pointsList =after DV-outsorting=====:\n ', d_points #------------------------
+ return d_points
+
+
+ def tribles_out(self, settings, d_points):
+ """routine to sort out of three_in_place.vertices-----------------------------
+ """
+ minimal_dist = settings.var['dist_min'] * 0.1
+ dv_count = 0
+ temp_points = []
+ for i in xrange(len(d_points)-2):
+ point1 = d_points[i]
+ point2 = d_points[i+1]
+ point3 = d_points[i+2]
+ #print 'deb:double.vertex p1,p2', point, point2 #------------------------
+ delta12 = Mathutils.Vector(point2.loc) - Mathutils.Vector(point1.loc)
+ delta23 = Mathutils.Vector(point3.loc) - Mathutils.Vector(point2.loc)
+ if delta12.length < minimal_dist and delta23.length < minimal_dist:
+ dv_count+=1
+ else:
+ temp_points.append(point1)
+ #print 'deb:drawPoly2d double.vertex sort out! count=', dv_count #------------------------
+ point1 = d_points[-2]
+ point2 = d_points[-1]
+ delta12 = Mathutils.Vector(point2.loc) - Mathutils.Vector(point1.loc)
+ if delta12.length > minimal_dist:
+ temp_points.append(d_points[-2]) #------ incl. 2last vertex -------------
+ temp_points.append(d_points[-1]) #------ incl. 1last vertex -------------
+ #if self.closed: temp_points.append(d_points[1]) #------ loop start vertex -------------
+ d_points = temp_points #-----vertex.list without "double.vertices"
+ #print 'deb:drawPoly2d d_pointsList =after DV-outsorting=====:\n ', d_points #------------------------
+ return d_points
+
+
def draw(self, settings): #-------------%%%% DRAW POLYLINE %%%---------------
"""for POLYLINE: generate Blender_geometry.
"""
+ #print 'deb:drawPOLYLINE.START:----------------' #------------------------
+ #print 'deb:POLYLINEdraw self.pltype:', self.pltype #------------------------
+ #print 'deb:POLYLINEdraw self.points:\n', self.points #------------------------
ob = []
- if self.plface: #---- 3dPolyFace - mesh with free topology
+ #---- 3dPolyFace - mesh with free topology
+ if self.pltype=='plface' and settings.drawTypes['plmesh']:
ob = self.drawPlFace(settings)
- elif self.plmesh: #---- 3dPolyMesh - mesh with ortogonal topology
+ #---- 3dPolyMesh - mesh with ortogonal topology
+ elif self.pltype=='plmesh' and settings.drawTypes['plmesh']:
ob = self.drawPlMesh(settings)
+
#---- 2dPolyline - plane polyline with arc/wide/thic segments
+ elif self.pltype=='poly2d' and settings.drawTypes['polyline']:
+ if settings.var['plines_as'] in [5,6]: # and self.spline:
+ ob = self.drawPolyCurve(settings)
+ else:
+ ob = self.drawPoly2d(settings)
+
#---- 3dPolyline - non-plane polyline (thin segments = without arc/wide/thic)
- elif self.poly2d or self.poly3d:
- if settings.var['curves_on']: # and self.spline:
+ elif self.pltype=='poly3d' and settings.drawTypes['pline3']:
+ if settings.var['plines3_as'] in [5,6]: # and self.spline:
ob = self.drawPolyCurve(settings)
else:
ob = self.drawPoly2d(settings)
- return ob
+ #---- Spline - curved polyline (thin segments = without arc/wide/thic)
+ elif self.pltype=='spline' and settings.drawTypes['spline']:
+ if settings.var['splines_as'] in [5,6]:
+ ob = self.drawPolyCurve(settings)
+ else:
+ ob = self.drawPoly2d(settings)
+ return ob
def drawPlFace(self, settings): #---- 3dPolyFace - mesh with free topology
"""Generate the geometery of polyface.
"""
- #print 'deb:polyface.draw.START:----------------' #------------------------
+ #print 'deb:drawPlFace.START:----------------' #------------------------
points = []
faces = []
#print 'deb:len of pointsList ====== ', len(self.points) #------------------------
@@ -1002,23 +1149,33 @@ class Polyline: #--------------------------------------------------------------
else:
points.append(point.loc)
+ if settings.var['plmesh_flip']: # ----------------------
+ for face in faces:
+ face.reverse()
+ face = [face[-1]] + face[:-1]
- #print 'deb:len of points_list:\n', len(points) #-----------------------
- #print 'deb:points_list:\n', points #-----------------------
- #print 'deb:faces_list:\n', faces #-----------------------
+ #print 'deb:drawPlFace: len of points_list:\n', len(points) #-----------------------
+ #print 'deb:drawPlFace: len of faces_list:\n', len(faces) #-----------------------
+ #print 'deb:drawPlFace: points_list:\n', points #-----------------------
+ #print 'deb:drawPlFace: faces_list:\n', faces #-----------------------
obname = 'pf_%s' %self.layer # create object name from layer name
obname = obname[:MAX_NAMELENGTH]
me = Mesh.New(obname) # create a new mesh
ob = SCENE.objects.new(me) # create a new mesh_object
me.verts.extend(points) # add vertices to mesh
me.faces.extend(faces) # add faces to the mesh
+ if settings.var['normals_out']: # ----------------------
+ #me.flipNormals()
+ me.recalcNormals(0)
+ #me.update()
+ #print 'deb:drawPlFace: len of me.faces:\n', len(me.faces) #-----------------------
if settings.var['meshSmooth_on']: # ----------------------
- for i in xrange(len(faces)):
+ for i in xrange(len(me.faces)):
me.faces[i].smooth = True
#me.Mode(AUTOSMOOTH)
transform(self.extrusion, 0, ob)
- #print 'deb:polyface.draw.END:----------------' #------------------------
+ #print 'deb:drawPlFace.END:----------------' #------------------------
return ob
@@ -1058,7 +1215,10 @@ class Polyline: #--------------------------------------------------------------
ob = SCENE.objects.new(me) # create a new mesh_object
me.verts.extend([point.loc for point in self.points]) # add vertices to mesh
me.faces.extend(faces) # add faces to the mesh
-
+ if settings.var['normals_out']: # ----------------------
+ #me.flipNormals()
+ me.recalcNormals(0)
+ #me.update()
if settings.var['meshSmooth_on']: # ----------------------
for i in xrange(len(faces)):
me.faces[i].smooth = True
@@ -1077,9 +1237,9 @@ class Polyline: #--------------------------------------------------------------
#print 'deb:drawPoly2d exit, cause POLYLINE has less than 2 vertices' #---------
return
- if self.spline: pline_typ = 'ps' # Polyline-nurbSpline
- elif self.curved: pline_typ = 'pc' # Polyline-bezierCurve
- else: pline_typ = 'pl' # Polyline
+ if self.spline: pline_typ = 'ps' # Polyline-NURBSpline
+ elif self.curved: pline_typ = 'pc' # Polyline-BezierCurve
+ else: pline_typ = 'pl' # Polyline classic
obname = '%s_%s' %(pline_typ, self.layer) # create object_name from layer name
obname = obname[:MAX_NAMELENGTH]
d_points = []
@@ -1095,6 +1255,10 @@ class Polyline: #--------------------------------------------------------------
point.loc[2] = self.elevation
d_points.append(point)
+ #d_points = self.tribles_out(settings, d_points)
+ #d_points = self.doubles_out(settings, d_points)
+ #print 'deb:drawPolyCurve d_pointsList =after DV-outsorting=====:\n ', d_points #------------------------
+
thic = set_thick(self.thic, settings)
if thic != 0.0: #hack: Blender<2.45 curve-extrusion
LocZ = d_points[0].loc[2]
@@ -1108,26 +1272,14 @@ class Polyline: #--------------------------------------------------------------
pline = Curve.New(obname) # create new curve data
#pline.setResolu(24) #--todo-----
- if False: #self.spline: # NURBSplines-----FAKE(with Bezier)-----
- #print 'deb:polyline2dCurve.draw self.spline!' #---------------
- curve = pline.appendNurb(BezTriple.New(d_points[0]))
- for p in d_points[1:]:
- curve.append(BezTriple.New(p))
- for point in curve:
- point.handleTypes = [AUTO, AUTO]
- if self.closed:
- curve.flagU = 1 # Set curve cyclic=close
- else:
- curve.flagU = 0 # Set curve not cyclic=open
- curve[0].handleTypes = [FREE, ALIGN] #remi--todo-----
- curve[-1].handleTypes = [ALIGN, FREE] #remi--todo-----
-
- elif self.spline: # NURBSplines-----OK-----
+ if False: #old self.spline: # NURBSplines-----OK-----
#print 'deb:polyline2dCurve.draw self.spline!' #---------------
weight1 = 0.5
weight2 = 1.0
- # generate middlepoints except start/end-segments ---
- if self.curvQBspline:
+ if self.curvQuadrati:
+ # Bezier-curve form simulated in NURBS-curve
+ # generate middlepoints except start/end-segments ---
+ #print 'deb:polyline2dCurve.draw extraQBspline!' #---------------
temp_points = []
point = d_points[0].loc
point.append(weight1)
@@ -1180,7 +1332,27 @@ class Polyline: #--------------------------------------------------------------
else:
curve.flagU = 0 # Set curve not cyclic=open
- elif self.curved: #--Bezier-curves---OK-------
+ if self.spline: # NURBSplines-----OK-----
+ #print 'deb:polyline2dCurve.draw self.spline!' #---------------
+ nurbs_points = []
+ for d in d_points:
+ pkt = d.loc
+ pkt.append(d.weight)
+ nurbs_points.append(pkt)
+ firstpoint = nurbs_points[0]
+ curve = pline.appendNurb(firstpoint)
+ curve.setType(4) # set curvetype NURBS
+ for point in nurbs_points[1:]:
+ curve.append(point)
+ if self.closed:
+ curve.flagU = 1+0 # Set curve cyclic=close and uni
+ else:
+ curve.flagU = 0+2 # Set curve not cyclic=open
+ try: curve.orderU = 5 # works only with >2.46svn080625
+ except AttributeError: pass
+ #print 'deb: dir(curve):', dir(curve) #----------------
+
+ elif False: #orig self.curved: #--Bezier-curves---OK-------
#print 'deb:polyline2dCurve.draw self.curved!' #---------------
curve = pline.appendNurb(BezTriple.New(d_points[0]))
for p in d_points[1:]:
@@ -1194,7 +1366,45 @@ class Polyline: #--------------------------------------------------------------
curve[0].handleTypes = [FREE, ALIGN] #remi--todo-----
curve[-1].handleTypes = [ALIGN, FREE] #remi--todo-----
- else: #--straight line- and arc-segments----OK------
+ elif self.curved: #--SPLINE as Bezier-curves---wip------
+ #print 'deb:polyline2dCurve.draw self.curved!' #---------------
+ begtangent, endtangent = None, None
+ if d_points[0].tangent:
+ begtangent = d_points[0]
+ d_points = d_points[1:]
+ if d_points[-1].tangent:
+ endtangent = d_points[-1]
+ d_points = d_points[:-1]
+ curve = pline.appendNurb(BezTriple.New(d_points[0]))
+ for p in d_points[1:]:
+ curve.append(BezTriple.New(p))
+ for point in curve:
+ point.handleTypes = [AUTO, AUTO]
+ #curve.setType(1) #Bezier curve
+ if self.closed:
+ curve.flagU = 5 #1 # Set curve cyclic=close
+ else:
+ curve.flagU = 4 #0 # Set curve not cyclic=open
+ if begtangent:
+ #print 'deb:polyline2dCurve.draw curve[0].vec:', curve[0].vec #-----
+ #print 'deb:polyline2dCurve.draw begtangent:', begtangent #-----
+ p0h1,p0,p0h2 = curve[0].vec
+ p0h1 = [p0h1[i]+begtangent[i] for i in range(3)]
+ curve.__setitem__(0,BezTriple.New(p0h1+p0+p0h2))
+ curve[0].handleTypes = [FREE, ALIGN] #remi--todo-----
+ if endtangent:
+ #print 'deb:polyline2dCurve.draw curve[-1].vec:', curve[-1].vec #-----
+ #print 'deb:polyline2dCurve.draw endtangent:', endtangent #-----
+ p0h1,p0,p0h2 = curve[-1].vec
+ p0h2 = [p0h2[i]+endtangent[i] for i in range(3)]
+ #print 'deb:drawPlineCurve: p0h2:', p0h2 #----------
+ curve.__setitem__(-1,BezTriple.New(p0h1+p0+p0h2))
+ #print 'deb:polyline2dCurve.draw curve[-1].vec:', curve[-1].vec #-----
+ curve[-1].handleTypes = [ALIGN, FREE] #remi--todo-----
+
+
+
+ else: #-- only straight line- and arc-segments----OK------
#print 'deb:polyline2dCurve.draw curve:', curve #-----
points = []
arc_res = settings.var['curve_arc']
@@ -1288,6 +1498,7 @@ class Polyline: #--------------------------------------------------------------
else:
pline.setFlag(pline.getFlag() & ~6) # dont set top and button caps
+ pline.setResolu(settings.var['curve_res'])
pline.update()
ob = SCENE.objects.new(pline) # create a new curve_object
@@ -1314,6 +1525,7 @@ class Polyline: #--------------------------------------------------------------
ewidths = []
swidth_default = self.swidth #default start width of POLYLINEs segments
ewidth_default = self.ewidth #default end width of POLYLINEs segments
+ #print 'deb:drawPoly2d self.swidth=', self.swidth #------------------------
thic = set_thick(self.thic, settings)
if self.spline: pline_typ = 'ps'
elif self.curved: pline_typ = 'pc'
@@ -1350,8 +1562,10 @@ class Polyline: #--------------------------------------------------------------
#print 'deb:drawPoly2d len of d_pointsList ====== ', len(d_points) #------------------------
#print 'deb:drawPoly2d d_pointsList ======:\n ', d_points #------------------------
+ d_points = self.doubles_out(settings, d_points)
+ #print 'deb:drawPolyCurve d_pointsList =after DV-outsorting=====:\n ', d_points #------------------------
- # routine to sort out of "double.vertices" ------------------------------------
+ """# routine to sort out of "double.vertices" ------------------------------------
minimal_dist = settings.var['dist_min'] * 0.1
temp_points = []
for i in xrange(len(d_points)-1):
@@ -1366,6 +1580,7 @@ class Polyline: #--------------------------------------------------------------
#if self.closed: temp_points.append(d_points[1]) #------ loop start vertex -------------
d_points = temp_points #-----vertex.list without "double.vertices"
#print 'deb:drawPoly2d d_pointsList =after DV-outsorting=====:\n ', d_points #------------------------
+ """
#print 'deb:drawPoly2d len of d_pointsList ====== ', len(d_points) #------------------------
if len(d_points) < 2: #if too few vertex, then return
@@ -1385,9 +1600,11 @@ class Polyline: #--------------------------------------------------------------
swidth = point1.swidth
ewidth = point1.ewidth
+ #print 'deb:drawPoly2d point1.swidth=', swidth #------------------------
if swidth == None: swidth = swidth_default
if ewidth == None: ewidth = ewidth_default
if swidth != 0.0 or ewidth != 0.0: wide_segment_exist = True
+ #print 'deb:drawPoly2d vertex_swidth=', swidth #------------------------
if settings.var['width_force']: # force minimal width for thin segments
width_min = settings.var['width_min']
@@ -1571,14 +1788,14 @@ class Polyline: #--------------------------------------------------------------
left_angle = False
limit_dist = settings.var['dist_min']
if left_angle: # if left turning angle
- print 'deb:drawPoly2d it is left turning angle' #-------------
+ #print 'deb:drawPoly2d it is left turning angle' #-------------
# to avoid triangelface/doubleVertex
delta1 = (cornerpointL - vecL1).normalize() * limit_dist
delta4 = (cornerpointL - vecL4).normalize() * limit_dist
pointsLc.extend((cornerpointL - delta1, cornerpointL - delta4))
pointsRc.extend((pointsRe[i],pointsRs[i+1]))
else: # if right turning angle
- print 'deb:drawPoly2d right turning angle' #-------------
+ #print 'deb:drawPoly2d right turning angle' #-------------
delta1 = (cornerpointR - vecR1).normalize() * limit_dist
delta4 = (cornerpointR - vecR4).normalize() * limit_dist
pointsRc.extend((cornerpointR - delta1, cornerpointR - delta4))
@@ -1669,8 +1886,10 @@ class Polyline: #--------------------------------------------------------------
#faces = f_bottom + f_top
#faces = f_left + f_right + f_start + f_end
#print 'deb:faces_list:\n', faces #-----------------------
- me = Mesh.New(obname) # create a new mesh
- ob = SCENE.objects.new(me) # create a new mesh_object
+ if M_OBJ: obname, me, ob = makeNewObject()
+ else:
+ me = Mesh.New(obname) # create a new mesh
+ ob = SCENE.objects.new(me) # create a new mesh_object
me.verts.extend(pointsW) # add vertices to mesh
me.faces.extend(faces) # add faces to the mesh
@@ -1678,7 +1897,7 @@ class Polyline: #--------------------------------------------------------------
# The mesh must first be linked to an object so the method knows which object to update.
# This is because vertex groups in Blender are stored in the object -- not in the mesh,
# which may be linked to more than one object.
- if settings.var['vGroup_on']:
+ if settings.var['vGroup_on'] and not M_OBJ:
# each MeshSide becomes vertexGroup for easier material assignment ---------------------
replace = Blender.Mesh.AssignModes.REPLACE #or .AssignModes.ADD
vg_left, vg_right, vg_top, vg_bottom = [], [], [], []
@@ -1708,8 +1927,10 @@ class Polyline: #--------------------------------------------------------------
faces = [[num, len1+num, len1+num+1, num+1] for num in xrange(len1 - 1)]
if self.closed:
faces.append([len1, 0, len1-1, len1+len1-1])
- me = Mesh.New(obname) # create a new mesh
- ob = SCENE.objects.new(me) # create a new mesh_object
+ if M_OBJ: obname, me, ob = makeNewObject()
+ else:
+ me = Mesh.New(obname) # create a new mesh
+ ob = SCENE.objects.new(me) # create a new mesh_object
me.verts.extend(pointsW) # add vertices to mesh
me.faces.extend(faces) # add faces to the mesh
@@ -1728,8 +1949,10 @@ class Polyline: #--------------------------------------------------------------
faces = [[num, num+1, num+len1+1, num+len1] for num in xrange(len1 - 1)]
if self.closed:
faces.append([len1-1, 0, len1, 2*len1-1])
- me = Mesh.New(obname) # create a new mesh
- ob = SCENE.objects.new(me) # create a new mesh_object
+ if M_OBJ: obname, me, ob = makeNewObject()
+ else:
+ me = Mesh.New(obname) # create a new mesh
+ ob = SCENE.objects.new(me) # create a new mesh_object
me.verts.extend(points) # add vertices to mesh
me.faces.extend(faces) # add faces to the mesh
@@ -1745,8 +1968,10 @@ class Polyline: #--------------------------------------------------------------
edges = [[num, num+1] for num in xrange(len(points)-1)]
if self.closed:
edges.append([len(points)-1, 0])
- me = Mesh.New(obname) # create a new mesh
- ob = SCENE.objects.new(me) # create a new mesh_object
+ if M_OBJ: obname, me, ob = makeNewObject()
+ else:
+ me = Mesh.New(obname) # create a new mesh
+ ob = SCENE.objects.new(me) # create a new mesh_object
me.verts.extend(points) # add vertices to mesh
me.edges.extend(edges) # add edges to the mesh
@@ -1758,7 +1983,8 @@ class Polyline: #--------------------------------------------------------------
class Vertex(object): #-----------------------------------------------------------------
- """Generic vertex object used by POLYLINEs (and maybe others).
+ """Generic vertex object used by POLYLINEs, (and maybe others).
+ also used by class_LWPOLYLINEs but without obj-parameter
"""
def __init__(self, obj=None):
@@ -1769,15 +1995,19 @@ class Vertex(object): #--------------------------------------------------------
#print 'deb:Vertex.init.START:----------------' #-----------------------
self.loc = [0,0,0]
self.face = []
- self.swidth = 0
- self.ewidth = 0
+ self.swidth = None #0
+ self.ewidth = None #0
self.bulge = 0
+ self.tangent = False
+ self.weight = 1.0
if obj is not None:
if not obj.type == 'vertex':
raise TypeError, "Wrong type %s for vertex object!" %obj.type
self.type = obj.type
- self.data = obj.data[:]
- self.get_props(obj.data)
+# self.data = obj.data[:]
+ self.get_props(obj)
+ else:
+ pass
#print 'deb:Vertex.init.END:----------------' #------------------------
@@ -1798,24 +2028,29 @@ class Vertex(object): #--------------------------------------------------------
self.flags = getit(data, 70, 0) # flags
self.curved = self.flags&1 # Bezier-curve-fit:additional-vertex
- self.curv_t = self.flags&2 # Bezier-curve-fit:tangent exists
- self.spline = self.flags&8 # Bspline-fit:additional-vertex
- self.splin2 = self.flags&16 # Bspline-fit:control-vertex
+ self.curved_t = self.flags&2 # Bezier-curve-fit:tangent exists
+ self.spline = self.flags&8 # NURBSpline-fit:additional-vertex
+ self.spline_c = self.flags&16 # NURBSpline-fit:control-vertex
self.poly3d = self.flags&32 # polyline3d:control-vertex
self.plmesh = self.flags&64 # polymesh3d:control-vertex
self.plface = self.flags&128 # polyface
# if PolyFace.Vertex with Face_definition
- if self.curv_t:
- self.curv_tangent = getit(data, 50, None) # curve_tangent
-
- if self.plface and not self.plmesh:
- v1 = getit(data, 71, 0) # polyface:Face.vertex 1.
- v2 = getit(data, 72, 0) # polyface:Face.vertex 2.
- v3 = getit(data, 73, 0) # polyface:Face.vertex 3.
- v4 = getit(data, 74, None) # polyface:Face.vertex 4.
- self.face = [abs(v1)-1,abs(v2)-1,abs(v3)-1]
- if v4 != None:
+ if self.curved_t:
+ self.curve_tangent = getit(data, 50, None) # curve_tangent
+ if not self.curve_tangent==None:
+ self.tangent = True
+ #elif self.spline_c: # NURBSpline:control-vertex
+ # self.weight = getit(data, 41, 1.0) # weight od control point
+
+ elif self.plface and not self.plmesh:
+ v1 = getit(data, 71, 0) # polyface:Face.vertex 1.
+ v2 = getit(data, 72, 0) # polyface:Face.vertex 2.
+ v3 = getit(data, 73, 0) # polyface:Face.vertex 3.
+ v4 = getit(data, 74, None) # polyface:Face.vertex 4.
+ self.face = [abs(v1)-1,abs(v2)-1,abs(v3)-1]
+ if v4 != None:
+ if abs(v4) != abs(v1):
self.face.append(abs(v4)-1)
else: #--parameter for polyline2d
self.swidth = getit(data, 40, None) # start width
@@ -1870,6 +2105,263 @@ class Vertex(object): #--------------------------------------------------------
+class Spline(Polyline): #-----------------------------------------------------------------
+ """Class for objects representing dxf SPLINEs.
+ """
+ """Expects an entity object of type spline as input.
+100 - Subclass marker (AcDbSpline)
+210,220, 230 - Normal vector (omitted if the spline is nonplanar) X,Y,Z values of normal vector
+70 - Spline flag (bit coded):
+ 1 = Closed spline
+ 2 = Periodic spline
+ 4 = Rational spline
+ 8 = Planar
+ 16 = Linear (planar bit is also set)
+71 - Degree of the spline curve
+72 - Number of knots
+73 - Number of control points
+74 - Number of fit points (if any)
+42 - Knot tolerance (default = 0.0000001)
+43 - Control-point tolerance (default = 0.0000001)
+44 - Fit tolerance (default = 0.0000000001)
+12,22,32 - Start tangent--may be omitted (in WCS). X,Y,Z values of start tangent--may be omitted (in WCS).
+13,23, 33 - End tangent--may be omitted (in WCS). X,Y,Z values of end tangent--may be omitted (in WCS)
+40 - Knot value (one entry per knot)
+41 - Weight (if not 1); with multiple group pairs, are present if all are not 1
+10,20, 30 - Control points (in WCS) one entry per control point.
+DXF: X value; APP: 3D point, Y and Z values of control points (in WCS) (one entry per control point)
+11,21, 31 - Fit points (in WCS) one entry per fit point.
+ X,Y,Z values of fit points (in WCS) (one entry per fit point)
+ """
+ def __init__(self, obj):
+ #print 'deb:Spline.START:----------------' #------------------------
+ if not obj.type == 'spline':
+ raise TypeError, "Wrong type %s for spline object!" %obj.type
+ self.type = obj.type
+# self.data = obj.data[:]
+
+ # required data
+ self.num_points = obj.get_type(73)[0]
+
+ # optional data (with defaults)
+ self.space = getit(obj, 67, 0)
+
+ self.color_index = getit(obj, 62, BYLAYER)
+
+ #self.elevation = getit(obj, 30, 0)
+ self.thic = 0 # getit(obj, 39, 0)
+
+ width = 0
+ self.swidth = width # default start width
+ self.ewidth = width # default end width
+
+ self.flags = getit(obj, 70, 0)
+ self.closed = self.flags & 1 # closed spline
+ self.period = self.flags & 2 # Periodic spline
+ self.ration = self.flags & 4 # Rational spline
+ self.planar = self.flags & 8 # Planar
+ self.linear = self.flags & 16 # Linear (and Planar)
+
+ self.curvNoFitted = False
+ self.curvQuadrati = False
+ self.curvCubicBsp = False
+ self.curvBezier = False
+ self.degree = getit(obj, 71, 0) # Degree of the spline curve
+ if self.degree == 0: self.curvNoFitted = True
+ elif self.degree == 1: self.curvQuadrati = True
+ elif self.degree == 2: self.curvCubicBsp = True
+ #elif self.degree == 3: self.curvBezier = True
+ #elif self.degree == 3: self.spline = True
+
+ self.knotpk_len = getit(obj, 72, 0) # Number of knots
+ self.ctrlpk_len = getit(obj, 73, 0) # Number of control points
+ self.fit_pk_len = getit(obj, 74, 0) # Number of fit points (if any)
+
+ #print 'deb:Spline self.fit_pk_len=', self.fit_pk_len #------------------------
+ #self.fit_pk_len = 0 # temp for debug
+ if self.fit_pk_len and 'spline_as'==5:
+ self.spline = False
+ self.curved = True
+ else:
+ self.spline = True
+ self.curved = False
+
+ self.knotpk_tol = getit(obj, 42, 0.0000001) # Knot tolerance (default = 0.0000001)
+ self.ctrlpk_tol = getit(obj, 43, 0.0000001) # Control-point tolerance (default = 0.0000001)
+ self.fit_pk_tol = getit(obj, 44, 0.0000000001) # Fit tolerance (default = 0.0000000001)
+
+ self.layer = getit(obj, 8, None)
+ self.extrusion = get_extrusion(obj)
+
+ self.pltype = 'spline' # spline is a 2D- or 3D-polyline
+
+ self.points = self.get_points(obj.data)
+ #self.knots_val = self.get_knots_val(obj.data) # 40 - Knot value (one entry per knot)
+ #self.knots_wgh = self.get_knots_wgh(obj.data) # 41 - Weight (default 1)
+
+ #print 'deb:Spline obj.data:\n', obj.data #------------------------
+ #print 'deb:Spline self.points:\n', self.points #------------------------
+ #print 'deb:Spline.ENDinit:----------------' #------------------------
+
+
+ def get_points(self, data):
+ """Gets points for a spline type object.
+
+ Splines have fixed number of verts, and
+ each vert can have a number of properties.
+ Verts should be coded as
+ 10:xvalue
+ 20:yvalue
+ for each vert
+ """
+ point = None
+ points = []
+ pointend = None
+ #point = Vertex()
+ if self.spline: # NURBSpline definition
+ for item in data:
+ #print 'deb:Spline.get_points spilne_item:', item #------------------------
+ if item[0] == 10: # control point
+ if point: points.append(point)
+ point = Vertex()
+ point.curved = True
+ point.x = item[1]
+ elif item[0] == 20: # 20 = y
+ point.y = item[1]
+ elif item[0] == 30: # 30 = z
+ point.z = item[1]
+ elif item[0] == 41: # 41 = weight
+ point.weight = item[1]
+ #print 'deb:Spline.get_points control point:', point #------------------------
+
+ elif self.curved: # Bezier definition
+ for item in data:
+ #print 'deb:Spline.get_points curved_item:', item #------------------------
+ if item[0] == 11: # fit point
+ if point: points.append(point)
+ point = Vertex()
+ point.tangent = False
+ point.x = item[1]
+ elif item[0] == 21: # 20 = y
+ point.y = item[1]
+ elif item[0] == 31: # 30 = z
+ point.z = item[1]
+ #print 'deb:Spline.get_points fit point:', point #------------------------
+
+ elif item[0] == 12: # start tangent
+ if point: points.append(point)
+ point = Vertex()
+ point.tangent = True
+ point.x = item[1]
+ elif item[0] == 22: # = y
+ point.y = item[1]
+ elif item[0] == 32: # = z
+ point.z = item[1]
+ #print 'deb:Spline.get_points fit begtangent:', point #------------------------
+
+ elif item[0] == 13: # end tangent
+ if point: points.append(point)
+ pointend = Vertex()
+ pointend.tangent = True
+ pointend.x = item[1]
+ elif item[0] == 23: # 20 = y
+ pointend.y = item[1]
+ elif item[0] == 33: # 30 = z
+ pointend.z = item[1]
+ #print 'deb:Spline.get_points fit endtangent:', pointend #------------------------
+ points.append(point)
+ if self.curved and pointend:
+ points.append(pointend)
+ #print 'deb:Spline points:\n', points #------------------------
+ return points
+
+ def __repr__(self):
+ return "%s: layer - %s, points - %s" %(self.__class__.__name__, self.layer, self.points)
+
+
+
+class LWpolyline(Polyline): #-------------------------------------------------------------
+ """Class for objects representing dxf LWPOLYLINEs.
+ """
+ def __init__(self, obj):
+ """Expects an entity object of type lwpolyline as input.
+ """
+ #print 'deb:LWpolyline.START:----------------' #------------------------
+ if not obj.type == 'lwpolyline':
+ raise TypeError, "Wrong type %s for polyline object!" %obj.type
+ self.type = obj.type
+# self.data = obj.data[:]
+
+ # required data
+ self.num_points = obj.get_type(90)[0]
+
+ # optional data (with defaults)
+ self.space = getit(obj, 67, 0)
+ self.elevation = getit(obj, 38, 0)
+ self.thic = getit(obj, 39, 0)
+ self.color_index = getit(obj, 62, BYLAYER)
+ width = getit(obj, 43, 0)
+ self.swidth = width # default start width
+ self.ewidth = width # default end width
+ #print 'deb:LWpolyline width=', width #------------------------
+ #print 'deb:LWpolyline elevation=', self.elevation #------------------------
+
+ self.flags = getit(obj, 70, 0)
+ self.closed = self.flags&1 # byte coded, 1 = closed, 128 = plinegen
+
+ self.layer = getit(obj, 8, None)
+ self.extrusion = get_extrusion(obj)
+
+ self.points = self.get_points(obj.data)
+
+ self.pltype = 'poly2d' # LW-polyline is a 2D-polyline
+ self.spline = False
+ self.curved = False
+
+
+ #print 'deb:LWpolyline.obj.data:\n', obj.data #------------------------
+ #print 'deb:LWpolyline.ENDinit:----------------' #------------------------
+
+
+ def get_points(self, data):
+ """Gets points for a polyline type object.
+
+ LW-Polylines have no fixed number of verts, and
+ each vert can have a number of properties.
+ Verts should be coded as
+ 10:xvalue
+ 20:yvalue
+ 40:startwidth or 0
+ 41:endwidth or 0
+ 42:bulge or 0
+ for each vert
+ """
+ num = self.num_points
+ point = None
+ points = []
+ for item in data:
+ if item[0] == 10: # 10 = x
+ if point:
+ points.append(point)
+ point = Vertex()
+ point.x = item[1]
+ point.z = self.elevation
+ elif item[0] == 20: # 20 = y
+ point.y = item[1]
+ elif item[0] == 40: # 40 = start width
+ point.swidth = item[1]
+ elif item[0] == 41: # 41 = end width
+ point.ewidth = item[1]
+ elif item[0] == 42: # 42 = bulge
+ point.bulge = item[1]
+ points.append(point)
+ return points
+
+
+ def __repr__(self):
+ return "%s: layer - %s, points - %s" %(self.__class__.__name__, self.layer, self.points)
+
+
class Text: #-----------------------------------------------------------------
"""Class for objects representing dxf TEXT.
"""
@@ -1879,7 +2371,7 @@ class Text: #-----------------------------------------------------------------
if not obj.type == 'text':
raise TypeError, "Wrong type %s for text object!" %obj.type
self.type = obj.type
- self.data = obj.data[:]
+# self.data = obj.data[:]
# required data
self.height = 1.7 * obj.get_type(40)[0] #text.height
@@ -1911,14 +2403,13 @@ class Text: #-----------------------------------------------------------------
#3=aligned, 4=middle, 5=fit
self.halignment = getit(obj, 72, 0)
- self.layer = getit(obj.data, 8, None)
- self.loc1, self.loc2 = self.get_loc(obj.data)
+ self.layer = getit(obj, 8, None)
+ self.loc1, self.loc2 = self.get_loc(obj)
if self.loc2[0] != None and self.halignment != 5:
self.loc = self.loc2
else:
self.loc = self.loc1
- self.extrusion = get_extrusion(obj.data)
-
+ self.extrusion = get_extrusion(obj)
def get_loc(self, data):
@@ -2027,13 +2518,13 @@ class Mtext: #-----------------------------------------------------------------
if not obj.type == 'mtext':
raise TypeError, "Wrong type %s for mtext object!" %obj.type
self.type = obj.type
- self.data = obj.data[:]
+# self.data = obj.data[:]
# required data
self.height = obj.get_type(40)[0]
self.width = obj.get_type(41)[0]
self.alignment = obj.get_type(71)[0] # alignment 1=TL, 2=TC, 3=TR, 4=ML, 5=MC, 6=MR, 7=BL, 8=BC, 9=BR
- self.value = self.get_text(obj.data) # The text string value
+ self.value = self.get_text(obj) # The text string value
# optional data (with defaults)
self.space = getit(obj, 67, 0)
@@ -2043,9 +2534,9 @@ class Mtext: #-----------------------------------------------------------------
self.width_factor = getit(obj, 42, 1) # Scaling factor along local x axis
self.line_space = getit(obj, 44, 1) # percentage of default
- self.layer = getit(obj.data, 8, None)
- self.loc = self.get_loc(obj.data)
- self.extrusion = get_extrusion(obj.data)
+ self.layer = getit(obj, 8, None)
+ self.loc = self.get_loc(obj)
+ self.extrusion = get_extrusion(obj)
def get_text(self, data):
@@ -2114,8 +2605,6 @@ class Mtext: #-----------------------------------------------------------------
return ob
-
-
class Circle: #-----------------------------------------------------------------
"""Class for objects representing dxf CIRCLEs.
"""
@@ -2126,7 +2615,7 @@ class Circle: #----------------------------------------------------------------
if not obj.type == 'circle':
raise TypeError, "Wrong type %s for circle object!" %obj.type
self.type = obj.type
- self.data = obj.data[:]
+# self.data = obj.data[:]
# required data
self.radius = obj.get_type(40)[0]
@@ -2136,9 +2625,9 @@ class Circle: #----------------------------------------------------------------
self.thic = getit(obj, 39, 0)
self.color_index = getit(obj, 62, BYLAYER)
- self.layer = getit(obj.data, 8, None)
- self.loc = self.get_loc(obj.data)
- self.extrusion = get_extrusion(obj.data)
+ self.layer = getit(obj, 8, None)
+ self.loc = self.get_loc(obj)
+ self.extrusion = get_extrusion(obj)
@@ -2167,18 +2656,15 @@ class Circle: #----------------------------------------------------------------
radius = self.radius
thic = set_thick(self.thic, settings)
- if settings.var['curves_on']:
- if False: # universal version
- arc_res = 4 # ONLY 4 works well for point.handleTypes = [AUTO, AUTO]
- start, end = 0.0, 360.0
- verts = calcArc(None, radius, start, end, arc_res, True)
- c = Curve.New(obname) # create new curve data
- curve = c.appendNurb(BezTriple.New(verts[0]))
- for p in verts[1:-1]:
- curve.append(BezTriple.New(p))
- for point in curve:
- point.handleTypes = [AUTO, AUTO]
- elif True: # universal version
+ width = 0.0
+ if settings.var['lines_as'] == 4: # as thin_box
+ thic = settings.var['thick_min']
+ width = settings.var['width_min']
+ if settings.var['lines_as'] == 3: # as thin cylinder
+ cyl_rad = 0.5 * settings.var['width_min']
+
+ if settings.var['lines_as'] == 5: # draw CIRCLE as curve -------------
+ if True: # universal version
arc_res = settings.var['curve_arc']
#arc_res = 3
start, end = 0.0, 360.0
@@ -2214,9 +2700,10 @@ class Circle: #----------------------------------------------------------------
else:
c.setFlag(c.getFlag() & ~6) # dont set top and button caps
+ c.setResolu(settings.var['curve_res'])
c.update()
- #remi --todo-----to check---------------------------
+ #--todo-----to check---------------------------
ob = SCENE.objects.new(c) # create a new curve_object
ob.loc = tuple(self.loc)
if thic != 0.0: #hack: Blender<2.45 curve-extrusion
@@ -2247,14 +2734,17 @@ class Circle: #----------------------------------------------------------------
return ob
else: # draw CIRCLE as mesh -----------------------------------------------
- cir = Mesh.New(obname) # create a new mesh
- ob = SCENE.objects.new(cir) # create a new circle_object
+ if M_OBJ: obname, me, ob = makeNewObject()
+ else:
+ me = Mesh.New(obname) # create a new mesh
+ ob = SCENE.objects.new(me) # create a new mesh_object
# set a number of segments in entire circle
arc_res = settings.var['arc_res'] * sqrt(radius) / sqrt(settings.var['arc_rad'])
start, end = 0.0 , 360.0
verts = calcArc(None, radius, start, end, arc_res, False)
verts = verts[:-1] #list without last point/edge (cause by circle it is equal to the first point)
- #print 'deb:circleDraw:edges:', edges #---------------
+ #print 'deb:circleDraw: verts:', verts #---------------
+
if thic != 0:
len1 = len(verts)
thic_verts = []
@@ -2286,24 +2776,24 @@ class Circle: #----------------------------------------------------------------
#print 'deb:circleDraw:verts:', verts #---------------
faces = f_band + f_bottom + f_top
#print 'deb:circleDraw:faces:', faces #---------------
- cir.verts.extend(verts) # add vertices to mesh
- cir.faces.extend(faces) # add faces to the mesh
+ me.verts.extend(verts) # add vertices to mesh
+ me.faces.extend(faces) # add faces to the mesh
if settings.var['meshSmooth_on']: # left and right side become smooth ----------------------
for i in xrange(smooth_len):
- cir.faces[i].smooth = True
+ me.faces[i].smooth = True
# each MeshSide becomes vertexGroup for easier material assignment ---------------------
- if settings.var['vGroup_on']:
+ if settings.var['vGroup_on'] and not M_OBJ:
# each MeshSide becomes vertexGroup for easier material assignment ---------------------
replace = Blender.Mesh.AssignModes.REPLACE #or .AssignModes.ADD
vg_band, vg_top, vg_bottom = [], [], []
for v in f_band: vg_band.extend(v)
- cir.addVertGroup('side.band') ; cir.assignVertsToGroup('side.band', list(set(vg_band)), 1.0, replace)
+ me.addVertGroup('side.band') ; me.assignVertsToGroup('side.band', list(set(vg_band)), 1.0, replace)
if settings.var['fill_on']:
for v in f_top: vg_top.extend(v)
for v in f_bottom: vg_bottom.extend(v)
- cir.addVertGroup('side.top') ; cir.assignVertsToGroup('side.top', list(set(vg_top)), 1.0, replace)
- cir.addVertGroup('side.bottom'); cir.assignVertsToGroup('side.bottom',list(set(vg_bottom)), 1.0, replace)
+ me.addVertGroup('side.top') ; me.assignVertsToGroup('side.top', list(set(vg_top)), 1.0, replace)
+ me.addVertGroup('side.bottom'); me.assignVertsToGroup('side.bottom',list(set(vg_bottom)), 1.0, replace)
else: # if thic == 0
if settings.var['fill_on']:
@@ -2315,20 +2805,18 @@ class Circle: #----------------------------------------------------------------
faces.append([len1-1, 0, center1])
#print 'deb:circleDraw:verts:', verts #---------------
#print 'deb:circleDraw:faces:', faces #---------------
- cir.verts.extend(verts) # add vertices to mesh
- cir.faces.extend(faces) # add faces to the mesh
+ me.verts.extend(verts) # add vertices to mesh
+ me.faces.extend(faces) # add faces to the mesh
else:
- cir.verts.extend(verts) # add vertices to mesh
+ me.verts.extend(verts) # add vertices to mesh
edges = [[num, num+1] for num in xrange(len(verts))]
edges[-1][1] = 0 # it points the "new" last edge to the first vertex
- cir.edges.extend(edges) # add edges to the mesh
+ me.edges.extend(edges) # add edges to the mesh
ob.loc = tuple(self.loc)
transform(self.extrusion, 0, ob)
return ob
-
-
class Arc: #-----------------------------------------------------------------
"""Class for objects representing dxf ARCs.
@@ -2340,7 +2828,7 @@ class Arc: #-----------------------------------------------------------------
if not obj.type == 'arc':
raise TypeError, "Wrong type %s for arc object!" %obj.type
self.type = obj.type
- self.data = obj.data[:]
+# self.data = obj.data[:]
# required data
self.radius = obj.get_type(40)[0]
@@ -2352,9 +2840,9 @@ class Arc: #-----------------------------------------------------------------
self.thic = getit(obj, 39, 0)
self.color_index = getit(obj, 62, BYLAYER)
- self.layer = getit(obj.data, 8, None)
- self.loc = self.get_loc(obj.data)
- self.extrusion = get_extrusion(obj.data)
+ self.layer = getit(obj, 8, None)
+ self.loc = self.get_loc(obj)
+ self.extrusion = get_extrusion(obj)
#print 'deb:Arc__init__: center, radius, start, end:\n', self.loc, self.radius, self.start_angle, self.end_angle #---------
@@ -2395,7 +2883,7 @@ class Arc: #-----------------------------------------------------------------
if settings.var['lines_as'] == 3: # as thin cylinder
cyl_rad = 0.5 * settings.var['width_min']
- if settings.var['curves_on']: # draw ARC as curve -------------
+ if settings.var['lines_as'] == 5: # draw ARC as curve -------------
arc_res = settings.var['curve_arc']
triples = True
VectorTriples = calcArc(None, radius, start, end, arc_res, triples)
@@ -2406,6 +2894,8 @@ class Arc: #-----------------------------------------------------------------
for point in curve:
point.handleTypes = [FREE, FREE]
curve.flagU = 0 # 0 sets the curve not cyclic=open
+ arc.setResolu(settings.var['curve_res'])
+
arc.update() #important for handles calculation
ob = SCENE.objects.new(arc) # create a new curve_object
@@ -2420,8 +2910,10 @@ class Arc: #-----------------------------------------------------------------
return ob
else: # draw ARC as mesh --------------------
- arc = Mesh.New(obname) # create a new mesh
- ob = SCENE.objects.new(arc) # create a new arc_object
+ if M_OBJ: obname, me, ob = makeNewObject()
+ else:
+ me = Mesh.New(obname) # create a new mesh
+ ob = SCENE.objects.new(me) # create a new mesh_object
# set a number of segments in entire circle
arc_res = settings.var['arc_res'] * sqrt(radius) / sqrt(settings.var['arc_rad'])
@@ -2430,34 +2922,19 @@ class Arc: #-----------------------------------------------------------------
len1 = len(verts)
#print 'deb:len1:', len1 #-----------------------
if width != 0:
- if False:
- radius_out = radius + (0.5 * width)
- radius_in = radius - (0.5 * width)
- if radius_in <= 0.0:
- radius_in = settings.var['dist_min']
- #radius_in = 0.0
- verts_in = []
- verts_out = []
- for point in verts:
- pointVec = Mathutils.Vector(point)
- pointVec = pointVec.normalize()
- verts_in.append(list(radius_in * pointVec)) #vertex inside
- verts_out.append(list(radius_out * pointVec)) #vertex outside
- verts = verts_in + verts_out
- else:
- radius_out = radius + (0.5 * width)
- radius_in = radius - (0.5 * width)
- if radius_in <= 0.0:
- radius_in = settings.var['dist_min']
- #radius_in = 0.0
- verts_in = []
- verts_out = []
- for point in verts:
- pointVec = Mathutils.Vector(point)
- pointVec = pointVec.normalize()
- verts_in.append(list(radius_in * pointVec)) #vertex inside
- verts_out.append(list(radius_out * pointVec)) #vertex outside
- verts = verts_in + verts_out
+ radius_out = radius + (0.5 * width)
+ radius_in = radius - (0.5 * width)
+ if radius_in <= 0.0:
+ radius_in = settings.var['dist_min']
+ #radius_in = 0.0
+ verts_in = []
+ verts_out = []
+ for point in verts:
+ pointVec = Mathutils.Vector(point)
+ pointVec = pointVec.normalize()
+ verts_in.append(list(radius_in * pointVec)) #vertex inside
+ verts_out.append(list(radius_out * pointVec)) #vertex outside
+ verts = verts_in + verts_out
#print 'deb:verts:', verts #---------------------
if thic != 0:
@@ -2476,15 +2953,15 @@ class Arc: #-----------------------------------------------------------------
f_end = [[len1+len1-1, 0+len1-1, len1+len1+len1-1, len1+len1+len1+len1-1]]
faces = f_left + f_right + f_bottom + f_top + f_start + f_end
- arc.verts.extend(verts) # add vertices to mesh
- arc.faces.extend(faces) # add faces to the mesh
+ me.verts.extend(verts) # add vertices to mesh
+ me.faces.extend(faces) # add faces to the mesh
if settings.var['meshSmooth_on']: # left and right side become smooth ----------------------
smooth_len = len(f_left) + len(f_right)
for i in xrange(smooth_len):
- arc.faces[i].smooth = True
+ me.faces[i].smooth = True
# each MeshSide becomes vertexGroup for easier material assignment ---------------------
- if settings.var['vGroup_on']:
+ if settings.var['vGroup_on'] and not M_OBJ:
# each MeshSide becomes vertexGroup for easier material assignment ---------------------
replace = Blender.Mesh.AssignModes.REPLACE #or .AssignModes.ADD
vg_left, vg_right, vg_top, vg_bottom = [], [], [], []
@@ -2492,18 +2969,18 @@ class Arc: #-----------------------------------------------------------------
for v in f_right: vg_right.extend(v)
for v in f_top: vg_top.extend(v)
for v in f_bottom: vg_bottom.extend(v)
- arc.addVertGroup('side.left') ; arc.assignVertsToGroup('side.left', list(set(vg_left)), 1.0, replace)
- arc.addVertGroup('side.right') ; arc.assignVertsToGroup('side.right', list(set(vg_right)), 1.0, replace)
- arc.addVertGroup('side.top') ; arc.assignVertsToGroup('side.top', list(set(vg_top)), 1.0, replace)
- arc.addVertGroup('side.bottom'); arc.assignVertsToGroup('side.bottom',list(set(vg_bottom)), 1.0, replace)
- arc.addVertGroup('side.start'); arc.assignVertsToGroup('side.start', f_start[0], 1.0, replace)
- arc.addVertGroup('side.end') ; arc.assignVertsToGroup('side.end', f_end[0], 1.0, replace)
+ me.addVertGroup('side.left') ; me.assignVertsToGroup('side.left', list(set(vg_left)), 1.0, replace)
+ me.addVertGroup('side.right') ; me.assignVertsToGroup('side.right', list(set(vg_right)), 1.0, replace)
+ me.addVertGroup('side.top') ; me.assignVertsToGroup('side.top', list(set(vg_top)), 1.0, replace)
+ me.addVertGroup('side.bottom'); me.assignVertsToGroup('side.bottom',list(set(vg_bottom)), 1.0, replace)
+ me.addVertGroup('side.start'); me.assignVertsToGroup('side.start', f_start[0], 1.0, replace)
+ me.addVertGroup('side.end') ; me.assignVertsToGroup('side.end', f_end[0], 1.0, replace)
else: # if thick=0 - draw only flat ring
faces = [[num, len1+num, len1+num+1, num+1] for num in xrange(len1 - 1)]
- arc.verts.extend(verts) # add vertices to mesh
- arc.faces.extend(faces) # add faces to the mesh
+ me.verts.extend(verts) # add vertices to mesh
+ me.faces.extend(faces) # add faces to the mesh
elif thic != 0:
thic_verts = []
@@ -2518,20 +2995,20 @@ class Arc: #-----------------------------------------------------------------
#print 'deb:verts:', verts #---------------------
faces = [[num, num+1, num+len1+1, num+len1] for num in xrange(len1 - 1)]
- arc.verts.extend(verts) # add vertices to mesh
- arc.faces.extend(faces) # add faces to the mesh
+ me.verts.extend(verts) # add vertices to mesh
+ me.faces.extend(faces) # add faces to the mesh
if settings.var['meshSmooth_on']: # left and right side become smooth ----------------------
for i in xrange(len(faces)):
- arc.faces[i].smooth = True
+ me.faces[i].smooth = True
else:
edges = [[num, num+1] for num in xrange(len(verts)-1)]
- arc.verts.extend(verts) # add vertices to mesh
- arc.edges.extend(edges) # add edges to the mesh
+ me.verts.extend(verts) # add vertices to mesh
+ me.edges.extend(edges) # add edges to the mesh
- #arc.update()
- #ob = SCENE.objects.new(arc) # create a new arc_object
- #ob.link(arc)
+ #me.update()
+ #ob = SCENE.objects.new(me) # create a new arc_object
+ #ob.link(me)
ob.loc = tuple(center)
#ob.loc = Mathutils.Vector(ob.loc)
transform(self.extrusion, 0, ob)
@@ -2549,7 +3026,7 @@ class BlockRecord: #-----------------------------------------------------------
if not obj.type == 'block_record':
raise TypeError, "Wrong type %s for block_record object!" %obj.type
self.type = obj.type
- self.data = obj.data[:]
+# self.data = obj.data[:]
# required data
self.name = getit(obj, 2, None)
@@ -2557,8 +3034,8 @@ class BlockRecord: #-----------------------------------------------------------
# optional data (with defaults)
self.insertion_units = getit(obj, 70, None)
self.insert_units = getit(obj, 1070, None)
- """code 1070 Einfügeeinheiten:
- 0 = Keine Einheiten; 1 = Zoll; 2 = Fuß; 3 = Meilen; 4 = Millimeter;
+ """code 1070 Einfuegeeinheiten:
+ 0 = Keine Einheiten; 1 = Zoll; 2 = Fuss; 3 = Meilen; 4 = Millimeter;
5 = Zentimeter; 6 = Meter; 7 = Kilometer; 8 = Mikrozoll;
9 = Mils; 10 = Yard; 11 = Angstrom; 12 = Nanometer;
13 = Mikrons; 14 = Dezimeter; 15 = Dekameter;
@@ -2582,30 +3059,44 @@ class Block: #-----------------------------------------------------------------
"""
if not obj.type == 'block':
raise TypeError, "Wrong type %s for block object!" %obj.type
+
self.type = obj.type
- self.data = obj.data[:]
self.name = obj.name
+ self.data = obj.data[:]
# required data
- self.flags = obj.get_type(70)[0]
- self.entities = dxfObject('block_contents') #creates empty entities_container for this block
- self.entities.data = objectify([ent for ent in obj.data if type(ent) != list])
+ self.flags = getit(obj, 70, 0)
+ self.anonim = self.flags & 1 #anonymous block generated by hatching, associative dimensioning, other
+ self.atrib = self.flags & 2 # has attribute definitions
+ self.xref = self.flags & 4 # is an external reference (xref)
+ self.xref_lay = self.flags & 8 # is an xref overlay
+ self.dep_ext = self.flags & 16 # is externally dependent
+ self.dep_res = self.flags & 32 # resolved external reference
+ self.xref_ext = self.flags & 64 # is a referenced external reference xref
+ #--todo--- if self.flag > 4: self.xref = True
# optional data (with defaults)
- self.path = getit(obj, 1, '')
+ self.path = getit(obj, 1, '') # Xref path name
self.discription = getit(obj, 4, '')
- self.layer = getit(obj.data, 8, None)
- self.loc = self.get_loc(obj.data)
+ self.entities = dxfObject('block_contents') #creates empty entities_container for this block
+ self.entities.data = objectify([ent for ent in obj.data if type(ent) != list])
+
+ self.layer = getit(obj, 8, None)
+ self.loc = self.get_loc(obj)
+ #print 'deb:Block %s data:\n%s' %(self.name, self.data) #------------
+ #print 'deb:Block %s self.entities.data:\n%s' %(self.name, self.entities.data) #------------
+
+
def get_loc(self, data):
"""Gets the insert point of the block.
"""
loc = [0, 0, 0]
- loc[0] = getit(data, 10, None) # 10 = x
- loc[1] = getit(data, 20, None) # 20 = y
- loc[2] = getit(data, 30, 0.0) # 30 = z
+ loc[0] = getit(data, 10, 0.0) # 10 = x
+ loc[1] = getit(data, 20, 0.0) # 20 = y
+ loc[2] = getit(data, 30, 0.0) # 30 = z
return loc
@@ -2626,21 +3117,24 @@ class Insert: #----------------------------------------------------------------
raise TypeError, "Wrong type %s for insert object!" %obj.type
self.type = obj.type
self.data = obj.data[:]
+ #print 'deb:Insert_init_ self.data:\n', self.data #-----------
# required data
- self.blockname = obj.get_type(2)[0]
+ self.name = obj.get_type(2)[0]
# optional data (with defaults)
self.rotation = getit(obj, 50, 0)
self.space = getit(obj, 67, 0)
self.color_index = getit(obj, 62, BYLAYER)
- self.layer = getit(obj.data, 8, None)
- self.loc = self.get_loc(obj.data)
- self.scale = self.get_scale(obj.data)
- self.rows, self.columns = self.get_array(obj.data)
- self.extrusion = get_extrusion(obj.data)
+ self.layer = getit(obj, 8, None)
+ self.loc = self.get_loc(obj)
+ self.scale = self.get_scale(obj)
+ self.rows, self.columns = self.get_array(obj)
+ self.extrusion = get_extrusion(obj)
+ #self.flags = getit(obj.data, 66, 0) #
+ #self.attrib = self.flags & 1
def get_loc(self, data):
@@ -2653,7 +3147,6 @@ class Insert: #----------------------------------------------------------------
return loc
-
def get_scale(self, data):
"""Gets the x/y/z scale factors of the insert.
"""
@@ -2664,7 +3157,6 @@ class Insert: #----------------------------------------------------------------
return scale
-
def get_array(self, data):
"""Returns the pair (row number, row spacing), (column number, column spacing).
"""
@@ -2675,9 +3167,38 @@ class Insert: #----------------------------------------------------------------
return (rows, rspace), (columns, cspace)
+ def get_target(self, data):
+ """Gets the origin location of the insert.
+ """
+ loc = [0, 0, 0]
+ loc[0] = getit(data, 1011, 0.0)
+ loc[1] = getit(data, 1021, 0.0)
+ loc[2] = getit(data, 1031, 0.0)
+ return loc
+
+
+ def get_color(self, data):
+ """Gets the origin location of the insert.
+ """
+ loc = [0, 0, 0]
+ loc[0] = getit(data, 1010, 0.0)
+ loc[1] = getit(data, 1020, 0.0)
+ loc[2] = getit(data, 1030, 0.0)
+ return loc
+
+
+ def get_ave_render(self, data):
+ """Gets the origin location of the insert.
+ """
+ loc = [0, 0, 0]
+ loc[0] = getit(data, 1010, 0.0)
+ loc[1] = getit(data, 1020, 0.0)
+ loc[2] = getit(data, 1030, 0.0)
+ return loc
+
def __repr__(self):
- return "%s: layer - %s, blockname - %s" %(self.__class__.__name__, self.layer, self.blockname)
+ return "%s: layer - %s, name - %s" %(self.__class__.__name__, self.layer, self.name)
def draw(self, settings, deltaloc):
@@ -2692,11 +3213,89 @@ class Insert: #----------------------------------------------------------------
insert object gives the location/scale/rotation of the block instances.
"""
- obname = settings.blocknamesmap[self.blockname]
- obname = 'in_%s' %obname # create object name from block name
- #obname = obname[:MAX_NAMELENGTH]
-
- if settings.drawTypes['insert']: #if insert_drawType activated
+ name = self.name.lower()
+ if name == 'ave_render':
+ if settings.var['lights_on']: #if lights support activated
+ a_data = get_ave_data(self.data)
+ # AVE_RENDER objects:
+ # 7:'Pref', 0:'Full Opt', 0:'Quick Opt', 1:'Scanl Opt', 2:'Raytr Opt', 0:'RFile Opt'
+ # 0:'Fog Opt', 0:'BG Opt', 0:'SCENE1','','','','','','','','','',
+ # '','','','','','','','','','','','',
+
+ if a_data.key == 'SCENE': # define set of lights as blender group
+ scene_lights = 1
+ elif False: # define set of lights as blender group
+ scene_lights = 1
+ return
+ elif name == 'ave_global':
+ if settings.var['lights_on']: #if lights support activated
+ return
+ elif name == 'sh_spot':
+ if settings.var['lights_on']: #if lights support activated
+ obname = settings.blocknamesmap[self.name]
+ obname = 'sp_%s' %obname # create object name from block name
+ #obname = obname[:MAX_NAMELENGTH]
+ # blender: 'Lamp', 'Sun', 'Spot', 'Hemi', 'Area', or 'Photon'
+ li = Lamp.New('Spot', obname)
+ ob = SCENE.objects.new(li)
+ intensity = 2.0 #--todo-- -----------
+ li.setEnergy(intensity)
+ target = self.get_target(self.data)
+ color = self.get_color(self.data)
+ li.R = color[0]
+ li.G = color[1]
+ li.B = color[2]
+
+ ob.loc = tuple(self.loc)
+ transform(self.extrusion, 0, ob)
+ return ob
+
+ elif name == 'overhead':
+ if settings.var['lights_on']: #if lights support activated
+ obname = settings.blocknamesmap[self.name]
+ obname = 'la_%s' %obname # create object name from block name
+ #obname = obname[:MAX_NAMELENGTH]
+ # blender: 'Lamp', 'Sun', 'Spot', 'Hemi', 'Area', or 'Photon'
+ li = Lamp.New('Lamp', obname)
+ ob = SCENE.objects.new(li)
+ intensity = 2.0 #--todo-- -----------
+ li.setEnergy(intensity)
+ target = self.get_target(self.data)
+ color = self.get_color(self.data)
+ li.R = color[0]
+ li.G = color[1]
+ li.B = color[2]
+
+ ob.loc = tuple(self.loc)
+ transform(self.extrusion, 0, ob)
+ return ob
+
+ elif name == 'direct':
+ if settings.var['lights_on']: #if lights support activated
+ obname = settings.blocknamesmap[self.name]
+ obname = 'su_%s' %obname # create object name from block name
+ #obname = obname[:MAX_NAMELENGTH]
+ # blender: 'Lamp', 'Sun', 'Spot', 'Hemi', 'Area', or 'Photon'
+ li = Lamp.New('Sun', obname)
+ ob = SCENE.objects.new(li)
+ intensity = 2.0 #--todo-- -----------
+ li.setEnergy(intensity)
+ color = self.get_color(self.data)
+ li.R = color[0]
+ li.G = color[1]
+ li.B = color[2]
+
+ ob.loc = tuple(self.loc)
+ transform(self.extrusion, 0, ob)
+ return ob
+
+ elif settings.drawTypes['insert']: #if insert_drawType activated
+ #print 'deb:draw. settings.blocknamesmap:', settings.blocknamesmap #--------------------
+ obname = settings.blocknamesmap[self.name]
+ obname = 'in_%s' %obname # create object name from block name
+ #obname = obname[:MAX_NAMELENGTH]
+
+ # if material BYBLOCK def needed: use as placeholder a mesh-vertex instead of empty
ob = SCENE.objects.new('Empty', obname) # create a new empty_object
empty_size = 1.0 * settings.var['g_scale']
if empty_size < 0.01: empty_size = 0.01 #Blender limits (0.01-10.0)
@@ -2704,19 +3303,22 @@ class Insert: #----------------------------------------------------------------
ob.drawSize = empty_size
# get our block_def-group
- block = settings.blocks(self.blockname)
+ block = settings.blocks(self.name)
ob.DupGroup = block
ob.enableDupGroup = True
- #print 'deb:draw.block.deltaloc:', deltaloc #--------------------
- ob.loc = tuple(self.loc)
- if deltaloc:
- deltaloc = rotXY_Vec(self.rotation, deltaloc)
- #print 'deb:draw.block.loc:', deltaloc #--------------------
- ob.loc = [ob.loc[0]+deltaloc[0], ob.loc[1]+deltaloc[1], ob.loc[2]+deltaloc[2]]
- transform(self.extrusion, self.rotation, ob)
- ob.size = tuple(self.scale)
- return ob
+ if block.name.startswith('xr_'):
+ ob.name = 'xb_' + ob.name[3:]
+
+ #print 'deb:draw.block.deltaloc:', deltaloc #--------------------
+ ob.loc = tuple(self.loc)
+ if deltaloc:
+ deltaloc = rotXY_Vec(self.rotation, deltaloc)
+ #print 'deb:draw.block.loc:', deltaloc #--------------------
+ ob.loc = [ob.loc[0]+deltaloc[0], ob.loc[1]+deltaloc[1], ob.loc[2]+deltaloc[2]]
+ transform(self.extrusion, self.rotation, ob)
+ ob.size = tuple(self.scale)
+ return ob
@@ -2731,11 +3333,11 @@ class Ellipse: #---------------------------------------------------------------
if not obj.type == 'ellipse':
raise TypeError, "Wrong type %s for ellipse object!" %obj.type
self.type = obj.type
- self.data = obj.data[:]
+# self.data = obj.data[:]
# required data
- self.ratio = obj.get_type(40)[0]
- self.start_angle = obj.get_type(41)[0]
+ self.ratio = obj.get_type(40)[0] # Ratio of minor axis to major axis
+ self.start_angle = obj.get_type(41)[0] # in radians
self.end_angle = obj.get_type(42)[0]
# optional data (with defaults)
@@ -2743,11 +3345,10 @@ class Ellipse: #---------------------------------------------------------------
self.thic = getit(obj, 39, 0.0)
self.color_index = getit(obj, 62, BYLAYER)
- self.layer = getit(obj.data, 8, None)
- self.loc = self.get_loc(obj.data)
- self.major = self.get_major(obj.data)
- self.extrusion = get_extrusion(obj.data)
- self.radius = sqrt(self.major[0]**2 + self.major[0]**2 + self.major[0]**2)
+ self.layer = getit(obj, 8, None)
+ self.loc = self.get_loc(obj)
+ self.major = self.get_major(obj)
+ self.extrusion = get_extrusion(obj)
def get_loc(self, data):
@@ -2781,31 +3382,176 @@ class Ellipse: #---------------------------------------------------------------
def draw(self, settings):
"""for ELLIPSE: generate Blender_geometry.
"""
- # Generate the geometery
+ obname = 'el_%s' %self.layer # create object name from layer name
+ obname = obname[:MAX_NAMELENGTH]
+
center = self.loc
+ if True:
+ start = degrees(self.start_angle)
+ end = degrees(self.end_angle)
+ if abs(end - 360.0) < 0.00001: end = 360.0
+ ellipse_closed = False
+ if end - start == 360.0: ellipse_closed = True
+
+ else: # bug in AutoCAD_2002 dxf-exporter into r12 for ELLIPSE->POLYLINE_ARC
+ #print 'deb:calcEllipse---------:\n start=%s\n end=%s' %(self.start_angle, self.end_angle) #---------
+ if self.start_angle > pi+pi: self.start_angle %= pi+pi
+ if self.end_angle > pi+pi: self.end_angle %= pi+pi
+ if abs(self.end_angle - pi - pi) < 0.00001: self.end_angle = pi + pi
+ ellipse_closed = False
+ if abs(self.end_angle - self.start_angle) == pi + pi: ellipse_closed = True
+ test = self.start_angle % pi
+ if test < 0.001 or pi - test < 0.001: start = self.start_angle
+ else:
+ start = atan(tan(self.start_angle) * self.ratio)
+ if start < 0.0: start += pi
+ if self.start_angle > pi: start += pi
+ test = self.end_angle % pi
+ if test < 0.001 or pi - test < 0.001: end = self.end_angle
+ else:
+ end = atan(tan(self.end_angle) * self.ratio)
+ if end < 0.0: end += pi
+ if self.end_angle > pi: end += pi
+ start = degrees(start)
+ end = degrees(end)
+
+ # rotation = Angle between major and WORLDX
+ # doesnt work, couse produces always positive value: rotation = Mathutils.AngleBetweenVecs(major, WORLDX)
+ if self.major[0] == 0:
+ rotation = 90.0
+ if self.major[1] < 0: rotation += 180
+ else:
+ rotation = degrees(atan(self.major[1] / self.major[0]))
+ if self.major[0] < 0:
+ rotation += 180.0
+
+ major = Mathutils.Vector(self.major)
+ #radius = sqrt(self.major[0]**2 + self.major[1]**2 + self.major[2]**2)
+ radius = major.length
+ #print 'deb:calcEllipse:\n center, radius, start, end:\n', center, radius, start, end #---------
+
thic = set_thick(self.thic, settings)
+ width = 0.0
+ if settings.var['lines_as'] == 4: # as thin_box
+ thic = settings.var['thick_min']
+ width = settings.var['width_min']
+ elif settings.var['lines_as'] == 3: # as thin cylinder
+ cyl_rad = 0.5 * settings.var['width_min']
- if settings.var['curves_on']:
- ob = drawCurveArc(self)
- else:
- obname = 'el_%s' %self.layer # create object name from layer name
- obname = obname[:MAX_NAMELENGTH]
- me = Mesh.New(obname) # create a new mesh
- ob = SCENE.objects.new(me) # create a new mesh_object
+ elif settings.var['lines_as'] == 5: # draw ELLIPSE as curve -------------
+ arc_res = settings.var['curve_arc']
+ triples = True
+ VectorTriples = calcArc(None, radius, start, end, arc_res, triples)
+ arc = Curve.New(obname) # create new curve data
+ curve = arc.appendNurb(BezTriple.New(VectorTriples[0]))
+ if ellipse_closed:
+ for p in VectorTriples[1:-1]:
+ curve.append(BezTriple.New(p))
+ for point in curve:
+ point.handleTypes = [FREE, FREE]
+ curve.flagU = 1 # 0 sets the curve not cyclic=open
+ if settings.var['fill_on']:
+ arc.setFlag(6) # 2+4 set top and button caps
+ else:
+ arc.setFlag(arc.getFlag() & ~6) # dont set top and button caps
+ else:
+ for p in VectorTriples[1:]:
+ curve.append(BezTriple.New(p))
+ for point in curve:
+ point.handleTypes = [FREE, FREE]
+ curve.flagU = 0 # 0 sets the curve not cyclic=open
+
+ arc.setResolu(settings.var['curve_res'])
+ arc.update() #important for handles calculation
+
+ ob = SCENE.objects.new(arc) # create a new curve_object
+ ob.loc = tuple(self.loc)
+ if thic != 0.0: #hack: Blender<2.45 curve-extrusion
+ thic = thic * 0.5
+ arc.setExt1(1.0) # curve-extrusion: Blender2.45 accepts only (0.0 - 5.0)
+ ob.LocZ = thic + self.loc[2]
+ transform(self.extrusion, rotation, ob)
+ ob.SizeY *= self.ratio
+ if thic != 0.0:
+ ob.SizeZ *= abs(thic)
+ return ob
- major = Mathutils.Vector(self.major)
- #remi--todo----AngleBetweenVecs makes abs(value)!-----
- delta = Mathutils.AngleBetweenVecs(major, WORLDX)
- radius = major.length
- start = degrees(self.start_angle)
- end = degrees(self.end_angle)
+ else: # draw ELLIPSE as mesh --------------------------------------
+ if M_OBJ: obname, me, ob = makeNewObject()
+ else:
+ me = Mesh.New(obname) # create a new mesh
+ ob = SCENE.objects.new(me) # create a new mesh_object
# set a number of segments in entire circle
arc_res = settings.var['arc_res'] * sqrt(radius) / sqrt(settings.var['arc_rad'])
+
verts = calcArc(None, radius, start, end, arc_res, False)
#verts = [list(point) for point in verts]
- if thic != 0:
- len1 = len(verts)
+ if False: #--todo--: if ellipse_closed:
+ verts = verts[:-1] #list without last point/edge (cause closed curve)
+ len1 = len(verts)
+ #print 'deb:len1:', len1 #-----------------------
+ if width != 0:
+ radius_out = radius + (0.5 * width)
+ radius_in = radius - (0.5 * width)
+ if radius_in <= 0.0:
+ radius_in = settings.var['dist_min']
+ #radius_in = 0.0
+ verts_in = []
+ verts_out = []
+ for point in verts:
+ pointVec = Mathutils.Vector(point)
+ pointVec = pointVec.normalize()
+ verts_in.append(list(radius_in * pointVec)) #vertex inside
+ verts_out.append(list(radius_out * pointVec)) #vertex outside
+ verts = verts_in + verts_out
+
+ #print 'deb:verts:', verts #---------------------
+ if thic != 0:
+ thic_verts = []
+ thic_verts.extend([[point[0], point[1], point[2]+thic] for point in verts])
+ if thic < 0.0:
+ thic_verts.extend(verts)
+ verts = thic_verts
+ else:
+ verts.extend(thic_verts)
+ f_bottom = [[num, num+1, len1+num+1, len1+num] for num in xrange(len1-1)]
+ f_top = [[num, len1+num, len1+num+1, num+1] for num in xrange(len1+len1, len1+len1+len1-1)]
+ f_left = [[num, len1+len1+num, len1+len1+num+1, num+1] for num in xrange(len1-1)]
+ f_right = [[num, num+1, len1+len1+num+1, len1+len1+num] for num in xrange(len1, len1+len1-1)]
+ f_start = [[0, len1, len1+len1+len1, len1+len1]]
+ f_end = [[len1+len1-1, 0+len1-1, len1+len1+len1-1, len1+len1+len1+len1-1]]
+ faces = f_left + f_right + f_bottom + f_top + f_start + f_end
+
+ me.verts.extend(verts) # add vertices to mesh
+ me.faces.extend(faces) # add faces to the mesh
+
+ if settings.var['meshSmooth_on']: # left and right side become smooth ----------------------
+ smooth_len = len(f_left) + len(f_right)
+ for i in xrange(smooth_len):
+ me.faces[i].smooth = True
+ if settings.var['vGroup_on'] and not M_OBJ:
+ # each MeshSide becomes vertexGroup for easier material assignment ---------------------
+ replace = Blender.Mesh.AssignModes.REPLACE #or .AssignModes.ADD
+ vg_left, vg_right, vg_top, vg_bottom = [], [], [], []
+ for v in f_left: vg_left.extend(v)
+ for v in f_right: vg_right.extend(v)
+ for v in f_top: vg_top.extend(v)
+ for v in f_bottom: vg_bottom.extend(v)
+ me.addVertGroup('side.left') ; me.assignVertsToGroup('side.left', list(set(vg_left)), 1.0, replace)
+ me.addVertGroup('side.right') ; me.assignVertsToGroup('side.right', list(set(vg_right)), 1.0, replace)
+ me.addVertGroup('side.top') ; me.assignVertsToGroup('side.top', list(set(vg_top)), 1.0, replace)
+ me.addVertGroup('side.bottom'); me.assignVertsToGroup('side.bottom',list(set(vg_bottom)), 1.0, replace)
+ me.addVertGroup('side.start'); me.assignVertsToGroup('side.start', f_start[0], 1.0, replace)
+ me.addVertGroup('side.end') ; me.assignVertsToGroup('side.end', f_end[0], 1.0, replace)
+
+
+ else: # if thick=0 - draw only flat ring
+ faces = [[num, len1+num, len1+num+1, num+1] for num in xrange(len1 - 1)]
+ me.verts.extend(verts) # add vertices to mesh
+ me.faces.extend(faces) # add faces to the mesh
+
+ elif thic != 0:
thic_verts = []
thic_verts.extend([[point[0], point[1], point[2]+thic] for point in verts])
if thic < 0.0:
@@ -2815,21 +3561,28 @@ class Ellipse: #---------------------------------------------------------------
verts.extend(thic_verts)
faces = []
#print 'deb:len1:', len1 #-----------------------
- #print 'deb:verts:', verts #----------------------
+ #print 'deb:verts:', verts #---------------------
faces = [[num, num+1, num+len1+1, num+len1] for num in xrange(len1 - 1)]
- me.verts.extend(verts) # add vertices to mesh
- me.faces.extend(faces) # add faces to the mesh
+ me.verts.extend(verts) # add vertices to mesh
+ me.faces.extend(faces) # add faces to the mesh
+ if settings.var['meshSmooth_on']: # left and right side become smooth ----------------------
+ for i in xrange(len(faces)):
+ me.faces[i].smooth = True
+
else:
edges = [[num, num+1] for num in xrange(len(verts)-1)]
- me.verts.extend(verts) # add vertices to mesh
- me.edges.extend(edges) # add edges to the mesh
-
- ob.loc = tuple(center)
- ob.SizeY = self.ratio
- transform(self.extrusion, 0, ob)
+ me.verts.extend(verts) # add vertices to mesh
+ me.edges.extend(edges) # add edges to the mesh
- return ob
+ #print 'deb:calcEllipse transform rotation: ', rotation #---------
+ ob.loc = tuple(center)
+ #old ob.SizeY = self.ratio
+ transform(self.extrusion, rotation, ob)
+ #old transform(self.extrusion, 0, ob)
+ ob.SizeY *= self.ratio
+
+ return ob
@@ -2843,14 +3596,14 @@ class Face: #-----------------------------------------------------------------
if not obj.type == '3dface':
raise TypeError, "Wrong type %s for 3dface object!" %obj.type
self.type = obj.type
- self.data = obj.data[:]
+# self.data = obj.data[:]
# optional data (with defaults)
self.space = getit(obj, 67, 0)
self.color_index = getit(obj, 62, BYLAYER)
- self.layer = getit(obj.data, 8, None)
- self.points = self.get_points(obj.data)
+ self.layer = getit(obj, 8, None)
+ self.points = self.get_points(obj)
def get_points(self, data):
@@ -2897,21 +3650,24 @@ class Face: #-----------------------------------------------------------------
global activObjectName
#print 'deb:draw:face.ob IN activObjectName: ', activObjectName #---------------------
- if activObjectLayer == self.layer and settings.var['one_mesh_on']:
- obname = activObjectName
- #print 'deb:face.draw obname from activObjectName: ', obname #---------------------
- ob = Object.Get(obname) # open an existing mesh_object
- #ob = SCENE.getChildren(obname) # open an existing mesh_object
- else:
- obname = 'fa_%s' %self.layer # create object name from layer name
- obname = obname[:MAX_NAMELENGTH]
- me = Mesh.New(obname) # create a new mesh
- ob = SCENE.objects.new(me) # create a new mesh_object
- activObjectName = ob.name
- activObjectLayer = self.layer
- #print ('deb:except. new face.ob+mesh:"%s" created!' %ob.name) #---------------------
-
- me = Mesh.Get(ob.name) # open objects mesh data
+ if M_OBJ: obname, me, ob = makeNewObject()
+ else:
+ if activObjectLayer == self.layer and settings.var['one_mesh_on']:
+ obname = activObjectName
+ #print 'deb:face.draw obname from activObjectName: ', obname #---------------------
+ ob = getSceneChild(obname) # open an existing mesh_object
+ #ob = SCENE.getChildren(obname) # open an existing mesh_object
+ me = ob.getData(name_only=False, mesh=True)
+ else:
+ obname = 'fa_%s' %self.layer # create object name from layer name
+ obname = obname[:MAX_NAMELENGTH]
+ me = Mesh.New(obname) # create a new mesh
+ ob = SCENE.objects.new(me) # create a new mesh_object
+ activObjectName = ob.name
+ activObjectLayer = self.layer
+ #print ('deb:except. new face.ob+mesh:"%s" created!' %ob.name) #---------------------
+
+ #me = Mesh.Get(ob.name) # open objects mesh data
faces, edges = [], []
n = len(me.verts)
if len(self.points) == 4:
@@ -2924,7 +3680,7 @@ class Face: #-----------------------------------------------------------------
me.verts.extend(points) # add vertices to mesh
if faces: me.faces.extend(faces) # add faces to the mesh
if edges: me.edges.extend(edges) # add faces to the mesh
- if settings.var['vGroup_on']:
+ if settings.var['vGroup_on'] and not M_OBJ:
# entities with the same color build one vertexGroup for easier material assignment ---------------------
ob.link(me) # link mesh to that object
vG_name = 'color_%s' %self.color_index
@@ -2945,6 +3701,8 @@ class Face: #-----------------------------------------------------------------
#---------------------------------------------------------------------------------------
# type to object maping (sorted-dictionary for f_obiectify ONLY!, format={'key':Class} )
type_map = {
+ 'vport':Vport,
+ 'view':View,
'layer':Layer,
'block_record':BlockRecord,
'block':Block,
@@ -2952,10 +3710,11 @@ type_map = {
'point':Point,
'3dface':Face,
'line':Line,
-# 'mline':MLine,
+# 'mline':MLine,
'polyline':Polyline,
'lwpolyline':LWpolyline,
-# 'region':Region,
+ 'spline':Spline,
+# 'region':Region,
'trace':Solid,
'solid':Solid,
'text':Text,
@@ -2992,14 +3751,14 @@ def objectify(data): #---------------------------------------------------------
if item.type == 'vertex':
#print 'deb:objectify gosub Vertex--------' #-------------
v = Vertex(item)
- if pline.spline: # Bspline-curve
+ if pline.spline: # if NURBSpline-curve
# then for Blender-mesh filter only additional_vertices
# OR
# then for Blender-curve filter only spline_control_vertices
- if (v.spline and not curves_on) or (curves_on and v.splin2): #correct for real NURBS-import
- #if (v.spline and not curves_on) or (curves_on and not v.splin2): #fake for Bezier-emulation of NURBS-import
+ if (v.spline and not curves_on) or (curves_on and v.spline_c): #correct for real NURBS-import
+ #if (v.spline and not curves_on) or (curves_on and not v.spline_c): #fake for Bezier-emulation of NURBS-import
pline.points.append(v)
- elif pline.curved: # Bezier-curve
+ elif pline.curved: # if Bezier-curve
# then for Blender-mesh filter only curve_additional_vertices
# OR
# then for Blender-curve filter curve_control_vertices
@@ -3015,12 +3774,27 @@ def objectify(data): #---------------------------------------------------------
index -= 1 #so go back one step
break
objects.append(pline)
+ elif type(item) != list and item.type in ['block', 'insert']:
+ if not settings.var['block_nn'] and item.name.startswith('*X'):
+ #print 'deb:objectify item.type:"%s", item.name:"%s"' %(item.type, item.name) #------------
+ pass
+ elif settings.var['blockFilter_on'] and not settings.accepted_block(item.name):
+ pass
+ else:
+ try:
+ objects.append(type_map[item.type](item))
+ except TypeError:
+ pass
elif type(item) != list and item.type in known_types:
# proccess the object and append the resulting object
- objects.append(type_map[item.type](item))
+ try:
+ objects.append(type_map[item.type](item))
+ except TypeError:
+ pass
else:
- # we will just let the data pass un-harrased
- objects.append(item)
+ #we will just let the data pass un-harrased
+ #objects.append(item)
+ pass
index += 1
#print 'deb:objectify objects:\n', objects #------------
#print 'deb:objectify END %%%%%%%%' #------------
@@ -3039,7 +3813,7 @@ class MatColors: #-------------------------------------------------------------
the material.
"""
- def __init__(self, layersmap):
+ def __init__(self):
"""Expects a map - a dictionary mapping layer names to layers.
"""
#self.layersmap = layersmap # a dictionary of layername:layerobject
@@ -3052,24 +3826,29 @@ class MatColors: #-------------------------------------------------------------
If a layer name is provided, the color of that layer is used.
"""
- if color == None:
- color = 256 # color 256=BYLAYER
+ if color == None: color = 256 # color 256=BYLAYER
if type(color) == str: # looking for color of LAYER named "color"
#--todo---bug with ARC from ARC-T0.DXF layer="T-3DARC-1"-----
#print 'deb:color is string:--------: ', color
#try:
- #color = self.layersmap[color].color
+ #color = layersmap[color].color
#print 'deb:color=self.map[color].color:', color #------------------
#except KeyError:
#layer = Layer(name=color, color=256, frozen=False)
- #self.layersmap[color] = layer
+ #layersmap[color] = layer
#color = 0
- color = layersmap[color].color
+ if color in layersmap.keys():
+ color = layersmap[color].color
+ if color == 256: # color 256 = BYLAYER
+ #--todo-- should looking for color of LAYER
+ #if layersmap: color = layersmap[color].color
+ color = 3
if color == 0: # color 0 = BYBLOCK
#--todo-- should looking for color of paret-BLOCK
- #color = layersmap[color].color
- pass
+ #if layersmap: color = layersmap[color].color
+ color = 3
color = abs(color) # cause the value could be nagative = means the layer is turned off
+
if color not in self.colMaterials.keys():
self.add(color)
return self.colMaterials[color]
@@ -3099,7 +3878,7 @@ class MatLayers: #-------------------------------------------------------------
the material.
"""
- def __init__(self, layersmap):
+ def __init__(self):
"""Expects a map - a dictionary mapping layer names to layers.
"""
#self.layersmap = layersmap # a dictionary of layername:layer
@@ -3116,7 +3895,8 @@ class MatLayers: #-------------------------------------------------------------
layername_short = layername
if layername in layernamesmap.keys():
layername_short = layernamesmap[layername]
- colorlayername = str(color) + layername_short
+ colorlayername = layername_short
+ if color: colorlayername = str(color) + colorlayername
if colorlayername not in self.layMaterials.keys():
self.add(layername, color, colorlayername)
return self.layMaterials[colorlayername]
@@ -3130,14 +3910,17 @@ class MatLayers: #-------------------------------------------------------------
#print 'deb:MatLayers material: ', mat #----------
#global settings
#print 'deb:MatLayers material_from: ', settings.var['material_from'] #----------
- if settings.var['material_from'] == 3: mat_color = color
- elif layersmap: mat_color = layersmap[layername].color
+ if settings.var['material_from'] == 3 and color:
+ if color == 0 or color == 256: mat_color = 3
+ else: mat_color = color
+ elif layersmap and layername:
+ mat_color = layersmap[layername].color
else: mat_color = 3
#print 'deb:MatLayers color: ', color #-----------
#print 'deb:MatLayers mat_color: ', mat_color #-----------
- mat.setRGBCol(color_map[mat_color])
- mat.mode |= Material.Modes.SHADELESS
- mat.mode |= Material.Modes.WIRE
+ mat.setRGBCol(color_map[abs(mat_color)])
+ #mat.mode |= Material.Modes.SHADELESS
+ #mat.mode |= Material.Modes.WIRE
# try: mat.setMode('Shadeless', 'Wire') #work-around for 2.45rc-bug
# except: pass
self.layMaterials[colorlayername] = mat
@@ -3160,7 +3943,7 @@ class Blocks: #----------------------------------------------------------------
"""
self.blocksmap = blocksmap #a dictionary mapping block_name:block_data
self.settings = settings
- self.blocks = {} #container for blocks
+ self.blocks = {} #container for blender groups representing blocks
def __call__(self, name=None):
@@ -3179,13 +3962,36 @@ class Blocks: #----------------------------------------------------------------
def addBlock(self, name):
"""Create a new 'block group' for the block name.
"""
-
- block_def = Group.New('bl_%s' %name) # Blender groupObject contains definition of BLOCK
block = self.blocksmap[name]
+ prefix = 'bl'
+ if block.xref: prefix = 'xr'
+ blender_group = Group.New('%s_%s' %(prefix,name)) # Blender groupObject contains definition of BLOCK
+ block_def = [blender_group, block.loc]
self.settings.write("\nDrawing block:\'%s\' ..." % name)
- drawEntities(block.entities, self.settings, block_def)
+
+ if block.xref:
+ obname = 'xr_%s' %name # create object name from xref block name
+ #obname = obname[:MAX_NAMELENGTH]
+ # if material BYBLOCK def needed: use as placeholder a mesh-vertex instead of empty
+ ob = SCENE.objects.new('Empty', obname) # create a new empty_object
+ empty_size = 1.0 * settings.var['g_scale']
+ if empty_size < 0.01: empty_size = 0.01 #Blender limits (0.01-10.0)
+ elif empty_size > 10.0: empty_size = 10.0
+ ob.drawSize = empty_size
+ ob.loc = tuple(block.loc)
+ ob.properties['xref_path'] = block.path
+ ob.layers = [19]
+ insertFlag=True; blockFlag=True
+ global oblist
+ oblist.append((ob, insertFlag, blockFlag))
+ else:
+ if M_OBJ:
+ car_end()
+ car_start()
+ drawEntities(block.entities, self.settings, block_def)
+ if M_OBJ: car_end()
self.settings.write("Drawing block:\'%s\' done!" %name)
- self.blocks[name] = block_def
+ self.blocks[name] = blender_group
@@ -3219,14 +4025,23 @@ class Settings: #--------------------------------------------------------------
'0'
]
- self.var['blockFilter_on'] = False #deb:remi------------
- self.acceptedBlocks = ['BOX01',
+ self.var['groupFilter_on'] = False #deb:remi------------
+ self.acceptedLayers = ['3',
+ '0'
+ ]
+
+ #self.var['blockFilter_on'] = 0 #deb:remi------------
+ self.acceptedBlocks = ['WALL_1871',
'BOX02'
]
+ self.unwantedBlocks = ['BOX05',
+ 'BOX04'
+ ]
def update(self, keywords, drawTypes):
"""update all the important settings used by the draw functions.
+ mostly used after loading parameters from INI-file
"""
for k, v in keywords.iteritems():
@@ -3236,6 +4051,13 @@ class Settings: #--------------------------------------------------------------
self.drawTypes[t] = v
#print 'deb:settings_update drawType %s= %s' %(t, self.drawTypes[t]) #--------------
+ self.drawTypes['arc'] = self.drawTypes['line']
+ self.drawTypes['circle'] = self.drawTypes['line']
+ self.drawTypes['ellipse'] = self.drawTypes['line']
+ self.drawTypes['trace'] = self.drawTypes['solid']
+ self.drawTypes['insert'] = self.drawTypes['block']
+ #self.drawTypes['vport'] = self.drawTypes['view']
+
#print 'deb:self.drawTypes', self.drawTypes #---------------
@@ -3243,68 +4065,127 @@ class Settings: #--------------------------------------------------------------
"""Given the drawing, build dictionaries of Layers, Colors and Blocks.
"""
- #de: paßt die distance parameter an globalScale
- if self.var['g_scale'] != 1:
+ global oblist
+ #adjust the distance parameter to globalScale
+ if self.var['g_scale'] != 1.0:
self.var['dist_min'] = self.var['dist_min'] / self.var['g_scale']
self.var['thick_min'] = self.var['thick_min'] / self.var['g_scale']
self.var['width_min'] = self.var['width_min'] / self.var['g_scale']
self.var['arc_rad'] = self.var['arc_rad'] / self.var['g_scale']
+ self.g_origin = Mathutils.Vector(self.var['g_originX'], self.var['g_originY'], self.var['g_originZ'])
+
# First sort out all the section_items
sections = dict([(item.name, item) for item in drawing.data])
# The section:header may be omited
if 'header' in sections.keys():
- self.write("Found section:header!")
+ self.write("found section:header")
else:
self.write("File contains no section:header!")
+ if self.var['optimization'] == 0: self.var['one_mesh_on'] = 0
# The section:tables may be partialy or completely missing.
self.layersTable = False
- self.colMaterials = MatColors({}) #A container for dxf-color based materials
- self.layMaterials = MatLayers({}) #A container for dxf-layer based materials
+ self.colMaterials = MatColors() #A container for dxf-color based materials
+ self.layMaterials = MatLayers() #A container for dxf-layer based materials
#self.collayMaterials = MatColLayers({}) #A container for dxf-color+layer based materials
global layersmap, layernamesmap
layersmap, layernamesmap = {}, {}
if 'tables' in sections.keys():
- self.write("Found section:tables!")
- # First sort out all the tables
- tables = dict([(item.name, item) for item in sections["tables"].data])
- if 'layer' in tables.keys():
- self.write("Found table:layers!")
- self.layersTable = True
+ self.write("found section:tables")
+ views, vports, layers = False, False, False
+ for table in drawing.tables.data:
+ if table.name == 'layer':
+ self.write("found table:layers")
+ layers = table
+ elif table.name == 'view':
+ print "found table:view"
+ views = table
+ elif table.name == 'vport':
+ print "found table:vport"
+ vports = table
+ if layers: #----------------------------------
# Read the layers table and get the layer colors
- layersmap, layernamesmap = getLayersmap(drawing)
- self.colMaterials = MatColors(layersmap)
- self.layMaterials = MatLayers(layersmap)
+ layersmap, layernamesmap = getLayersmap(layers)
+ #self.colMaterials = MatColors()
+ #self.layMaterials = MatLayers()
else:
self.write("File contains no table:layers!")
+
+
+ if views: #----------------------------------
+ if self.var['views_on']:
+ for item in views.data:
+ if type(item) != list and item.type == 'view':
+ #print 'deb:settings_valid views dir(item)=', dir(item) #-------------
+ #print 'deb:settings_valid views item=', item #-------------
+ ob = item.draw(self)
+ #viewsmap[item.name] = [item.length]
+ #--todo-- add to obj_list for global.Scaling
+ insertFlag, blockFlag = False, False
+ oblist.append((ob, insertFlag, blockFlag))
+
+ else:
+ self.write("File contains no table:views!")
+
+
+ if vports: #----------------------------------
+ if self.var['views_on']:
+ for item in vports.data:
+ if type(item) != list and item.type == 'vport':
+ #print 'deb:settings_valid views dir(item)=', dir(item) #-------------
+ #print 'deb:settings_valid views item=', item #-------------
+ ob = item.draw(self)
+ #viewsmap[item.name] = [item.length]
+ #--todo-- add to obj_list for global.Scaling
+ insertFlag, blockFlag = False, False
+ oblist.append((ob, insertFlag, blockFlag))
+ else:
+ self.write("File contains no table:vports!")
+
+
else:
self.write("File contains no section:tables!")
self.write("File contains no table:layers!")
+
# The section:blocks may be omited
if 'blocks' in sections.keys():
- self.write("Found section:blocks!")
+ self.write("found section:blocks")
# Read the block definitions and build our block object
- if self.drawTypes['insert']: #if drawing of type 'Insert' activated
- blocksmap, self.blocknamesmap, self.obj_number = getBlocksmap(drawing) #Build a dictionary of blockname:block_data pairs
+ if self.drawTypes['insert']: #if support for entity type 'Insert' is activated
+ #Build a dictionary of blockname:block_data pairs
+ blocksmap, obj_number = getBlocksmap(drawing, layersmap, self.var['layFrozen_on'])
+ self.obj_number += obj_number
+ self.blocknamesmap = getBlocknamesmap(blocksmap)
self.blocks = Blocks(blocksmap, self) # initiates container for blocks_data
-
- #print 'deb: self.obj_number', self.obj_number #----------
+ self.usedBlocks = blocksmap.keys()
+ #print 'deb:settings_valid self.usedBlocks', self.usedBlocks #----------
+ else:
+ self.write("ignored, because support for BLOCKs is turn off!")
+ #print 'deb:settings_valid self.obj_number', self.obj_number #----------
else:
self.write("File contains no section:blocks!")
self.drawTypes['insert'] = False
# The section:entities
if 'entities' in sections.keys():
- self.write("Found section:entities!")
-
+ self.write("found section:entities")
self.obj_number += len(drawing.entities.data)
- #print 'deb: self.obj_number', self.obj_number #----------
self.obj_number = 1.0 / self.obj_number
+ def accepted_block(self, name):
+ if name not in self.usedBlocks: return False
+ if name in self.unwantedBlocks: return False
+ elif name in self.acceptedBlocks: return True
+ #elif (name.find('*X')+1): return False
+ #elif name.startswith('3'): return True
+ #elif name.endswith('H'): return False
+ return True
+
+
def write(self, text, newline=True):
"""Wraps the built-in print command in a optimization check.
"""
@@ -3334,7 +4215,7 @@ class Settings: #--------------------------------------------------------------
"""Given a layer name, and return its visible status.
"""
# if layer is off then color_index is negative
- if layersmap[layername].color < 0: return True
+ if layersmap and layersmap[layername].color < 0: return True
#print 'deb:layer_isOff: layer is ON' #---------------
return False
@@ -3342,50 +4223,58 @@ class Settings: #--------------------------------------------------------------
def layer_isFrozen(self, layername): # no more used -------
"""Given a layer name, and return its frozen status.
"""
- if layersmap[layername].frozen: return True
+ if layersmap and layersmap[layername].frozen: return True
#print 'deb:layer_isFrozen: layer is not FROZEN' #---------------
return False
def analyzeDXF(dxfFile): #---------------------------------------
- """list LAYER and BLOCK dependences into textfile
+ """list statistics about LAYER and BLOCK dependences into textfile.INF
"""
Window.WaitCursor(True) # Let the user know we are thinking
- print 'start reading DXF file: %s.' % dxfFile
+ print 'reading DXF file: %s.' % dxfFile
time1 = Blender.sys.time() #time marker1
drawing = readDXF(dxfFile, objectify)
- print 'finished reading DXF file in %.4f sec.' % (Blender.sys.time()-time1)
- Window.WaitCursor(False)
+ print 'finish reading in %.4f sec.' % (Blender.sys.time()-time1)
# First sort out all the section_items
sections = dict([(item.name, item) for item in drawing.data])
# The section:header may be omited
- if 'header' in sections.keys(): print "Found section:header!"
+ if 'header' in sections.keys(): print "found section:header"
else: print "File contains no section:header!"
# The section:tables may be partialy or completely missing.
layersTable = False
global layersmap
layersmap = {}
+ viewsmap = {}
+ vportsmap = {}
+ layersmap_str = '#File contains no table:layers!'
+ viewsmap_str = '#File contains no table:views!'
+ vportsmap_str = '#File contains no table:vports!'
if 'tables' in sections.keys():
- print "Found section:tables!"
+ print "found section:tables"
+ views, vports, layers = False, False, False
for table in drawing.tables.data:
if table.name == 'layer':
- print "Found table:layers!"
+ print "found table:layers"
layers = table
- break
- if layers:
- layersmap = {}
+ elif table.name == 'view':
+ print "found table:view"
+ views = table
+ elif table.name == 'vport':
+ print "found table:vport"
+ vports = table
+ if layers: #----------------------------------
for item in layers.data:
if type(item) != list and item.type == 'layer':
#print dir(item)
layersmap[item.name] = [item.color, item.frozen]
#print 'deb:analyzeDXF: layersmap=' , layersmap #-------------
- layersmap_str = '#list of LAYERs: layername, layercolor, frozen\n'
-
+ layersmap_str = '#list of LAYERs: name, color, frozen_status ---------------------------\n'
key_list = layersmap.keys()
key_list.sort()
for key in key_list:
@@ -3397,58 +4286,119 @@ def analyzeDXF(dxfFile): #---------------------------------------
#print 'deb:analyzeDXF: layersmap_str=\n' , layersmap_str #-------------
else:
print "File contains no table:layers!"
+
+ if views: #----------------------------------
+ for item in views.data:
+ if type(item) != list and item.type == 'view':
+ #print dir(item)
+ viewsmap[item.name] = [item.length]
+ #print 'deb:analyzeDXF: viewsmap=' , viewsmap #-------------
+ viewsmap_str = '#list of VIEWs: name, focus_length ------------------------------------\n'
+ key_list = viewsmap.keys()
+ key_list.sort()
+ for key in key_list:
+ #for view_name, view_data in viewsmap.iteritems():
+ view_name, view_data = key, viewsmap[key]
+ view_str = '\'%s\': length=%s' %(view_name,view_data[0])#-------------
+ #if view_data[1]: view_str += ', something'
+ viewsmap_str += view_str + '\n'
+ #print 'deb:analyzeDXF: layersmap_str=\n' , layersmap_str #-------------
+ else:
+ print "File contains no table:views!"
+
+ if vports: #----------------------------------
+ for item in vports.data:
+ if type(item) != list and item.type == 'vport':
+ #print dir(item)
+ vportsmap[item.name] = [item.length]
+ #print 'deb:analyzeDXF: vportsmap=' , vportsmap #-------------
+ vportsmap_str = '#list of VPORTs: name, focus_length -----------------------------------\n'
+ key_list = vportsmap.keys()
+ key_list.sort()
+ for key in key_list:
+ #for vport_name, vport_data in vportsmap.iteritems():
+ vport_name, vport_data = key, vportsmap[key]
+ vport_str = '\'%s\': length=%s' %(vport_name,vport_data[0])#-------------
+ #if vport_data[1]: vport_str += ', something'
+ vportsmap_str += vport_str + '\n'
+ #print 'deb:analyzeDXF: vportsmap_str=\n' , vportsmap_str #-------------
+ else:
+ print "File contains no table:vports!"
+
else:
print "File contains no section:tables!"
- print "File contains no table:layers!"
+ print "File contains no tables:layers,views,vports!"
# The section:blocks may be omited
if 'blocks' in sections.keys():
- print "Found section:blocks!"
+ print "found section:blocks"
blocksmap = {}
for item in drawing.blocks.data:
#print 'deb:getBlocksmap item=' ,item #--------
#print 'deb:getBlocksmap item.entities=' ,item.entities #--------
#print 'deb:getBlocksmap item.entities.data=' ,item.entities.data #--------
if type(item) != list and item.type == 'block':
- insertList = []
+ xref = False
+ if item.xref: xref = True
+ childList = []
+ used = False
for item2 in item.entities.data:
if type(item2) != list and item2.type == 'insert':
- #print dir(item2)
- item2str = [item2.blockname, item2.layer, item2.color_index, item2.scale, item2.space]
- insertList.append(item2str)
- try:
- blocksmap[item.name] = insertList
- except KeyError:
- # annon block
- print 'Cannot map "%s" - "%s" as Block!' %(item.name, item)
+ #print 'deb:getBlocksmap dir(item2)=', dir(item2) #----------
+ item2str = [item2.name, item2.layer, item2.color_index, item2.scale, item2.space]
+ childList.append(item2str)
+ try: blocksmap[item.name] = [used, childList, xref]
+ except KeyError: print 'Cannot map "%s" - "%s" as Block!' %(item.name, item)
#print 'deb:analyzeDXF: blocksmap=' , blocksmap #-------------
- blocksmap_str = '#list of BLOCKs: child, layer, color, scale, space\n'
+
+ for item2 in drawing.entities.data:
+ if type(item2) != list and item2.type == 'insert':
+ if not layersmap or (layersmap and not layersmap[item2.layer][1]): #if insert_layer is not frozen
+ blocksmap[item2.name][0] = True # marked as world used BLOCK
+
+ key_list = blocksmap.keys()
+ key_list.reverse()
+ for key in key_list:
+ if blocksmap[key][0]: #if used
+ for child in blocksmap[key][1]:
+ if not layersmap or (layersmap and not layersmap[child[1]][1]): #if insert_layer is not frozen
+ blocksmap[child[0]][0] = True # marked as used BLOCK
+
+ blocksmap_str = '#list of BLOCKs: name:(unused)(xref) -[child_name, layer, color, scale, space]-------\n'
key_list = blocksmap.keys()
key_list.sort()
for key in key_list:
#for block_name, block_data in blocksmap.iteritems():
block_name, block_data = key, blocksmap[key]
- block_str = '\''+block_name + '\':\n' #-------------
- blocksmap_str += block_str
+ block_str = '\'%s\': ' %(block_name) #-------------
+ used = '(unused)'
+ if block_data[0]: used = ''
+# else: used = '(unused)'
+ xref = ''
+ if block_data[2]: xref = '(xref)'
+ blocksmap_str += block_str + used + xref +'\n'
if block_data:
- for block_item in block_data:
+ for block_item in block_data[1]:
block_data_str = ' - %s\n' %block_item
blocksmap_str += block_data_str
#print 'deb:analyzeDXF: blocksmap_str=\n' , blocksmap_str #-------------
else:
+ blocksmap_str = '#File contains no section:blocks!'
print "File contains no section:blocks!"
- output_str = '%s\n%s' %(layersmap_str, blocksmap_str)
- infFile = dxfFile[:-4] + '_DXF.inf' # replace last char:'.dxf' with '.INF'
+ Window.WaitCursor(False)
+ output_str = '%s\n%s\n%s\n%s' %(viewsmap_str, vportsmap_str, layersmap_str, blocksmap_str)
+ infFile = dxfFile[:-4] + '_DXF.INF' # replace last char:'.dxf' with '_DXF.inf'
try:
f = file(infFile, 'w')
- f.write(INFFILE_HEADER + '\n# this is a comment line\n')
+ f.write(INFFILE_HEADER + '\n# this is a comment line\n\n')
f.write(output_str)
f.close()
- Draw.PupMenu('DXF importer: INF-file: Done!%t|see listing of DXF-model saved in:|' + '\'%s\'' %infFile)
+ Draw.PupMenu('DXF importer: report saved in INF-file:%t|' + '\'%s\'' %infFile)
except:
- Draw.PupMenu('DXF importer: INF-file: Error!%t|failure by writing to ' + '\'%s\'|no listings saved!' %infFile)
-
+ Draw.PupMenu('DXF importer: ERROR by writing report in INF-file:%t|' + '\'%s\'' %infFile)
+ finally:
+ f.close()
@@ -3456,6 +4406,7 @@ def analyzeDXF(dxfFile): #---------------------------------------
def main(dxfFile): #---------------#############################-----------
#print 'deb:filename:', filename #--------------
global SCENE
+ global oblist
editmode = Window.EditMode() # are we in edit mode? If so ...
if editmode:
Window.EditMode(0) # leave edit mode before
@@ -3467,17 +4418,9 @@ def main(dxfFile): #---------------#############################-----------
cur_COUNTER = 0
try:
- print "Getting settings..."
- global GUI_A, GUI_B
- if GUI_A['g_scale_on'].val:
- if GUI_A['g_scale_as'].val == 6: #scale inches to meters
- GUI_A['g_scale'].val = 0.02540
- elif GUI_A['g_scale_as'].val == 7: #scale feets to meters
- GUI_A['g_scale'].val = 0.30480
- elif GUI_A['g_scale_as'].val == 8: #scale yards to meters
- GUI_A['g_scale'].val = 0.91440
- else: GUI_A['g_scale'].val = 10.0 ** int(GUI_A['g_scale_as'].val)
- else:
+ #print "Getting settings..."
+ global GUI_A, GUI_B, g_scale_as
+ if not GUI_A['g_scale_on'].val:
GUI_A['g_scale'].val = 1.0
keywords = {}
@@ -3505,45 +4448,53 @@ def main(dxfFile): #---------------#############################-----------
#print 'deb: dxfFile file: ', dxfFile #----------------------
if dxfFile.lower().endswith('.dxf') and sys.exists(dxfFile):
Window.WaitCursor(True) # Let the user know we are thinking
- print 'start reading DXF file: %s.' % dxfFile
+ print 'reading file: %s.' % dxfFile
time1 = Blender.sys.time() #time marker1
drawing = readDXF(dxfFile, objectify)
- print 'finished reading DXF file in %.4f sec.' % (Blender.sys.time()-time1)
+ print 'reading finished in %.4f sec.' % (Blender.sys.time()-time1)
Window.WaitCursor(False)
else:
- if UI_MODE: Draw.PupMenu('DXF importer: EXIT----------!%t| no valid DXF-file selected!')
- print "DXF importer: error, no DXF-file selected. Abort!"
+ if UI_MODE: Draw.PupMenu('DXF importer: Alert!%t| no valid DXF-file selected!')
+ print "DXF importer: Alert! - no valid DXF-file selected."
Window.WaitCursor(False)
if editmode: Window.EditMode(1) # and put things back how we fond them
return None
- settings.validate(drawing)
+ # Draw all the know entity types in the current scene
+ oblist = [] # a list of all created AND linked objects for final f_globalScale
+ time2 = Blender.sys.time() #time marker2
Window.WaitCursor(True) # Let the user know we are thinking
settings.write("\n\nDrawing entities...")
- # Draw all the know entity types in the current scene
- global oblist
- oblist = [] # a list of all created AND linked objects for final f_globalScale
- time2 = Blender.sys.time() #time marker2
+ settings.validate(drawing)
+
+ global activObjectLayer, activObjectName
+ activObjectLayer, activObjectName = None, None
+
+ if M_OBJ: car_init()
drawEntities(drawing.entities, settings)
#print 'deb:drawEntities after: oblist:', oblist #-----------------------
+ if M_OBJ: car_end()
if oblist: # and settings.var['g_scale'] != 1:
globalScale(oblist, settings.var['g_scale'])
- # Set the visable layers
+ # Set visibility for all layers on all View3d
+ #Window.ViewLayers([i+1 for i in range(18)]) # for 2.45
SCENE.setLayers([i+1 for i in range(18)])
SCENE.update(1)
- #Blender.Redraw(-1)
SCENE.objects.selected = [i[0] for i in oblist] #select only the imported objects
#SCENE.objects.selected = SCENE.objects #select all objects in current scene
Blender.Redraw()
time_text = Blender.sys.time() - time2
Window.WaitCursor(False)
- message = 'DXF Import to Blender: done in %.4f sec. --------------------' % time_text
+ if settings.var['paper_space_on']: space = 'from paper space'
+ else: space = 'from model space'
+ ob_len = len(oblist)
+ message = ' %s objects imported %s in %.4f sec. -----DONE-----' % (ob_len, space, time_text)
settings.progress(1.0/settings.obj_number, 'DXF import done!')
print message
#settings.write(message)
@@ -3561,16 +4512,15 @@ def getOCS(az): #--------------------------------------------------------------
"""An implimentation of the Arbitrary Axis Algorithm.
"""
#decide if we need to transform our coords
- if az[0] == 0 and az[1] == 0:
- if az[2] == 1.0:
+ #if az[0] == 0 and az[1] == 0:
+ if abs(az[0]) < 0.00001 and abs(az[1]) < 0.00001:
+ if az[2] > 0.0:
return False
- elif az[2] == -1.0:
+ elif az[2] < 0.0:
ax = Mathutils.Vector(-1.0, 0, 0)
ay = Mathutils.Vector(0, 1.0, 0)
az = Mathutils.Vector(0, 0, -1.0)
return ax, ay, az
- #elif abs(az[0]) < 0.0001 and abs(az[1]) < 0.0001:
- # return False
az = Mathutils.Vector(az)
@@ -3625,60 +4575,94 @@ def rotXY_Vec(rotation, vec): #------------------------------------------------
-def getLayersmap(drawing): #------------------------------------------------------
- """Build two dictionaries: 1.layername:layer pairs and 2.layername:layername_short
+def getLayersmap(dxflayers): #------------------------------------------------------
+ """Build two dictionaries: 1.layername:layer object, and 2.layername:layername_short
+ gets set of layers from TABLES SECTION LAYERS
"""
- tables = drawing.tables
- for table in tables.data:
- if table.name == 'layer':
- layers = table
- break
layersmap = {}
layernamesmap = {}
- for item in layers.data:
+ for item in dxflayers.data:
if type(item) != list and item.type == 'layer':
layersmap[item.name] = item
layername_short = item.name[:MAX_NAMELENGTH-1]
i = 0 #sufix for layernames cause Blender-objectnames-limits
while layername_short in layernamesmap.keys():
i += 1
- suffix = str(i)
+ suffix = str(i) #--todo--set zero-leading number format
layername_short = layername_short[:-2] + suffix
layernamesmap[item.name] = layername_short
- return layersmap, layernamesmap
+ #print 'deb:getLayersmap layersmap:\n', layersmap #------------
+ #print 'deb:getLayersmap layernamesmap:\n', layernamesmap #------------
+ return layersmap, layernamesmap
-def getBlocksmap(drawing): #--------------------------------------------------------
- """Build a dictionary of blockname:block_data pairs and 2.blockname:blockname_short pairs
+
+def getBlocksmap(drawing, layersmap, layFrozen_on=False): #--------------------------------------------------------
+ """Build a dictionary of blockname:block_data pairs
"""
- blocksmap = {}
- blocksmap_short = {}
- blocknamesmap = {}
- obj_number = 0
+ usedblocks = {}
for item in drawing.blocks.data:
- #print 'deb:getBlocksmap item=' ,item #--------
- #print 'deb:getBlocksmap item.entities=' ,item.entities #--------
- #print 'deb:getBlocksmap item.entities.data=' ,item.entities.data #--------
+ #print 'deb:getBlocksmap item=%s\n i.entities=%s\n i.data=%s' %(item,item.entities,item.entities.data)
if type(item) != list and item.type == 'block':
+ childList = []
+ used = False
+ for item2 in item.entities.data:
+ if type(item2) != list and item2.type == 'insert':
+ #print 'deb:getBlocksmap dir(item2)=', dir(item2) #----------
+ item2str = [item2.name, item2.layer]
+ childList.append(item2str)
+ try: usedblocks[item.name] = [used, childList]
+ except KeyError: print 'Cannot map "%s" - "%s" as Block!' %(item.name, item)
+ #print 'deb:getBlocksmap: usedblocks=' , usedblocks #-------------
+ #print 'deb:getBlocksmap: layersmap=' , layersmap #-------------
+
+ for item in drawing.entities.data:
+ if type(item) != list and item.type == 'insert':
+ if not layersmap or (not layersmap[item.layer].frozen or layFrozen_on): #if insert_layer is not frozen
+ try: usedblocks[item.name][0] = True
+ except: pass
+
+ key_list = usedblocks.keys()
+ key_list.reverse()
+ for key in key_list:
+ if usedblocks[key][0]: #if parent used, then set used also all child blocks
+ for child in usedblocks[key][1]:
+ if not layersmap or (layersmap and not layersmap[child[1]].frozen): #if insert_layer is not frozen
+ usedblocks[child[0]][0] = True # marked as used BLOCK
+
+ usedblocks = [i for i in usedblocks.keys() if usedblocks[i][0]]
+ #print 'deb:getBlocksmap: usedblocks=' , usedblocks #-------------
+ obj_number = 0
+ blocksmap = {}
+ for item in drawing.blocks.data:
+ if type(item) != list and item.type == 'block' and item.name in usedblocks:
+ #if item.name.startswith('*X'): #--todo--
obj_number += len(item.entities.data)
- try:
- blocksmap[item.name] = item
- except KeyError:
- # annon block
- print 'Cannot map "%s" - "%s" as Block!' %(item.name, item)
-
- blockname_short = item.name[:MAX_NAMELENGTH-1]
- i = 0 #sufix for blockname cause Blender-objectnamelength-limit
- while blockname_short in blocknamesmap.keys():
- i += 1
- suffix = str(i)
- blockname_short = blockname_short[:-2] + suffix
- blocknamesmap[item.name] = blockname_short
+ try: blocksmap[item.name] = item
+ except KeyError: print 'Cannot map "%s" - "%s" as Block!' %(item.name, item)
+
- return blocksmap, blocknamesmap, obj_number
+ #print 'deb:getBlocksmap: blocksmap:\n', blocksmap #------------
+ return blocksmap, obj_number
+def getBlocknamesmap(blocksmap): #--------------------------------------------------------
+ """Build a dictionary of blockname:blockname_short pairs
+ """
+ #print 'deb:getBlocknamesmap blocksmap:\n', blocksmap #------------
+ blocknamesmap = {}
+ for n in blocksmap.keys():
+ blockname_short = n[:MAX_NAMELENGTH-1]
+ i = 0 #sufix for blockname cause Blender-objectnamelength-limit
+ while blockname_short in blocknamesmap.keys():
+ i += 1
+ suffix = str(i)
+ blockname_short = blockname_short[:-2] + suffix
+ blocknamesmap[n] = blockname_short
+ #print 'deb:getBlocknamesmap blocknamesmap:\n', blocknamesmap #------------
+ return blocknamesmap
+
def drawEntities(entities, settings, block_def=None): #----------------------------------------
"""Draw every kind of thing in the entity list.
@@ -3688,7 +4672,8 @@ def drawEntities(entities, settings, block_def=None): #------------------------
for _type in type_map.keys():
#print 'deb:drawEntities_type:', _type #------------------
# for each known type get a list of that type and call the associated draw function
- drawer(_type, entities.get_type(_type), settings, block_def)
+ entities_type = entities.get_type(_type)
+ if entities_type: drawer(_type, entities_type, settings, block_def)
def drawer(_type, entities, settings, block_def): #------------------------------------------
@@ -3696,6 +4681,7 @@ def drawer(_type, entities, settings, block_def): #----------------------------
If 'block_def': the entities are to be added to the Blender 'group'.
"""
+ global layersmap, layersmapshort
#print 'deb:drawer _type, entities:\n ', _type, entities #-----------------------
if entities:
@@ -3729,6 +4715,21 @@ def drawer(_type, entities, settings, block_def): #----------------------------
#entities = [entity for entity in entities if entity.layer[0] in ['M','3','0'] and not entity.layer.endswith('H')]
entities = [entity for entity in entities if entity.layer in settings.acceptedLayers]
+ # patch for incomplete layer table in HL2-DXF-files
+ if layersmap:
+ for entity in entities:
+ oblayer = entity.layer
+ if oblayer not in layersmap.keys():
+ layer_obj = Layer(None, name=oblayer)
+ layersmap[oblayer] = layer_obj
+ layername_short = oblayer[:MAX_NAMELENGTH-1]
+ i = 0 #sufix for layernames cause Blender-objectnames-limits
+ while layername_short in layernamesmap.keys():
+ i += 1
+ suffix = str(i) #--todo--set zero-leading number format
+ layername_short = layername_short[:-2] + suffix
+ layernamesmap[oblayer] = layername_short
+
# filtering only objects on not-frozen layers
if layersmap and not settings.var['layFrozen_on']:
entities = [entity for entity in entities if not layersmap[entity.layer].frozen]
@@ -3756,14 +4757,21 @@ def drawer(_type, entities, settings, block_def): #----------------------------
if cur_temp == show_progress:
settings.progress(cur_COUNTER, message)
cur_temp = 0
- #print 'deb:drawer show_progress=',show_progress #-----------------------
+ #print 'deb:drawer show_progress=',show_progress #----------------
# get the layer group (just to make things a little cleaner)
if settings.var['group_bylayer_on'] and not block_def:
group = getGroup('l:%s' % layernamesmap[entity.layer])
- if _type == 'insert': #---- INSERT and MINSERT=array ------------------------
+ if _type == 'insert': #---- INSERT and MINSERT=array --------------------
+ if not settings.var['block_nn'] and entity.name.startswith('*X'): #---- support for noname BLOCKs
+ #print 'deb:drawer entity.name:', entity.name #------------
+ continue
+ elif settings.var['blockFilter_on'] and not settings.accepted_block(entity.name):
+ continue
+
#print 'deb:insert entity.loc:', entity.loc #----------------
+ insertFlag = True
columns = entity.columns[0]
coldist = entity.columns[1]
rows = entity.rows[0]
@@ -3776,23 +4784,44 @@ def drawer(_type, entities, settings, block_def): #----------------------------
deltaloc[1] = row * rowdist
#print 'deb:insert col=%s, row=%s,deltaloc=%s' %(col, row, deltaloc) #------
ob = entity.draw(settings, deltaloc) #-----draw BLOCK----------
+ if block_def:
+ blockFlag = True
+ bl_loc = block_def[1]
+ ob.loc = [ob.loc[0]-bl_loc[0],ob.loc[1]-bl_loc[1],ob.loc[2]-bl_loc[2]]
+ else: blockFlag = False
setObjectProperties(ob, group, entity, settings, block_def)
if ob:
if settings.var['optimization'] <= settings.MIN:
- if settings.var['g_scale'] != 1: globalScaleOne(ob, True, settings.var['g_scale'])
+ #if settings.var['g_origin_on'] and not block_def: ob.loc = Mathutils.Vector(ob.loc) + settings.g_origin
+ if settings.var['g_scale_on']: globalScaleOne(ob, insertFlag, blockFlag, settings.var['g_scale'])
settings.redraw()
- else: oblist.append((ob, True))
+ else: oblist.append((ob, insertFlag, blockFlag))
else: #---draw entities except BLOCKs/INSERTs---------------------
+ insertFlag = False
alt_obname = activObjectName
ob = entity.draw(settings)
- if ob and ob.name != alt_obname:
- setObjectProperties(ob, group, entity, settings, block_def)
- if settings.var['optimization'] <= settings.MIN:
- if settings.var['g_scale'] != 1: globalScaleOne(ob, False, settings.var['g_scale'])
- settings.redraw()
- else: oblist.append((ob, False))
-
+ if ob:
+ if M_OBJ and ob.type=='Mesh': #'Curve', 'Text'
+ if block_def:
+ blockFlag = True
+ bl_loc = block_def[1]
+ ob.loc = [ob.loc[0]-bl_loc[0],ob.loc[1]-bl_loc[1],ob.loc[2]-bl_loc[2]]
+ car_nr()
+
+ elif ob.name != alt_obname:
+ if block_def:
+ blockFlag = True
+ bl_loc = block_def[1]
+ ob.loc = [ob.loc[0]-bl_loc[0],ob.loc[1]-bl_loc[1],ob.loc[2]-bl_loc[2]]
+ else: blockFlag = False
+ setObjectProperties(ob, group, entity, settings, block_def)
+ if settings.var['optimization'] <= settings.MIN:
+ #if settings.var['g_origin_on'] and not block_def: ob.loc = Mathutils.Vector(ob.loc) + settings.g_origin
+ if settings.var['g_scale_on']: globalScaleOne(ob, insertFlag, blockFlag, settings.var['g_scale'])
+ settings.redraw()
+ else: oblist.append((ob, insertFlag, blockFlag))
+
#print 'deb:Finished drawing:', entities[0].type #------------------------
message = "\nDrawing dxf\'%ss\' done!" % _type
settings.write(message, True)
@@ -3806,20 +4835,32 @@ def globalScale(oblist, SCALE): #----------------------------------------------
"""
#print 'deb:globalScale.oblist: ---------%\n', oblist #---------------------
for l in oblist:
- ob, insertFlag = l[0], l[1]
- globalScaleOne(ob, insertFlag, SCALE)
+ ob, insertFlag, blockFlag = l[0], l[1], l[2]
+ globalScaleOne(ob, insertFlag, blockFlag, SCALE)
-def globalScaleOne(ob, insertFlag, SCALE): #---------------------------------------------------------
+def globalScaleOne(ob, insertFlag, blockFlag, SCALE): #---------------------------------------------------------
"""Global_scale imported object.
"""
#print 'deb:globalScaleOne ob: ', ob #---------------------
+ if settings.var['g_origin_on'] and not blockFlag:
+ ob.loc = Mathutils.Vector(ob.loc) + settings.g_origin
+
SCALE_MAT= Mathutils.Matrix([SCALE,0,0,0],[0,SCALE,0,0],[0,0,SCALE,0],[0,0,0,1])
- if insertFlag: # by BLOCKs/INSERTs only insert-point must be scaled------------
+ if insertFlag: # by BLOCKs/INSERTs only insert-point coords must be scaled------------
ob.loc = Mathutils.Vector(ob.loc) * SCALE_MAT
else: # entire scaling for all other imported objects ------------
- ob.setMatrix(ob.matrixWorld*SCALE_MAT)
-
+ if ob.type == 'Mesh':
+ me = ob.getData(name_only=False, mesh=True)
+ #me = Mesh.Get(ob.name)
+ # set centers of all objects in (0,0,0)
+ #me.transform(ob.matrixWorld*SCALE_MAT)
+ #ob.loc = Mathutils.Vector([0,0,0])
+ # preseve centers of all objects
+ me.transform(SCALE_MAT)
+ ob.loc = Mathutils.Vector(ob.loc) * SCALE_MAT
+ else: #--todo-- also for curves: neutral scale factor after import
+ ob.setMatrix(ob.matrixWorld*SCALE_MAT)
def setObjectProperties(ob, group, entity, settings, block_def): #-----------------------
@@ -3835,7 +4876,7 @@ def setObjectProperties(ob, group, entity, settings, block_def): #-------------
setGroup(group, ob) # if object belongs to group
if block_def: # if object belongs to BLOCK_def - Move it to layer nr19
- setGroup(block_def, ob)
+ setGroup(block_def[0], ob)
#print 'deb:setObjectProperties \'%s\' set to block_def_group!' %ob.name #---------
ob.layers = [19]
else:
@@ -3843,7 +4884,7 @@ def setObjectProperties(ob, group, entity, settings, block_def): #-------------
ob.layers = [settings.var['target_layer']]
# Set material for any objects except empties
- if ob.type != 'Empty':
+ if ob.type != 'Empty' and settings.var['material_on']:
setMaterial_from(entity, ob, settings, block_def)
# Set the visibility
@@ -3884,12 +4925,13 @@ def setMaterial_from(entity, ob, settings, block_def): #-----------------------
- controlled by settings.var['material_from']
"""
if settings.var['material_from'] == 1: # 1= material from color
- if entity.color_index == BYLAYER:
+ if entity.color_index == BYLAYER or entity.color_index == 256:
mat = settings.colMaterials(entity.layer)
- elif entity.color_index == BYBLOCK:
+ elif entity.color_index == BYBLOCK or entity.color_index == 0:
#--todo-- looking for block.color_index
#mat = settings.colMaterials(block.color_index)
- mat = settings.colMaterials(entity.color_index)
+ #if block_def: mat = settings.colMaterials(block_def[2])
+ mat = settings.colMaterials(3)
else:
mat = settings.colMaterials(entity.color_index)
@@ -3910,10 +4952,11 @@ def setMaterial_from(entity, ob, settings, block_def): #-----------------------
mat = Material.Get('dxf-neutral')
except:
mat = Material.New('dxf-neutral')
- mat.mode |= Material.Modes.SHADELESS
- mat.mode |= Material.Modes.WIRE
-# try:mat.setMode('Shadeless', 'Wire') #work-around for 2.45rc1-bug
-# except: pass
+ mat.setRGBCol(color_map[3])
+ try:mat.setMode('Shadeless', 'Wire') #work-around for 2.45rc1-bug
+ except:
+ mat.mode |= Material.Modes.SHADELESS #
+ mat.mode |= Material.Modes.WIRE
try:
#print 'deb:material mat:', mat #-----------
ob.setMaterials([mat]) #assigns Blender-material to object
@@ -4205,15 +5248,19 @@ EVENT_START = 2
EVENT_REDRAW = 3
EVENT_LOAD_INI = 4
EVENT_SAVE_INI = 5
-EVENT_PRESET = 6
+EVENT_RESET = 6
EVENT_CHOOSE_INI = 7
EVENT_CHOOSE_DXF = 8
EVENT_HELP = 9
-EVENT_CONFIG = 10
+EVENT_PRESETCURV = 10
EVENT_PRESETS = 11
EVENT_DXF_DIR = 12
-EVENT_LIST = 13
+# = 13
+EVENT_LIST = 14
+EVENT_ORIGIN = 15
+EVENT_SCALE = 16
EVENT_PRESET2D = 20
+EVENT_PRESET3D = 21
EVENT_EXIT = 100
GUI_EVENT = EVENT_NONE
@@ -4222,22 +5269,41 @@ GUI_B = {} # GUI-buttons dictionary for drawingTypes
# settings default, initialize ------------------------
-points_as_menu = "convert to: %t|empty %x1|mesh.vertex %x2|thin sphere %x3|thin box %x4"
-lines_as_menu = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|*thin box %x4"
-mlines_as_menu = "convert to: %t|*edge %x1|*mesh %x2|*thin cylinder %x3|*thin box %x4"
-plines_as_menu = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|*thin box %x4"
-plines3_as_menu = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|*thin box %x4"
-plmesh_as_menu = "convert to: %t|mesh %x1"
-solids_as_menu = "convert to: %t|mesh %x1"
-blocks_as_menu = "convert to: %t|dupl.group %x1|*real.group %x2|*exploded %x3"
-texts_as_menu = "convert to: %t|text %x1|*mesh %x2"
+points_as_menu = "convert to: %t|empty %x1|mesh.vertex %x2|thin sphere %x3|thin box %x4|*curve.vertex %x5"
+lines_as_menu = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|thin box %x4|Bezier-curve %x5|NURBS-curve %x6"
+mlines_as_menu = "convert to: %t|*edge %x1|*mesh %x2|*thin cylinder %x3|*thin box %x|*curve %x5"
+plines_as_menu = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|*thin box %x4|Bezier-curve %x5|NURBS-curve %x6"
+splines_as_menu = "convert to: %t|mesh %x2|*thin cylinder %x3|*thin box %x4|Bezier-curve %x5|NURBS-curve %x6"
+plines3_as_menu = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|*thin box %x4|Bezier-curve %x5|NURBS-curve %x6"
+plmesh_as_menu = "convert to: %t|*edge %x1|mesh %x2|NURBS-surface %x6"
+solids_as_menu = "convert to: %t|*edge %x1|mesh %x2"
+blocks_as_menu = "convert to: %t|dupliGroup %x1|*real.Group %x2|*exploded %x3"
+texts_as_menu = "convert to: %t|text %x1|*mesh %x2|*curve %x5"
material_from_menu= "material from: %t|*LINESTYLE %x7|COLOR %x1|LAYER %x2|*LAYER+COLOR %x3|*BLOCK %x4|*XDATA %x5|*INI-File %x6"
-g_scale_list = "scale factor: %t|yard to m %x8|feet to m %x7|inch to m %x6|x 1000 %x3|x 100 %x2|x 10 %x1|x 1 %x0|x 0.1 %x-1|cm to m %x-2|mm to m %x-3|x 0.0001 %x-4|x 0.00001 %x-5"
+g_scale_list = ''.join((
+ 'scale factor: %t',
+ '|user def. %x12',
+ '|yard to m %x8',
+ '|feet to m %x7',
+ '|inch to m %x6',
+ '| x 1000 %x3',
+ '| x 100 %x2',
+ '| x 10 %x1',
+ '| x 1 %x0',
+ '| x 0.1 %x-1',
+ '| x 0.01 %x-2',
+ '| x 0.001 %x-3',
+ '| x 0.0001 %x-4',
+ '| x 0.00001 %x-5'))
+
+#print 'deb: g_scale_list', g_scale_list #-----------
dxfFileName = Draw.Create("")
iniFileName = Draw.Create(INIFILE_DEFAULT_NAME + INIFILE_EXTENSION)
user_preset = 0
config_UI = Draw.Create(0) #switch_on/off extended config_UI
+g_scale_as = Draw.Create(int(log10(G_SCALE)))
+
keywords_org = {
'curves_on' : 0,
@@ -4245,12 +5311,25 @@ keywords_org = {
'one_mesh_on': 1,
'vGroup_on' : 1,
'dummy_on' : 0,
+ 'views_on' : 0,
+ 'cams_on' : 0,
+ 'lights_on' : 0,
+ 'xref_on' : 1,
+ 'block_nn': 0,
+ 'blockFilter_on': 0,
+ 'layerFilter_on': 0,
+ 'colorFilter_on': 0,
+ 'groupFilter_on': 0,
'newScene_on' : 1,
'target_layer' : TARGET_LAYER,
'group_bylayer_on' : GROUP_BYLAYER,
+ 'g_originX' : G_ORIGIN_X,
+ 'g_originY' : G_ORIGIN_Y,
+ 'g_originZ' : G_ORIGIN_Z,
+ 'g_origin_on': 0,
'g_scale' : float(G_SCALE),
- 'g_scale_as': int(log10(G_SCALE)), # 0,
- 'g_scale_on': 1,
+# 'g_scale_as': int(log10(G_SCALE)), # 0,
+ 'g_scale_on': 0,
'thick_on' : 1,
'thick_min' : float(MIN_THICK),
'thick_force': 0,
@@ -4262,7 +5341,6 @@ keywords_org = {
'dist_force': 0,
'material_on': 1,
'material_from': 2,
- 'pl_3d' : 1,
'fill_on' : 1,
'meshSmooth_on': 1,
'curve_res' : CURV_RESOLUTION,
@@ -4272,6 +5350,8 @@ keywords_org = {
'thin_res' : THIN_RESOLUTION,
'pl_trim_max' : TRIM_LIMIT,
'pl_trim_on': 1,
+ 'plmesh_flip': 0,
+ 'normals_out': 0,
'paper_space_on': 0,
'layFrozen_on': 0,
'Z_force_on': 0,
@@ -4280,9 +5360,10 @@ keywords_org = {
'lines_as' : 2,
'mlines_as' : 2,
'plines_as' : 2,
+ 'splines_as' : 5,
'plines3_as': 2,
- 'plmesh_as' : 1,
- 'solids_as' : 1,
+ 'plmesh_as' : 2,
+ 'solids_as' : 2,
'blocks_as' : 1,
'texts_as' : 1
}
@@ -4292,9 +5373,10 @@ drawTypes_org = {
'line' : 1,
'arc' : 1,
'circle': 1,
- 'ellipse': 0,
+ 'ellipse': 1,
'mline' : 0,
'polyline': 1,
+ 'spline': 1,
'plmesh': 1,
'pline3': 1,
'lwpolyline': 1,
@@ -4302,9 +5384,10 @@ drawTypes_org = {
'mtext' : 0,
'block' : 1,
'insert': 1,
- 'face' : 1,
'solid' : 1,
- 'trace' : 1
+ 'trace' : 1,
+ 'face' : 1,
+# 'view' : 0,
}
# creating of GUI-buttons
@@ -4316,12 +5399,40 @@ for k, v in drawTypes_org.iteritems():
GUI_B[k] = Draw.Create(v)
#print 'deb:init GUI_A: ', GUI_A #---------------
#print 'deb:init GUI_B: ', GUI_B #---------------
+
+model_space_on = Draw.Create(1)
+
# initialize settings-object controls how dxf entities are drawn
settings = Settings(keywords_org, drawTypes_org)
+def update_RegistryKey(key, item): #
+ """updates key in Blender.Registry
+ """
+ cache = True # data is also saved to a file
+ rdict = Registry.GetKey('DXF_Importer', cache)
+ if not rdict: rdict = {}
+ if item:
+ rdict[key] = item
+ Registry.SetKey('DXF_Importer', rdict, cache)
+ #print 'deb:update_RegistryKey rdict', rdict #---------------
+
-def saveConfig(): #remi--todo-----------------------------------------------
+def check_RegistryKey(key):
+ """ check if the key is already there (saved on a previous execution of this script)
+ """
+ cache = True # data is also saved to a file
+ rdict = Registry.GetKey('DXF_Importer', cache)
+ #print 'deb:check_RegistryKey rdict:', rdict #----------------
+ if rdict: # if found, get the values saved there
+ try:
+ item = rdict[key]
+ return item
+ except:
+ #update_RegistryKey() # if data isn't valid rewrite it
+ pass
+
+def saveConfig(): #--todo-----------------------------------------------
"""Save settings/config/materials from GUI to INI-file.
Write all config data to INI-file.
@@ -4331,18 +5442,31 @@ def saveConfig(): #remi--todo-----------------------------------------------
iniFile = iniFileName.val
#print 'deb:saveConfig inifFile: ', inifFile #----------------------
if iniFile.lower().endswith(INIFILE_EXTENSION):
+
+ #--todo-- sort key.list for output
+ #key_list = GUI_A.keys().val
+ #key_list.sort()
+ #for key in key_list:
+ # l_name, l_data = key, GUI_A[key].val
+ # list_A
+
output_str = '[%s,%s]' %(GUI_A, GUI_B)
if output_str =='None':
Draw.PupMenu('DXF importer: INI-file: Alert!%t|no config-data present to save!')
else:
#if BPyMessages.Warning_SaveOver(iniFile): #<- remi find it too abstarct
if sys.exists(iniFile):
- f = file(iniFile, 'r'); header_str = f.readline(); f.close()
- if header_str.startswith(INIFILE_HEADER[0:12]):
+ try:
+ f = file(iniFile, 'r')
+ try: header_str = f.readline()
+ finally: f.close()
+ except: pass
+ if header_str.startswith(INIFILE_HEADER[0:13]):
if Draw.PupMenu(' OK ? %t|SAVE OVER: ' + '\'%s\'' %iniFile) == 1:
save_ok = True
+ else: save_ok = False
elif Draw.PupMenu(' OK ? %t|SAVE OVER: ' + '\'%s\'' %iniFile +
- '|Alert: this file has no valid ImportDXF-format| ! it may belong to another aplication !') == 1:
+ '|Alert: this file has no valid ImportDXF-header| ! it may belong to another aplication !') == 1:
save_ok = True
else: save_ok = False
else: save_ok = True
@@ -4356,10 +5480,11 @@ def saveConfig(): #remi--todo-----------------------------------------------
output_str = '{\n'.join(output_str.split('{'))
try:
f = file(iniFile, 'w')
- f.write(INIFILE_HEADER + '\n# this is a comment line\n')
- f.write(output_str)
- f.close()
- Draw.PupMenu('DXF importer: INI-file: Done!%t|config-data saved in ' + '\'%s\'' %iniFile)
+ try:
+ f.write(INIFILE_HEADER + '\n# this is a comment line\n')
+ f.write(output_str)
+ finally: f.close()
+ #Draw.PupMenu('DXF importer: INI-file: Done!%t|config-data saved in ' + '\'%s\'' %iniFile)
except:
Draw.PupMenu('DXF importer: INI-file: Error!%t|failure by writing to ' + '\'%s\'|no config-data saved!' %iniFile)
@@ -4380,28 +5505,28 @@ def loadConfig(): #remi--todo-----------------------------------------------
global iniFileName, GUI_A, GUI_B
iniFile = iniFileName.val
+ update_RegistryKey('iniFileName', iniFile)
#print 'deb:loadConfig iniFile: ', iniFile #----------------------
if iniFile.lower().endswith(INIFILE_EXTENSION) and sys.exists(iniFile):
- f = file(iniFile, 'r')
- header_str = f.readline()
- if not header_str.startswith(INIFILE_HEADER):
- f.close()
- Draw.PupMenu('DXF importer: INI-file: Alert!%t|no valid header in INI-file: ' + '\'%s\'' %iniFile)
- else:
- data_str = f.read()
- f.close()
- print 'deb:loadConfig data_str from %s: \n' %iniFile , data_str #--------------------------
- data = eval(data_str)
- for k, v in data[0].iteritems():
- try:
- GUI_A[k].val = v
- except:
- GUI_A[k] = Draw.Create(v)
- for k, v in data[1].iteritems():
- try:
- GUI_B[k].val = v
- except:
- GUI_B[k] = Draw.Create(v)
+ try:
+ f = file(iniFile, 'r')
+ try:
+ header_str = f.readline()
+ if header_str.startswith(INIFILE_HEADER):
+ data_str = f.read()
+ f.close()
+ #print 'deb:loadConfig data_str from %s: \n' %iniFile , data_str #-----------------
+ data = eval(data_str)
+ for k, v in data[0].iteritems():
+ try: GUI_A[k].val = v
+ except: GUI_A[k] = Draw.Create(v)
+ for k, v in data[1].iteritems():
+ try: GUI_B[k].val = v
+ except: GUI_B[k] = Draw.Create(v)
+ else:
+ Draw.PupMenu('DXF importer: INI-file: Alert!%t|no valid header in INI-file: ' + '\'%s\'' %iniFile)
+ finally: f.close()
+ except: pass
else:
Draw.PupMenu('DXF importer: INI-file: Alert!%t|no valid INI-file selected!')
print "DXF importer: Alert!: no valid INI-file selected."
@@ -4411,27 +5536,57 @@ def loadConfig(): #remi--todo-----------------------------------------------
-def resetDefaultConfig(): #-----------------------------------------------
- """Resets settings/config/materials to defaults.
+def updateConfig(keywords, drawTypes): #-----------------------------------------------
+ """updates GUI_settings with given dictionaries
"""
global GUI_A, GUI_B
#print 'deb:lresetDefaultConfig keywords_org: \n', keywords_org #---------
- for k, v in keywords_org.iteritems():
+ for k, v in keywords.iteritems():
GUI_A[k].val = v
- for k, v in drawTypes_org.iteritems():
+ for k, v in drawTypes.iteritems():
GUI_B[k].val = v
+def resetDefaultConfig(): #-----------------------------------------------
+ """Resets settings/config/materials to defaults.
+
+ """
+ #print 'deb:lresetDefaultConfig keywords_org: \n', keywords_org #---------
+ updateConfig(keywords_org, drawTypes_org)
+
+
+def presetConfig_curv(activate): #-----------------------------------------------
+ """Sets settings/config/materials for curve representation.
+
+ """
+ global GUI_A
+ if activate:
+ GUI_A['curves_on'].val = 1
+ GUI_A['points_as'].val = 5
+ GUI_A['lines_as'].val = 5
+ GUI_A['mlines_as'].val = 5
+ GUI_A['plines_as'].val = 5
+ GUI_A['splines_as'].val = 5
+ GUI_A['plines3_as'].val = 5
+ else:
+ GUI_A['curves_on'].val = 0
+ GUI_A['points_as'].val = 2
+ GUI_A['lines_as'].val = 2
+ GUI_A['mlines_as'].val = 2
+ GUI_A['plines_as'].val = 2
+ GUI_A['splines_as'].val = 6
+ GUI_A['plines3_as'].val = 2
+
def resetDefaultConfig_2D(): #-----------------------------------------------
"""Sets settings/config/materials to defaults 2D.
"""
- resetDefaultConfig()
- global GUI_A, GUI_B
+ presetConfig_curv(1)
keywords2d = {
- 'curves_on' : 0,
- 'one_mesh_on': 1,
+ 'views_on' : 0,
+ 'cams_on' : 0,
+ 'lights_on' : 0,
'vGroup_on' : 1,
'thick_on' : 0,
'thick_force': 0,
@@ -4439,16 +5594,11 @@ def resetDefaultConfig_2D(): #-----------------------------------------------
'width_force': 0,
'dist_on' : 1,
'dist_force': 0,
- 'pl_3d' : 0,
'fill_on' : 0,
'pl_trim_on': 1,
'Z_force_on': 0,
'meshSmooth_on': 0,
- 'points_as' : 2,
- 'lines_as' : 2,
- 'mlines_as' : 2,
- 'plines_as' : 2,
- 'solids_as' : 1,
+ 'solids_as' : 2,
'blocks_as' : 1,
'texts_as' : 1
}
@@ -4458,33 +5608,117 @@ def resetDefaultConfig_2D(): #-----------------------------------------------
'line' : 1,
'arc' : 1,
'circle': 1,
- 'ellipse': 0,
+ 'ellipse': 1,
'mline' : 0,
'polyline': 1,
+ 'spline': 1,
'plmesh': 0,
- 'pline3': 0,
+ 'pline3': 1,
'lwpolyline': 1,
'text' : 1,
'mtext' : 0,
'block' : 1,
'insert': 1,
+ 'solid' : 1,
+ 'trace' : 1,
'face' : 0,
+# 'view' : 0,
+ }
+
+ updateConfig(keywords2d, drawTypes2d)
+
+def resetDefaultConfig_3D(): #-----------------------------------------------
+ """Sets settings/config/materials to defaults 3D.
+
+ """
+ presetConfig_curv(0)
+ keywords3d = {
+# 'views_on' : 1,
+# 'cams_on' : 1,
+# 'lights_on' : 1,
+ 'vGroup_on' : 1,
+ 'thick_on' : 1,
+ 'thick_force': 0,
+ 'width_on' : 1,
+ 'width_force': 0,
+ 'dist_on' : 1,
+ 'dist_force': 0,
+ 'fill_on' : 1,
+ 'pl_trim_on': 1,
+ 'Z_force_on': 0,
+ 'meshSmooth_on': 1,
+ 'solids_as' : 2,
+ 'blocks_as' : 1,
+ 'texts_as' : 1
+ }
+
+ drawTypes3d = {
+ 'point' : 1,
+ 'line' : 1,
+ 'arc' : 1,
+ 'circle': 1,
+ 'ellipse': 1,
+ 'mline' : 0,
+ 'polyline': 1,
+ 'spline': 1,
+ 'plmesh': 1,
+ 'pline3': 1,
+ 'lwpolyline': 1,
+ 'text' : 0,
+ 'mtext' : 0,
+ 'block' : 1,
+ 'insert': 1,
'solid' : 1,
- 'trace' : 1
+ 'trace' : 1,
+ 'face' : 1,
+# 'view' : 0,
}
- for k, v in keywords2d.iteritems():
- GUI_A[k].val = v
- for k, v in drawTypes2d.iteritems():
- GUI_B[k].val = v
+ updateConfig(keywords3d, drawTypes3d)
+def inputGlobalScale():
+ """Pop-up UI-Block for global scale factor
+ """
+ global GUI_A
+ #print 'deb:inputGlobalScale ##########' #------------
+ x_scale = Draw.Create(GUI_A['g_scale'].val)
+ block = []
+ #block.append("global translation vector:")
+ block.append(("", x_scale, 0.0, 10000000.0))
+
+ retval = Draw.PupBlock("set global scale factor:", block)
+
+ GUI_A['g_scale'].val = float(x_scale.val)
+
+
+def inputOriginVector():
+ """Pop-up UI-Block for global translation vector
+ """
+ global GUI_A
+ #print 'deb:inputOriginVector ##########' #------------
+ x_origin = Draw.Create(GUI_A['g_originX'].val)
+ y_origin = Draw.Create(GUI_A['g_originY'].val)
+ z_origin = Draw.Create(GUI_A['g_originZ'].val)
+ block = []
+ #block.append("global translation vector:")
+ block.append(("X: ", x_origin, -100000000.0, 100000000.0))
+ block.append(("Y: ", y_origin, -100000000.0, 100000000.0))
+ block.append(("Z: ", z_origin, -100000000.0, 100000000.0))
+
+ retval = Draw.PupBlock("set global translation vector:", block)
+
+ GUI_A['g_originX'].val = x_origin.val
+ GUI_A['g_originY'].val = y_origin.val
+ GUI_A['g_originZ'].val = z_origin.val
+
def draw_UI(): #-----------------------------------------------------------------
""" Draw startUI and setup Settings.
"""
global GUI_A, GUI_B #__version__
- global user_preset, iniFileName, dxfFileName, config_UI
+ global user_preset, iniFileName, dxfFileName, config_UI, g_scale_as
+ global model_space_on
# This is for easy layout changes
but_0c = 70 #button 1.column width
@@ -4495,8 +5729,8 @@ def draw_UI(): #---------------------------------------------------------------
butt_margin = 10
menu_w = (3 * butt_margin) + but_0c + but_1c + but_2c + but_3c #menu width
- simple_menu_h = 110
- extend_menu_h = 400
+ simple_menu_h = 100
+ extend_menu_h = 350
y = simple_menu_h # y is menu upper.y
if config_UI.val: y += extend_menu_h
x = 20 #menu left.x
@@ -4504,199 +5738,328 @@ def draw_UI(): #---------------------------------------------------------------
but1c = but0c + but_0c + butt_margin
but2c = but1c + but_1c + butt_margin
but3c = but2c + but_2c + butt_margin
+ but4c = but3c + but_3c
# Here starts menu -----------------------------------------------------
#glClear(GL_COLOR_BUFFER_BIT)
#glRasterPos2d(8, 125)
+ y += 30
colorbox(x, y+20, x+menu_w+menu_margin*2, menu_margin)
- Draw.Label("DXF Importer ver." + __version__, but0c, y, menu_w, 20)
+ Draw.Label("DXF-Importer v" + __version__, but0c, y, menu_w, 20)
if config_UI.val:
- y -= 30
- Draw.BeginAlign()
- GUI_B['point'] = Draw.Toggle('POINT', EVENT_NONE, but0c, y, but_0c+but_1c, 20, GUI_B['point'].val, "support dxf-POINT on/off")
- Draw.Label('-->', but2c, y, but_2c, 20)
- GUI_A['points_as'] = Draw.Menu(points_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['points_as'].val, "select target Blender-object")
- Draw.EndAlign()
+ b0, b0_ = but0c, but_0c + butt_margin
+ b1, b1_ = but1c, but_1c
+ y_top = y
+ y -= 10
y -= 20
Draw.BeginAlign()
- GUI_B['line'] = Draw.Toggle('LINE.ARC.CIRCLE', EVENT_NONE, but0c, y, but_0c+but_1c, 20, GUI_B['line'].val, "support dxf-LINE,ARC,CIRCLE,ELLIPSE on/off")
- Draw.Label('-->', but2c, y, but_2c, 20)
- GUI_A['lines_as'] = Draw.Menu(lines_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['lines_as'].val, "select target Blender-object")
+ GUI_B['point'] = Draw.Toggle('POINT', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['point'].val, "support dxf-POINT on/off")
+ if GUI_B['point'].val:
+ GUI_A['points_as'] = Draw.Menu(points_as_menu, EVENT_NONE, b1, y, b1_, 20, GUI_A['points_as'].val, "select target Blender-object")
+# Draw.Label('-->', but2c, y, but_2c, 20)
Draw.EndAlign()
y -= 20
Draw.BeginAlign()
- GUI_B['mline'] = Draw.Toggle('*MLINE', EVENT_NONE, but0c, y, but_0c+but_1c, 20, GUI_B['mline'].val, "(*wip)support dxf-MLINE on/off")
- Draw.Label('-->', but2c, y, but_2c, 20)
- GUI_A['mlines_as'] = Draw.Menu(mlines_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['mlines_as'].val, "select target Blender-object")
+ GUI_B['line'] = Draw.Toggle('LINE...etc', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['line'].val, "support dxf-LINE,ARC,CIRCLE,ELLIPSE on/off")
+ if GUI_B['line'].val:
+ GUI_A['lines_as'] = Draw.Menu(lines_as_menu, EVENT_NONE, but1c, y, but_1c, 20, GUI_A['lines_as'].val, "select target Blender-object")
Draw.EndAlign()
y -= 20
Draw.BeginAlign()
- GUI_B['polyline'] = Draw.Toggle('2D-POLYLINE', EVENT_NONE, but0c, y, but_0c+but_1c, 20, GUI_B['polyline'].val, "support dxf-2D-POLYLINE on/off")
- Draw.Label('-->', but2c, y, but_2c, 20)
- GUI_A['plines_as'] = Draw.Menu(plines_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['plines_as'].val, "select target Blender-object")
+ GUI_B['mline'] = Draw.Toggle('*MLINE', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['mline'].val, "(*wip)support dxf-MLINE on/off")
+ if GUI_B['mline'].val:
+ GUI_A['mlines_as'] = Draw.Menu(mlines_as_menu, EVENT_NONE, but1c, y, but_1c, 20, GUI_A['mlines_as'].val, "select target Blender-object")
Draw.EndAlign()
y -= 20
Draw.BeginAlign()
- GUI_B['pline3'] = Draw.Toggle('3D-POLYLINE', EVENT_NONE, but0c, y, but_0c+but_1c, 20, GUI_B['pline3'].val, "support dxf-3D-POLYLINE on/off")
- Draw.Label('-->', but2c, y, but_2c, 20)
- GUI_A['plines3_as'] = Draw.Menu(plines3_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['plines3_as'].val, "select target Blender-object")
+ GUI_B['spline'] = Draw.Toggle('SPLINE', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['spline'].val, "support dxf-SPLINE on/off")
+ if GUI_B['spline'].val:
+ GUI_A['splines_as'] = Draw.Menu(splines_as_menu, EVENT_NONE, but1c, y, but_1c, 20, GUI_A['splines_as'].val, "select target Blender-object")
Draw.EndAlign()
y -= 20
Draw.BeginAlign()
- GUI_B['plmesh'] = Draw.Toggle('POLYMESH/-FACE', EVENT_NONE, but0c, y, but_0c+but_1c, 20, GUI_B['plmesh'].val, "support dxf-POLYMESH/POLYFACE on/off")
- Draw.Label('-->', but2c, y, but_2c, 20)
- GUI_A['plmesh_as'] = Draw.Menu(plmesh_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['plmesh_as'].val, "select target Blender-object")
+ GUI_B['polyline'] = Draw.Toggle('2D/LWPLINE', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['polyline'].val, "support dxf-2D-POLYLINE on/off")
+ if GUI_B['polyline'].val:
+ GUI_A['plines_as'] = Draw.Menu(plines_as_menu, EVENT_NONE, but1c, y, but_1c, 20, GUI_A['plines_as'].val, "select target Blender-object")
Draw.EndAlign()
y -= 20
Draw.BeginAlign()
- GUI_B['solid'] = Draw.Toggle('3DFACE.SOLID.TRACE', EVENT_NONE, but0c, y, but_0c+but_1c, 20, GUI_B['solid'].val, "support dxf-3DFACE, SOLID and TRACE on/off")
- Draw.Label('-->', but2c, y, but_2c, 20)
- GUI_A['solids_as'] = Draw.Menu(solids_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['solids_as'].val, "select target Blender-object")
+ GUI_B['pline3'] = Draw.Toggle('3D-PLINE', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['pline3'].val, "support dxf-3D-POLYLINE on/off")
+ if GUI_B['pline3'].val:
+ GUI_A['plines3_as'] = Draw.Menu(plines3_as_menu, EVENT_NONE, but1c, y, but_1c, 20, GUI_A['plines3_as'].val, "select target Blender-object")
Draw.EndAlign()
+ y_down = y
+ # -----------------------------------------------
+
+ y = y_top
+ b0, b0_ = but2c, but_2c + butt_margin
+ b1, b1_ = but3c, but_3c
+
+ y -= 10
y -= 20
Draw.BeginAlign()
- GUI_B['text'] = Draw.Toggle('TEXT', EVENT_NONE, but0c, y, but_0c, 20, GUI_B['text'].val, "support dxf-TEXT on/off")
- GUI_B['mtext'] = Draw.Toggle('*MTEXT', EVENT_NONE, but1c, y, but_1c-butt_margin, 20, GUI_B['mtext'].val, "(*wip)support dxf-MTEXT on/off")
- Draw.Label('-->', but2c, y, but_2c, 20)
- GUI_A['texts_as'] = Draw.Menu(texts_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['texts_as'].val, "select target Blender-object")
+ GUI_B['plmesh'] = Draw.Toggle('PL-MESH/FACE', EVENT_NONE, b0, y, b0_+b1_-40, 20, GUI_B['plmesh'].val, "support dxf-POLYMESH/POLYFACE on/off")
+# GUI_A['plmesh_as'] = Draw.Menu(plmesh_as_menu, EVENT_NONE, but1c, y, but_1c, 20, GUI_A['plmesh_as'].val, "select target Blender-object")
+ GUI_A['plmesh_flip'] = Draw.Toggle('N', EVENT_NONE, b1+b1_-40, y, 20, 20, GUI_A['plmesh_flip'].val, "flip DXF normals on/off")
+ GUI_A['normals_out'] = Draw.Toggle('N', EVENT_NONE, b1+b1_-20, y, 20, 20, GUI_A['normals_out'].val, "force Blender normals to outside on/off")
Draw.EndAlign()
y -= 20
+ GUI_B['solid'] = Draw.Toggle('SOLID', EVENT_NONE, b0, y, b0_, 20, GUI_B['solid'].val, "support dxf-SOLID and TRACE on/off")
+ GUI_B['face'] = Draw.Toggle('3DFACE', EVENT_NONE, b1, y, b1_, 20, GUI_B['face'].val, "support dxf-3DFACE on/off")
+# GUI_A['solids_as'] = Draw.Menu(solids_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['solids_as'].val, "select target Blender-object")
+ #print 'deb:support solid, trace', GUI_B['trace'].val, GUI_B['solid'].val # ------------
+
+
+ y -= 20
+ GUI_B['text'] = Draw.Toggle('TEXT', EVENT_NONE, b0, y, b0_, 20, GUI_B['text'].val, "support dxf-TEXT on/off")
+ GUI_B['mtext'] = Draw.Toggle('*MTEXT', EVENT_NONE, b1, y, b1_, 20, GUI_B['mtext'].val, "(*wip)support dxf-MTEXT on/off")
+# GUI_A['texts_as'] = Draw.Menu(texts_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['texts_as'].val, "select target Blender-object")
+
+ y -= 20
Draw.BeginAlign()
- GUI_B['block'] = Draw.Toggle('BLOCK', EVENT_NONE, but0c, y, but_0c, 20, GUI_B['block'].val, "support dxf-BLOCK and ARRAY on/off")
- GUI_A['dummy_on'] = Draw.Toggle('*XREF', EVENT_NONE, but1c, y, but_1c-butt_margin, 20, GUI_A['dummy_on'].val, "(*wip)support XREF-BLOCK on/off")
- Draw.Label('-->', but2c, y, but_2c, 20)
- GUI_A['blocks_as'] = Draw.Menu(blocks_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['blocks_as'].val, "select target Blender-object")
+ GUI_B['block'] = Draw.Toggle('BLOCK', EVENT_REDRAW, b0, y, b0_-30, 20, GUI_B['block'].val, "support dxf-BLOCK and ARRAY on/off")
+ GUI_B['insert'].val = GUI_B['block'].val
+ if GUI_B['block'].val:
+ GUI_A['block_nn'] = Draw.Toggle('n', EVENT_NONE, b1-30, y, 15, 20, GUI_A['block_nn'].val, "support hatch/noname BLOCKs *X... on/off")
+ GUI_A['xref_on'] = Draw.Toggle('Xref', EVENT_NONE, b1-15, y, 35, 20, GUI_A['xref_on'].val, "support for XREF-BLOCKs (place holders) on/off")
+ GUI_A['blocks_as'] = Draw.Menu(blocks_as_menu, EVENT_NONE, b1+20, y, b1_-20, 20, GUI_A['blocks_as'].val, "select target representation for imported BLOCKs")
Draw.EndAlign()
y -= 20
+ y -= 20
+
Draw.BeginAlign()
- GUI_A['dummy_on'] = Draw.Toggle('*views', EVENT_NONE, but0c, y, but_0c-25, 20, GUI_A['dummy_on'].val, "(*wip)support VIEWPORTs on/off")
- GUI_A['dummy_on'] = Draw.Toggle('*cams', EVENT_NONE, but1c-25, y, but_1c-25, 20, GUI_A['dummy_on'].val, "(*wip)support CAMERAs on/off")
- GUI_A['dummy_on'] = Draw.Toggle('*lights', EVENT_NONE, but1c+25, y, but_1c-25, 20, GUI_A['dummy_on'].val, "(*wip)support LIGHTs on/off")
+ GUI_A['views_on'] = Draw.Toggle('views', EVENT_NONE, b0, y, b0_-25, 20, GUI_A['views_on'].val, "imports VIEWs and VIEWPORTs as cameras on/off")
+ GUI_A['cams_on'] = Draw.Toggle('*cams', EVENT_NONE, b1-25, y, b1_-25, 20, GUI_A['cams_on'].val, "(*wip) support ASHADE cameras on/off")
+ GUI_A['lights_on'] = Draw.Toggle('*lights', EVENT_NONE, b1+25, y, b1_-25, 20, GUI_A['lights_on'].val, "(*wip) support AVE_RENDER lights on/off")
Draw.EndAlign()
+
+
+ if y < y_down: y_down = y
+ # -----end supported objects--------------------------------------
+
+ y_top = y_down
+ y = y_top
+ y -= 10
+ y -= 20
+ but_ = menu_w / 6
+ b0 = but0c + (menu_w - but_*6)/2
Draw.BeginAlign()
- GUI_A['material_on'] = Draw.Toggle('material', EVENT_NONE, but2c, y, but_2c-20, 20, GUI_A['material_on'].val, "support for material assignment on/off")
- GUI_A['material_from'] = Draw.Menu(material_from_menu, EVENT_NONE, but3c-20, y, but_3c+20, 20, GUI_A['material_from'].val, "material assignment from?")
+ GUI_A['paper_space_on'] = Draw.Toggle('paper', EVENT_NONE, b0+but_*0, y, but_, 20, GUI_A['paper_space_on'].val, "import only from Paper-Space on/off")
+ GUI_A['layFrozen_on'] = Draw.Toggle ('frozen', EVENT_NONE, b0+but_*1, y, but_, 20, GUI_A['layFrozen_on'].val, "import also from frozen LAYERs on/off")
+ GUI_A['layerFilter_on'] = Draw.Toggle('layer', EVENT_NONE, b0+but_*2, y, but_, 20, GUI_A['layerFilter_on'].val, "(*wip) LAYER filtering on/off")
+ GUI_A['colorFilter_on'] = Draw.Toggle('color', EVENT_NONE, b0+but_*3, y, but_, 20, GUI_A['colorFilter_on'].val, "(*wip) COLOR filtering on/off")
+ GUI_A['groupFilter_on'] = Draw.Toggle('group', EVENT_NONE, b0+but_*4, y, but_, 20, GUI_A['groupFilter_on'].val, "(*wip) GROUP filtering on/off")
+ GUI_A['blockFilter_on'] = Draw.Toggle('block', EVENT_NONE, b0+but_*5, y, but_, 20, GUI_A['blockFilter_on'].val, "(*wip) BLOCK 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--------------------------------------
+
+ b0, b0_ = but0c, but_0c + butt_margin
+ b1, b1_ = but1c, but_1c
+ y -= 10
y -= 20
Draw.BeginAlign()
- GUI_A['paper_space_on'] = Draw.Toggle('paperSpace', EVENT_NONE, but0c, y, but_0c+20, 20, GUI_A['paper_space_on'].val, "import from paper space only on/off")
- GUI_A['layFrozen_on'] = Draw.Toggle('frozen', EVENT_NONE, but1c+20, y, but_1c-20, 20, GUI_A['layFrozen_on'].val, "import also from frozen layers on/off")
- #GUI_A['dummy_on'] = Draw.Toggle('-', EVENT_NONE, but3c, y, but_3c, 20, GUI_A['dummy_on'].val, "dummy on/off")
+ GUI_A['g_origin_on'] = Draw.Toggle('glob.reLoc', EVENT_REDRAW, b0, y, b0_, 20, GUI_A['g_origin_on'].val, "global relocate all DXF objects on/off")
+ if GUI_A['g_origin_on'].val:
+ tmp = Draw.PushButton('=', EVENT_ORIGIN, b1, y, 20, 20, "edit relocation-vector (x,y,z in DXF units)")
+ origin_str = '(%.4f, %.4f, %.4f)' % (
+ GUI_A['g_originX'].val,
+ GUI_A['g_originY'].val,
+ GUI_A['g_originZ'].val
+ )
+ tmp = Draw.Label(origin_str, b1+20, y, 300, 20)
+ #GUI_A['g_origin'] = Draw.String('', EVENT_ORIGIN, b1, y, b1_, 20, GUI_A['g_origin'].val, "global translation-vector (x,y,z) in DXF units")
Draw.EndAlign()
+
+ y -= 20
Draw.BeginAlign()
- GUI_A['g_scale_on'] = Draw.Toggle('glob.Scale', EVENT_NONE, but2c, y, but_2c, 20, GUI_A['g_scale_on'].val, "scaling all DXF objects on/off")
- GUI_A['g_scale_as'] = Draw.Menu(g_scale_list, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['g_scale_as'].val, "10^ factor for scaling the DXFdata")
+ GUI_A['g_scale_on'] = Draw.Toggle('glob.Scale', EVENT_REDRAW, b0, y, b0_, 20, GUI_A['g_scale_on'].val, "global scale all DXF objects on/off")
+ if GUI_A['g_scale_on'].val:
+ g_scale_as = Draw.Menu(g_scale_list, EVENT_SCALE, b1, y, 45, 20, g_scale_as.val, "factor for scaling the DXFdata")
+ if g_scale_as.val == 12:
+ pass
+ else:
+ if g_scale_as.val == 6: #scale inches to meters
+ GUI_A['g_scale'].val = 0.0254000
+ elif g_scale_as.val == 7: #scale feets to meters
+ GUI_A['g_scale'].val = 0.3048000
+ elif g_scale_as.val == 8: #scale yards to meters
+ GUI_A['g_scale'].val = 0.9144000
+ else:
+ GUI_A['g_scale'].val = 10.0 ** int(g_scale_as.val)
+ scale_float = GUI_A['g_scale'].val
+ if scale_float < 0.000001 or scale_float > 1000000:
+ scale_str = ' = %s' % GUI_A['g_scale'].val
+ else:
+ scale_str = ' = %.6f' % GUI_A['g_scale'].val
+ Draw.Label(scale_str, b1+45, y, 200, 20)
Draw.EndAlign()
+ y_down = y
+ # -----end material,translate,scale------------------------------------------
- y -= 30
- GUI_A['group_bylayer_on'] = Draw.Toggle('oneGroup', EVENT_NONE, but0c, y, but_0c, 20, GUI_A['group_bylayer_on'].val, "grouping entities from the same layer on/off")
- GUI_A['vGroup_on'] = Draw.Toggle('vGroups', EVENT_NONE, but1c, y, but_1c, 20, GUI_A['vGroup_on'].val, "support Blender-VertexGroups on/off")
+ b0, b0_ = but0c, but_0c + butt_margin
+ b1, b1_ = but1c, but_1c
+
+ y_top = y_down
+ y = y_top
+ y -= 10
+ y -= 20
Draw.BeginAlign()
- GUI_A['Z_force_on'] = Draw.Toggle('*elevation', EVENT_NONE, but2c, y, but_2c, 20, GUI_A['Z_force_on'].val, "*set objects Z-coordinates to elevation on/off")
- GUI_A['Z_elev'] = Draw.Number('', EVENT_NONE, but3c, y, but_3c, 20, GUI_A['Z_elev'].val, -1000, 1000, "set default elevation(Z)")
+ GUI_A['meshSmooth_on'] = Draw.Toggle('smooth', EVENT_NONE, b0, y, b0_-20, 20, GUI_A['meshSmooth_on'].val, "mesh smooth for circles/arc-segments on/off")
+ GUI_A['pl_trim_on'] = Draw.Toggle('trim', EVENT_NONE, b1-20, y, 32, 20, GUI_A['pl_trim_on'].val, "clean intersection of POLYLINE-wide-segments on/off")
+ GUI_A['pl_trim_max'] = Draw.Number('', EVENT_NONE, b1+12, y, b1_-12, 20, GUI_A['pl_trim_max'].val, 0, 5, "threshold intersection of POLYLINE-wide-segments: 0.0-5.0")
Draw.EndAlign()
-
y -= 20
Draw.BeginAlign()
- GUI_A['meshSmooth_on'] = Draw.Toggle('smooth', EVENT_NONE, but0c, y, but_0c-20, 20, GUI_A['meshSmooth_on'].val, "mesh smooth for circles/arcsegments on/off")
- GUI_A['pl_trim_on'] = Draw.Toggle('trim', EVENT_NONE, but1c-20, y, 32, 20, GUI_A['pl_trim_on'].val, "intersection of POLYLINE-wide-segments on/off")
- GUI_A['pl_trim_max'] = Draw.Number('', EVENT_NONE, but1c+12, y, but_1c-12, 20, GUI_A['pl_trim_max'].val, 0, 5, "limit for intersection of POLYLINE-wide-segments: 0.0-5.0")
+# GUI_A['thin_res'] = Draw.Number('thin:', EVENT_NONE, but0c, y, but_0c, 20, GUI_A['thin_res'].val, 4, 64, "thin cylinder resolution - number of segments (4-64)")
+ GUI_A['arc_rad'] = Draw.Number('bR:', EVENT_NONE, b0, y, b0_, 20, GUI_A['arc_rad'].val, 0.01, 100, "basis radius for arc/circle resolution (0.01-100)")
+ GUI_A['arc_res'] = Draw.Number('', EVENT_NONE, b1, y, b1_/2, 20, GUI_A['arc_res'].val, 3, 500, "arc/circle resolution - number of segments (3-500)")
+ GUI_A['fill_on'] = Draw.Toggle('caps', EVENT_NONE, b1+b1_/2, y, b1_/2, 20, GUI_A['fill_on'].val, "draws top and bottom caps of CYLINDERs/closed curves on/off")
Draw.EndAlign()
+
+ y -= 20
Draw.BeginAlign()
- GUI_A['dist_on'] = Draw.Toggle('dist.:', EVENT_NONE, but2c, y, but_2c-20, 20, GUI_A['dist_on'].val, "support distance on/off")
- GUI_A['dist_force'] = Draw.Toggle('F', EVENT_NONE, but2c+but_2c-20, y, 20, 20, GUI_A['dist_force'].val, "force minimal distance on/off")
- GUI_A['dist_min'] = Draw.Number('', EVENT_NONE, but3c, y, but_3c, 20, GUI_A['dist_min'].val, 0, 10, "minimal length/distance (double.vertex removing)")
+ GUI_A['curve_arc'] = Draw.Number('', EVENT_NONE, b0, y, b0_/2, 20, GUI_A['curve_arc'].val, 3, 32, "Bezier circle: amount of segments: 3-32")
+ GUI_A['curve_res'] = Draw.Number('', EVENT_NONE, b0+b0_/2, y, b0_/2, 20, GUI_A['curve_res'].val, 1, 128, "Set the Curve's U-resolution value: 1-128")
+ GUI_A['curves_on'] = Draw.Toggle('to Curves', EVENT_PRESETCURV, b1, y, b1_, 20, GUI_A['curves_on'].val, "set Curve as target object type on/off")
Draw.EndAlign()
y -= 20
+ GUI_A['group_bylayer_on'] = Draw.Toggle('Layer', EVENT_NONE, b0, y, 30, 20, GUI_A['group_bylayer_on'].val, "DXF-entities group by layer on/off")
+ GUI_A['vGroup_on'] = Draw.Toggle('vGroups', EVENT_NONE, b0+30, y, b1_-10, 20, GUI_A['vGroup_on'].val, "sort faces into VertexGroups on/off")
+ GUI_A['one_mesh_on'] = Draw.Toggle('oneMesh', EVENT_NONE, b1+10, y, b1_-10, 20, GUI_A['one_mesh_on'].val, "draw DXF-entities into one mesh-object. Recommended for big DXF-files. on/off")
+
+ y -= 30
Draw.BeginAlign()
-# GUI_A['thin_res'] = Draw.Number('thin:', EVENT_NONE, but0c, y, but_0c, 20, GUI_A['thin_res'].val, 4, 64, "thin cylinder resolution - number of segments (4-64)")
- GUI_A['arc_rad'] = Draw.Number('bR:', EVENT_NONE, but0c, y, but_0c, 20, GUI_A['arc_rad'].val, 0.01, 100, "basis radius for arc/circle resolution (0.01-100)")
- GUI_A['arc_res'] = Draw.Number('', EVENT_NONE, but1c, y, but_1c/2, 20, GUI_A['arc_res'].val, 3, 500, "arc/circle resolution - number of segments (3-500)")
- GUI_A['fill_on'] = Draw.Toggle('caps', EVENT_NONE, but1c+but_1c/2, y, but_1c/2, 20, GUI_A['fill_on'].val, "draws top and bottom caps of CYLINDERs/closed curves on/off")
+ GUI_A['material_on'] = Draw.Toggle('material', EVENT_REDRAW, b0, y, b0_-20, 20, GUI_A['material_on'].val, "support for material assignment on/off")
+ if GUI_A['material_on'].val:
+ GUI_A['material_from'] = Draw.Menu(material_from_menu, EVENT_NONE, b1-20, y, b1_+20, 20, GUI_A['material_from'].val, "material assignment from?")
Draw.EndAlign()
+
+ y_down = y
+ # -----------------------------------------------
+
+ b0, b0_ = but2c, but_2c + butt_margin
+ b1, b1_ = but3c, but_3c
+
+ y = y_top
+ y -= 10
+ y -= 20
Draw.BeginAlign()
- GUI_A['thick_on'] = Draw.Toggle('thick:', EVENT_NONE, but2c, y, but_2c-20, 20, GUI_A['thick_on'].val, "support thickness on/off")
- GUI_A['thick_force'] = Draw.Toggle('F', EVENT_NONE, but2c+but_2c-20, y, 20, 20, GUI_A['thick_force'].val, "force minimal thickness on/off")
- GUI_A['thick_min'] = Draw.Number('', EVENT_NONE, but3c, y, but_3c, 20, GUI_A['thick_min'].val, 0, 10, "minimal thickness")
+ GUI_A['Z_force_on'] = Draw.Toggle('*elevation', EVENT_REDRAW, b0, y, b0_, 20, GUI_A['Z_force_on'].val, "*set objects Z-coordinates to elevation on/off")
+ if GUI_A['Z_force_on'].val:
+ GUI_A['Z_elev'] = Draw.Number('', EVENT_NONE, b1, y, b1_, 20, GUI_A['Z_elev'].val, -1000, 1000, "set default elevation(Z-coordinate)")
Draw.EndAlign()
+ y -= 20
+ Draw.BeginAlign()
+ GUI_A['dist_on'] = Draw.Toggle('dist.:', EVENT_NONE, b0, y, b0_-20, 20, GUI_A['dist_on'].val, "support distance on/off")
+ GUI_A['dist_force'] = Draw.Toggle('F', EVENT_NONE, b0+b0_-20, y, 20, 20, GUI_A['dist_force'].val, "force minimal distance on/off")
+ GUI_A['dist_min'] = Draw.Number('', EVENT_NONE, b1, y, b1_, 20, GUI_A['dist_min'].val, 0, 10, "minimal length/distance (double.vertex removing)")
+ Draw.EndAlign()
y -= 20
Draw.BeginAlign()
- #GUI_A['group_bylayer_on'] = Draw.Toggle('oneGroup', EVENT_NONE, but0c, y, but_0c, 20, GUI_A['group_bylayer_on'].val, "grouping entities from the same layer on/off")
- GUI_A['curves_on'] = Draw.Toggle('to Curves', EVENT_NONE, but0c, y, but_0c, 20, GUI_A['curves_on'].val, "drawing LINE/ARC/POLYLINE into Blender-Curves instead of Meshes on/off")
- GUI_A['curve_arc'] = Draw.Number('', EVENT_NONE, but1c, y, but_1c/2, 20, GUI_A['curve_arc'].val, 3, 32, "Bezier circle resolution - number of segments: 3-32")
- GUI_A['curve_res'] = Draw.Number('', EVENT_NONE, but1c+but_1c/2, y, but_1c/2, 20, GUI_A['curve_res'].val, 3, 50, "Bezier curve resolution: 3-50")
+ GUI_A['thick_on'] = Draw.Toggle('thick:', EVENT_NONE, b0, y, b0_-20, 20, GUI_A['thick_on'].val, "support thickness on/off")
+ GUI_A['thick_force'] = Draw.Toggle('F', EVENT_REDRAW, b0+b0_-20, y, 20, 20, GUI_A['thick_force'].val, "force for thickness at least limiter value on/off")
+ if GUI_A['thick_force'].val:
+ GUI_A['thick_min'] = Draw.Number('', EVENT_NONE, b1, y, b1_, 20, GUI_A['thick_min'].val, 0, 10, "minimal value for thickness")
Draw.EndAlign()
+
+ y -= 20
Draw.BeginAlign()
- GUI_A['width_on'] = Draw.Toggle('width:', EVENT_NONE, but2c, y, but_2c-20, 20, GUI_A['width_on'].val, "support width on/off")
- GUI_A['width_force'] = Draw.Toggle('F', EVENT_NONE, but2c+but_2c-20, y, 20, 20, GUI_A['width_force'].val, "force minimal width on/off")
- GUI_A['width_min'] = Draw.Number('', EVENT_NONE, but3c, y, but_3c, 20, GUI_A['width_min'].val, 0, 10, "minimal width")
+ GUI_A['width_on'] = Draw.Toggle('width:', EVENT_NONE, b0, y, b0_-20, 20, GUI_A['width_on'].val, "support width on/off")
+ GUI_A['width_force'] = Draw.Toggle('F', EVENT_REDRAW, b0+b0_-20, y, 20, 20, GUI_A['width_force'].val, "force for width at least limiter value on/off")
+ if GUI_A['width_force'].val:
+ GUI_A['width_min'] = Draw.Number('', EVENT_NONE, b1, y, b1_, 20, GUI_A['width_min'].val, 0, 10, "minimal value for width")
Draw.EndAlign()
y -= 30
- #GUI_A['dummy_on'] = Draw.Toggle(' - ', EVENT_NONE, but0c, y, but_0c, 20, GUI_A['dummy_on'].val, "reserved")
- GUI_A['one_mesh_on'] = Draw.Toggle('oneMesh', EVENT_NONE, but0c, y, but_0c, 20, GUI_A['one_mesh_on'].val, "draw DXF-entities into one mesh-object. Recommended for big DXF-files. on/off")
- GUI_A['newScene_on'] = Draw.Toggle('newScene', EVENT_NONE, but1c, y, but_1c, 20, GUI_A['newScene_on'].val, "creates new Blender-Scene for each import on/off")
- GUI_A['target_layer'] = Draw.Number('layer', EVENT_NONE, but2c, y, but_2c, 20, GUI_A['target_layer'].val, 1, 18, "imports into this Blender-layer (<19> reserved for block_definitions)")
- GUI_A['optimization'] = Draw.Number('optim:', EVENT_NONE, but3c, y, but_3c, 20, GUI_A['optimization'].val, 0, 3, "Optimization Level: 0=Debug/directDrawing, 1=Verbose, 2=ProgressBar, 3=silentMode/fastest")
+ but, but_ = but2c, 25
+ Draw.BeginAlign()
+ Draw.EndAlign()
+ if y < y_down: y_down = y
+ # -----end options --------------------------------------
+
+
+ #--------------------------------------
+ y_top = y_down
+ y = y_top
+ #GUI_A['dummy_on'] = Draw.Toggle(' - ', EVENT_NONE, but0c, y, but_0c, 20, GUI_A['dummy_on'].val, "reserved")
y -= 30
Draw.BeginAlign()
Draw.PushButton('INI file >', EVENT_CHOOSE_INI, but0c, y, but_0c, 20, 'Select INI-file from project directory')
- iniFileName = Draw.String(' :', EVENT_NONE, but1c, y, menu_w-but_0c-butt_margin, 20, iniFileName.val, FILENAME_MAX, "write here the name of the INI-file")
+ iniFileName = Draw.String(' :', EVENT_NONE, but1c, y, menu_w-but_1c-60, 20, iniFileName.val, FILENAME_MAX, "write here the name of the INI-file")
+ but = but4c-60
+ Draw.PushButton('#', EVENT_PRESETS, but, y, 20, 20, "toggle Preset-INI-files")
+ Draw.PushButton('L', EVENT_LOAD_INI, but+20, y, 20, 20, 'Loads configuration from ini-file: %s' % iniFileName.val)
+ Draw.PushButton('S', EVENT_SAVE_INI, but+40, y, 20, 20, 'Saves configuration to ini-file: %s' % iniFileName.val)
Draw.EndAlign()
- y -= 20
- Draw.BeginAlign()
- Draw.PushButton('Presets', EVENT_PRESETS, but0c, y, but_0c, 20, "tipist for Preset-INI-files")
- Draw.PushButton('Load', EVENT_LOAD_INI, but1c, y, but_1c, 20, ' Loads configuration from ini-file: %s' % iniFileName.val)
- Draw.PushButton('Save', EVENT_SAVE_INI, but2c, y, but_2c, 20, 'Saves configuration to ini-file: %s' % iniFileName.val)
-# user_preset = Draw.Number('preset:', EVENT_PRESETS, but2c, y, but_2c, 20, user_preset.val, 0, 5, "call user Preset-INI-files")
- Draw.PushButton('2D', EVENT_PRESET2D, but3c, y, but_3c/2, 20, 'resets configuration to 2D-defaults')
- Draw.PushButton('3D', EVENT_PRESET, but3c+but_3c/2, y, but_3c/2, 20, 'resets configuration to 3D-defaults')
- Draw.EndAlign()
+ b0, b0_ = but2c, but_2c + butt_margin
+ b1, b1_ = but3c, but_3c
- y -= 30
+ y = simple_menu_h
+ bm = butt_margin/2
+
+ #y -= 10
Draw.BeginAlign()
Draw.PushButton('DXFfile >', EVENT_CHOOSE_DXF, but0c, y, but_0c, 20, 'Select DXF-file from project directory')
- dxfFileName = Draw.String(' :', EVENT_NONE, but1c, y, but_1c+but_2c+but_3c-20, 20, dxfFileName.val, FILENAME_MAX, "type the name of DXF-file or * for multi-import")
- Draw.PushButton('*.*', EVENT_DXF_DIR, but3c+but_3c-20, y, 20, 20, 'Set asterisk * as filter')
+ dxfFileName = Draw.String(' :', EVENT_NONE, but1c, y, but_1c+but_2c+but_3c-20, 20, dxfFileName.val, FILENAME_MAX, "type the name of DXF-file or type *.dxf for multi-import")
+ Draw.PushButton('*.*', EVENT_DXF_DIR, but3c+but_3c-20, y, 20, 20, 'import all dxf files from this directory')
+ Draw.EndAlign()
+
+ y -= 30
+ config_UI = Draw.Toggle('CONFIG', EVENT_REDRAW, but0c, y, but_0c+bm, 20, config_UI.val, 'Advanced configuration on/off' )
+ Draw.BeginAlign()
+ but, but_ = but1c, but_1c+bm
+ but_ /= 3
+ Draw.PushButton('X', EVENT_RESET, but, y, 15, 20, "reset configuration to defaults")
+ Draw.PushButton('2D', EVENT_PRESET2D, but+but_, y, but_, 20, 'set configuration for 2D import')
+ Draw.PushButton('3D', EVENT_PRESET3D, but+(but_*2), y, but_, 20, 'set configuration for 3D import')
Draw.EndAlign()
+ Draw.BeginAlign()
+ GUI_A['newScene_on'] = Draw.Toggle('newScene', EVENT_NONE, but2c, y, but_2c, 20, GUI_A['newScene_on'].val, "create new Scene for each imported dxf file on/off")
+ GUI_A['target_layer'] = Draw.Number('layer', EVENT_NONE, but3c, y, but_3c, 20, GUI_A['target_layer'].val, 1, 18, "target Blender-layer (<19> reserved for block_definitions)")
+ Draw.EndAlign()
- y -= 50
+ y -= 40
+ Draw.PushButton('EXIT', EVENT_EXIT, but0c, y, but_0c+bm, 20, '' )
+ Draw.PushButton('HELP', EVENT_HELP, but1c, y, but_1c+bm, 20, 'calls DXF-Importer Manual Page on Wiki.Blender.org')
+ Draw.BeginAlign()
+ GUI_A['optimization'] = Draw.Number('', EVENT_NONE, but2c, y+20, 40, 20, GUI_A['optimization'].val, 0, 3, "Optimization Level: 0=Debug/directDrawing, 1=Verbose, 2=ProgressBar, 3=SilentMode")
+ Draw.EndAlign()
Draw.BeginAlign()
- Draw.PushButton('EXIT', EVENT_EXIT, but0c, y, but_0c, 40, '' )
- Draw.PushButton('HELP', EVENT_HELP, but1c, y, but_1c-20, 20, 'calls BlenderWiki for Manual, Updates and Support.')
- Draw.PushButton('?', EVENT_LIST, but1c+but_1c-20, y, 20, 20, 'analyze DXF-file: print listing of LAYERs and BLOCKs into the text-file.INF')
- Draw.PushButton('START IMPORT', EVENT_START, but2c, y, but_2c+but_3c+butt_margin, 40, 'Start the import procedure')
+ Draw.PushButton('TEST', EVENT_LIST, but2c, y, 40, 20, 'DXF-Analyze-Tool: reads data from selected dxf file and writes report in project_directory/dxf_blendname.INF')
+ Draw.PushButton('START IMPORT', EVENT_START, but2c+40, y, but_2c-40+but_3c+butt_margin, 40, 'Start the import process. For Cancel go to console and hit Ctrl-C')
Draw.EndAlign()
- config_UI = Draw.Toggle('CONFIG', EVENT_CONFIG, but1c-butt_margin/2, y+20, but_1c+butt_margin, 20, config_UI.val, 'Advanced configuration on/off' )
+
+
y -= 20
Draw.BeginAlign()
Draw.Label(' ', but0c-menu_margin, y, menu_margin, 20)
- Draw.Label("*) parts under construction", but0c, y, menu_w, 20)
+ Draw.Label(LAB, but0c, y, menu_w, 20)
Draw.Label(' ', but0c+menu_w, y, menu_margin, 20)
Draw.EndAlign()
@@ -4709,10 +6072,13 @@ def colorbox(x,y,xright,bottom):
def dxf_callback(input_filename):
global dxfFileName
dxfFileName.val=input_filename
+# dirname == Blender.sys.dirname(Blender.Get('filename'))
+# update_RegistryKey('DirName', dirname)
+# update_RegistryKey('dxfFileName', input_filename)
-def ini_callback(input_texture):
+def ini_callback(input_filename):
global iniFileName
- iniFileName.val=input_texture
+ iniFileName.val=input_filename
def event(evt, val):
if evt in (Draw.QKEY, Draw.ESCKEY) and not val:
@@ -4721,27 +6087,46 @@ def event(evt, val):
def bevent(evt):
# global EVENT_NONE,EVENT_LOAD_DXF,EVENT_LOAD_INI,EVENT_SAVE_INI,EVENT_EXIT
global config_UI, user_preset
+ global GUI_A
######### Manages GUI events
if (evt==EVENT_EXIT):
Blender.Draw.Exit()
+ print 'DXF-Importer *** exit ***' #---------------------
elif (evt==EVENT_CHOOSE_INI):
Window.FileSelector(ini_callback, "INI-file Selection", '*.ini')
- elif (evt==EVENT_CONFIG):
+ elif (evt==EVENT_REDRAW):
Draw.Redraw()
- elif (evt==EVENT_PRESET):
+ elif (evt==EVENT_RESET):
resetDefaultConfig()
Draw.Redraw()
elif (evt==EVENT_PRESET2D):
resetDefaultConfig_2D()
Draw.Redraw()
+ elif (evt==EVENT_SCALE):
+ if g_scale_as.val == 12:
+ inputGlobalScale()
+ if GUI_A['g_scale'].val < 0.00000001:
+ GUI_A['g_scale'].val = 0.00000001
+ Draw.Redraw()
+ elif (evt==EVENT_ORIGIN):
+ inputOriginVector()
+ Draw.Redraw()
+ elif (evt==EVENT_PRESET3D):
+ resetDefaultConfig_3D()
+ Draw.Redraw()
+ elif (evt==EVENT_PRESETCURV):
+ presetConfig_curv(GUI_A['curves_on'].val)
+ Draw.Redraw()
elif (evt==EVENT_PRESETS):
user_preset += 1
- if user_preset > 5: user_preset = 1
- iniFileName.val = INIFILE_DEFAULT_NAME + str(user_preset) + INIFILE_EXTENSION
+ index = str(user_preset)
+ if user_preset > 5: user_preset = 0; index = ''
+ iniFileName.val = INIFILE_DEFAULT_NAME + index + INIFILE_EXTENSION
Draw.Redraw()
elif (evt==EVENT_LIST):
dxfFile = dxfFileName.val
+ update_RegistryKey('dxfFileName', dxfFileName.val)
if dxfFile.lower().endswith('.dxf') and sys.exists(dxfFile):
analyzeDXF(dxfFile)
else:
@@ -4770,20 +6155,27 @@ http://wiki.blender.org/index.php?title=Scripts/Manual/Import/DXF-3D')
elif '\\' in dxfFile:
dxfPathName = '\\'.join(dxfFile.split('\\')[:-1]) + '\\'
dxfFileName.val = dxfPathName + '*.dxf'
- global GUI_A
+# dirname == Blender.sys.dirname(Blender.Get('filename'))
+# update_RegistryKey('DirName', dirname)
+# update_RegistryKey('dxfFileName', dxfFileName.val)
GUI_A['newScene_on'].val = 1
Draw.Redraw()
elif (evt==EVENT_CHOOSE_DXF):
- Window.FileSelector(dxf_callback, "DXF-file Selection", '*.dxf')
+ filename = '' # '*.dxf'
+ if dxfFileName.val: filename = dxfFileName.val
+ Window.FileSelector(dxf_callback, "DXF-file Selection", filename)
elif (evt==EVENT_START):
dxfFile = dxfFileName.val
#print 'deb: dxfFile file: ', dxfFile #----------------------
+ if E_M: dxfFileName.val, dxfFile = e_mode(dxfFile) #evaluation mode
+ update_RegistryKey('dxfFileName', dxfFileName.val)
if dxfFile.lower().endswith('*.dxf'):
if Draw.PupMenu('DXF importer: OK?|will import all DXF-files from:|%s' % dxfFile) == 1:
global UI_MODE
UI_MODE = False
- multi_import(dxfFile[:-5]) # cut last char:'*.dxf'
- Draw.Exit()
+ multi_import(dxfFile[:-5]) # cut last 5 characters '*.dxf'
+ Draw.Redraw()
+ #Draw.Exit()
else:
Draw.Redraw()
elif dxfFile.lower().endswith('.dxf') and sys.exists(dxfFile):
@@ -4795,6 +6187,7 @@ http://wiki.blender.org/index.php?title=Scripts/Manual/Import/DXF-3D')
global SCENE
SCENE = Blender.Scene.New(_dxf_file)
SCENE.makeCurrent()
+ Blender.Redraw()
#or so? Blender.Scene.makeCurrent(_dxf_file)
#sce = bpy.data.scenes.new(_dxf_file)
#bpy.data.scenes.active = sce
@@ -4822,7 +6215,7 @@ def multi_import(DIR):
batchTIME = Blender.sys.time()
#if #DIR == "": DIR = os.path.curdir
if DIR == "": DIR = Blender.sys.dirname(Blender.Get('filename'))
- print 'Multifile Mode: searching for DXF-files in %s' %DIR
+ print 'Multifiles Import from %s' %DIR
files = \
[sys.join(DIR, f) for f in os.listdir(DIR) if f.lower().endswith('.dxf')]
if not files:
@@ -4832,7 +6225,7 @@ def multi_import(DIR):
i = 0
for dxfFile in files:
i += 1
- print '\nImporting', dxfFile, ' NUMBER', i, 'of', len(files)
+ print '\nDXF-file', i, 'of', len(files) #,'\nImporting', dxfFile
if GUI_A['newScene_on'].val:
_dxf_file = dxfFile.split('/')[-1].split('\\')[-1]
_dxf_file = _dxf_file[:-4] # cut last char:'.dxf'
@@ -4849,12 +6242,25 @@ def multi_import(DIR):
#Blender.Redraw()
print 'TOTAL TIME: %.6f' % (Blender.sys.time() - batchTIME)
+ print '\a\r', # beep when done
+UI_MODE = True
if __name__ == "__main__":
UI_MODE = True
+ # recall last used DXF-file and INI-file names
+ dxffilename = check_RegistryKey('dxfFileName')
+ #print 'deb:start dxffilename:', dxffilename #----------------
+ if dxffilename: dxfFileName.val = dxffilename
+ else:
+ dirname = Blender.sys.dirname(Blender.Get('filename'))
+ #print 'deb:start dirname:', dirname #----------------
+ dxfFileName.val = sys.join(dirname, '')
+ inifilename = check_RegistryKey('iniFileName')
+ if inifilename: iniFileName.val = inifilename
+
Draw.Register(draw_UI, event, bevent)
@@ -4892,4 +6298,4 @@ if 1:
main(_dxf)
print 'TOTAL TIME: %.6f' % (Blender.sys.time() - TIME)
-"""
+""" \ No newline at end of file