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

operator.py « io_export_dxf - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 081f02175abbf9de18ebb77cd749ffbadf4a5689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# SPDX-License-Identifier: GPL-2.0-or-later

import bpy
from bpy.props import (
    BoolProperty,
    EnumProperty,
    StringProperty,
)

class DXFExporter(bpy.types.Operator):
    """
    Export to the Autocad model format (.dxf)
    """
    bl_idname = "export.dxf"
    bl_label = "Export DXF"
    filepath: StringProperty(subtype='FILE_PATH')

    entitylayer_from_items = (
        ('default_LAYER', 'Default Layer', ''),
        ('obj.name', 'Object name', ''),
        ('obj.layer', 'Object layer', ''),
        ('obj.material', 'Object material', ''),
        ('obj.data.name', 'Object\' data name', ''),
#        ('obj.data.material', 'Material of data', ''),
        ('..vertexgroup', 'Vertex Group', ''),
        ('..group', 'Group', ''),
        ('..map_table', 'Table', '')
    )
    layerColorFromItems = (
        ('default_COLOR', 'Vertex Group', ''),
        ('BYLAYER', 'BYLAYER', ''),
        ('BYBLOCK', 'BYBLOCK', ''),
        ('obj.layer', 'Object Layer', ''),
        ('obj.color', 'Object Color', ''),
        ('obj.material', 'Object material', ''),
        # I don'd know ?
#        ('obj.data.material', 'Vertex Group', ''),
#        ('..map_table', 'Vertex Group', ''),
    )
    layerNameFromItems = (
        ('LAYERNAME_DEF', 'Default Name', ''),
        ('drawing_name', 'From Drawing name', ''),
        ('scene_name', 'From scene name', '')
    )

    exportModeItems = (
        ('ALL', 'All Objects', ''),
        ('SELECTION', 'Selected Objects', ''),
    )
#    spaceItems = (
#        ('1', 'Paper-Space', ''),
#        ('2', 'Model-Space', '')
#    )

    entityltype_fromItems = (
        ('default_LTYPE', 'default_LTYPE', ''),
        ('BYLAYER', 'BYLAYER', ''),
        ('BYBLOCK', 'BYBLOCK', ''),
        ('CONTINUOUS', 'CONTINUOUS', ''),
        ('DOT', 'DOT', ''),
        ('DASHED', 'DASHED', ''),
        ('DASHDOT', 'DASHDOT', ''),
        ('BORDER', 'BORDER', ''),
        ('HIDDEN', 'HIDDEN', '')
    )
    material_toItems = (
        ('NO', 'Do not export', ''),
        ('COLOR', 'COLOR', ''),
        ('LAYER', 'LAYER', ''),
        ('..LINESTYLE', '..LINESTYLE', ''),
        ('..BLOCK', '..BLOCK', ''),
        ('..XDATA', '..XDATA', ''),
        ('..INI-File', '..INI-File', '')
    )
    projectionItems=(
        ('NO', 'No projection', 'Export 3D scene without any 2D projection'),
        ('TOP', 'TOP view', 'Use TOP view for projection'),
        ('BOTTOM', 'BOTTOM view', 'Use BOTTOM view for projection'),
        ('LEFT', 'LEFT view', 'Use LEFT view for projection'),
        ('RIGHT', 'RIGHT view', 'Use RIGHT view for projection'),
        ('FRONT', 'FRONT view', 'Use FRONT view for projection'),
        ('REAR', 'REAR view', 'Use REAR view for projection')
    )
    mesh_asItems = (
        ('NO', 'Do not export', ''),
        ('3DFACEs', '3DFACEs', ''),
        ('POLYFACE', 'POLYFACE', ''),
        ('POLYLINE', 'POLYLINE', ''),
        ('LINEs', 'LINEs', 'export Mesh as multiple LINEs'),
        ('POINTs', 'POINTs', 'Export Mesh as multiple POINTs')
    )
#    curve_asItems  = (
#        ('NO', 'Do not export', ''),
#        ('LINEs', 'LINEs', ''),
#        ('POLYLINE', 'POLYLINE', ''),
#        ('..LWPOLYLINE r14', '..LWPOLYLINE r14', ''),
#        ('..SPLINE r14', '..SPLINE r14', ''),
#        ('POINTs', 'POINTs',  '')
#    )
#    surface_asItems  = (
#        ('NO', 'Do not export', ''),
#        ('..3DFACEs', '..3DFACEs', ''),
#        ('..POLYFACE', '..POLYFACE', ''),
#        ('..POINTs', '..POINTs', ''),
#        ('..NURBS', '..NURBS', '')
#    )
#    meta_asItems  = (
#        ('NO', 'Do not export', ''),
#        ('..3DFACEs', '..3DFACEs', ''),
#        ('..POLYFACE', '..POLYFACE', ''),
#        ('..3DSOLID', '..3DSOLID', '')
#    )
#    text_asItems  = (
#        ('NO', 'Do not export', ''),
#        ('TEXT', 'TEXT', ''),
#        ('..MTEXT', '..MTEXT', ''),
#        ('..ATTRIBUT', '..ATTRIBUT', '')
#    )
#    empty_asItems  = (
#        ('NO', 'Do not export', ''),
#        ('POINT', 'POINT', ''),
#        ('..INSERT', '..INSERT', ''),
#        ('..XREF', '..XREF', '')
#    )
#    group_asItems  = (
#        ('NO', 'Do not export', ''),
#        ('..GROUP', '..GROUP', ''),
#        ('..BLOCK', '..BLOCK', ''),
#        ('..ungroup', '..ungroup', '')
#    )
##    parent_asItems = ['..BLOCK','..ungroup'] # ???
#    proxy_asItems = (
#        ('NO', 'Do not export', ''),
#        ('..BLOCK','..BLOCK', ''),
#        ('..XREF', '..XREF', ''),
#        ('..ungroup', '..ungroup', ''),
#        ('..POINT', '..POINT', '')
#    )
#    camera_asItems = (
#        ('NO', 'Do not export', ''),
#        ('..BLOCK', '..BLOCK', ''),
#        ('..A_CAMERA', '..A_CAMERA', ''),
#        ('VPORT', 'VPORT', ''),
#        ('VIEW', 'VIEW', ''),
#        ('POINT', 'POINT', '')
#    )
#    light_asItems = (
#        ('NO', 'Do not export', ''),
#        ('..BLOCK', '..BLOCK', ''),
#        ('..A_LIGHT', '..A_LIGHT', ''),
#        ('POINT', 'POINT', '')
#    )
    # --------- CONTROL PROPERTIES --------------------------------------------
    projectionThrough: EnumProperty(name="Projection", default="NO",
                                    description="Select camera for use to 2D projection",
                                    items=projectionItems)

    onlySelected: BoolProperty(name="Only selected", default=True,
                              description="What object will be exported? Only selected / all objects")

    apply_modifiers: BoolProperty(name="Apply modifiers", default=True,
                           description="Shall be modifiers applied during export?")
    # GUI_B -----------------------------------------
    mesh_as: EnumProperty( name="Export Mesh As", default='3DFACEs',
                            description="Select representation of a mesh",
                            items=mesh_asItems)
#    curve_as: EnumProperty( name="Export Curve As:", default='NO',
#                            description="Select representation of a curve",
#                            items=curve_asItems)
#    surface_as: EnumProperty( name="Export Surface As:", default='NO',
#                            description="Select representation of a surface",
#                            items=surface_asItems)
#    meta_as: EnumProperty( name="Export meta As:", default='NO',
#                            description="Select representation of a meta",
#                            items=meta_asItems)
#    text_as: EnumProperty( name="Export text As:", default='NO',
#                            description="Select representation of a text",
#                            items=text_asItems)
#    empty_as: EnumProperty( name="Export empty As:", default='NO',
#                            description="Select representation of a empty",
#                            items=empty_asItems)
#    group_as: EnumProperty( name="Export group As:", default='NO',
#                            description="Select representation of a group",
#                            items=group_asItems)
##    parent_as: EnumProperty( name="Export parent As:", default='NO',
##                            description="Select representation of a parent",
##                            items=parent_asItems)
#    proxy_as: EnumProperty( name="Export proxy As:", default='NO',
#                            description="Select representation of a proxy",
#                            items=proxy_asItems)
#    camera_as: EnumProperty( name="Export camera As:", default='NO',
#                            description="Select representation of a camera",
#                            items=camera_asItems)
#    light_as: EnumProperty( name="Export lamp As:", default='NO',
#                            description="Select representation of a lamp",
#                            items=light_asItems)
    # ----------------------------------------------------------
    entitylayer_from: EnumProperty(name="Entity Layer", default="obj.data.name",
                                    description="Entity LAYER assigned to?",
                                    items=entitylayer_from_items)
    entitycolor_from: EnumProperty(name="Entity Color", default="default_COLOR",
                                    description="Entity COLOR assigned to?",
                                    items=layerColorFromItems)
    entityltype_from: EnumProperty(name="Entity Linetype", default="CONTINUOUS",
                                    description="Entity LINETYPE assigned to?",
                                    items=entityltype_fromItems)

    layerName_from: EnumProperty(name="Layer Name", default="LAYERNAME_DEF",
                                    description="From where will layer name be taken?",
                                    items=layerNameFromItems)
    # GUI_A -----------------------------------------
#    layFrozen_on: BoolProperty(name="LAYER.frozen status", description="(*todo) Support LAYER.frozen status   on/off", default=False)
#    materialFilter_on: BoolProperty(name="Material filtering", description="(*todo) Material filtering   on/off", default=False)
#    colorFilter_on: BoolProperty(name="Color filtering", description="(*todo) Color filtering   on/off", default=False)
#    groupFilter_on: BoolProperty(name="Group filtering", description="(*todo) Group filtering   on/off", default=False)
#    objectFilter_on: BoolProperty(name="Object filtering", description="(*todo) Object filtering   on/off", default=False)
#    paper_space_on: EnumProperty(name="Space of export:", default="2",
#                                    description="Select space that will be taken for export.",
#                                    items=spaceItems)
#    material_to: EnumProperty(name="Material assigned to?:", default="NO",
#                                    description="Material assigned to?.",
#                                    items=material_toItems)

#    prefix_def: StringProperty(name="Prefix for LAYERs", default="DX_",
#                                    description='Type Prefix for LAYERs')
#    layername_def: StringProperty(name="default LAYER name", default="DEF_LAY",
#                                    description='Type default LAYER name')
#    layercolor_def: StringProperty(name="Default layer color:", default="1",
#                                    description='Set default COLOR. (0=BYBLOCK,256=BYLAYER)')
#    layerltype_def: StringProperty(name="Default LINETYPE", default="DEF_LAY_TYPE",
#                                    description='Set default LINETYPE')

    verbose: BoolProperty(name="Verbose", default=False,
                           description="Run the exporter in debug mode.  Check the console for output")

    def execute(self, context):
        filePath = bpy.path.ensure_ext(self.filepath, ".dxf")
        config = {
            'projectionThrough' : self._checkNO(self.projectionThrough),
            'onlySelected' : self.onlySelected,
            'apply_modifiers' : self.apply_modifiers,
            # GUI B
            'mesh_as' : self._checkNO(self.mesh_as),
#            'curve_as' : self._checkNO(self.curve_as),
#            'surface_as' : self._checkNO(self.surface_as),
#            'meta_as' : self._checkNO(self.meta_as),
#            'text_as' : self._checkNO(self.text_as),
#            'empty_as' : self._checkNO(self.empty_as),
#            'group_as' : self._checkNO(self.group_as),
#            'proxy_as' : self._checkNO(self.proxy_as),
#            'camera_as' : self._checkNO(self.camera_as),
#            'light_as' : self._checkNO(self.light_as),

            'entitylayer_from' : self.entitylayer_from,
            'entitycolor_from' : self.entitycolor_from,
            'entityltype_from' : self.entityltype_from,
            'layerName_from' : self.layerName_from,

            # NOT USED
#            'layFrozen_on' : self.layFrozen_on,
#            'materialFilter_on' : self.materialFilter_on,
#            'colorFilter_on' : self.colorFilter_on,
#            'groupFilter_on' : self.groupFilter_on,
#            'objectFilter_on' : self.objectFilter_on,
#            'paper_space_on' : self.paper_space_on,
#            'layercolor_def' : self.layercolor_def,
#            'material_to' : self.material_to,

            'verbose' : self.verbose
        }

        from .export_dxf import exportDXF
        exportDXF(context, filePath, config)
        return {'FINISHED'}

    def _checkNO(self, val):
        if val == 'NO': return None
        else: return val

    def invoke(self, context, event):
        if not self.filepath:
            self.filepath = bpy.path.ensure_ext(bpy.data.filepath, ".dxf")
        WindowManager = context.window_manager
        WindowManager.fileselect_add(self)
        return {'RUNNING_MODAL'}