AnimAll: update translation
[blender-addons.git] / io_export_dxf / operator.py
blob012ffdbcfced0465419738c3d247edb541321b03
1 # SPDX-FileCopyrightText: 2012-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 import bpy
6 from bpy.props import (
7 BoolProperty,
8 EnumProperty,
9 StringProperty,
12 class DXFExporter(bpy.types.Operator):
13 """
14 Export to the Autocad model format (.dxf)
15 """
16 bl_idname = "export.dxf"
17 bl_label = "Export DXF"
18 filepath: StringProperty(subtype='FILE_PATH')
20 entitylayer_from_items = (
21 ('default_LAYER', 'Default Layer', ''),
22 ('obj.name', 'Object name', ''),
23 ('obj.layer', 'Object layer', ''),
24 ('obj.material', 'Object material', ''),
25 ('obj.data.name', 'Object\' data name', ''),
26 # ('obj.data.material', 'Material of data', ''),
27 ('..vertexgroup', 'Vertex Group', ''),
28 ('..group', 'Group', ''),
29 ('..map_table', 'Table', '')
31 layerColorFromItems = (
32 ('default_COLOR', 'Vertex Group', ''),
33 ('BYLAYER', 'BYLAYER', ''),
34 ('BYBLOCK', 'BYBLOCK', ''),
35 ('obj.layer', 'Object Layer', ''),
36 ('obj.color', 'Object Color', ''),
37 ('obj.material', 'Object material', ''),
38 # I don'd know ?
39 # ('obj.data.material', 'Vertex Group', ''),
40 # ('..map_table', 'Vertex Group', ''),
42 layerNameFromItems = (
43 ('LAYERNAME_DEF', 'Default Name', ''),
44 ('drawing_name', 'From Drawing name', ''),
45 ('scene_name', 'From scene name', '')
48 exportModeItems = (
49 ('ALL', 'All Objects', ''),
50 ('SELECTION', 'Selected Objects', ''),
52 # spaceItems = (
53 # ('1', 'Paper-Space', ''),
54 # ('2', 'Model-Space', '')
55 # )
57 entityltype_fromItems = (
58 ('default_LTYPE', 'default_LTYPE', ''),
59 ('BYLAYER', 'BYLAYER', ''),
60 ('BYBLOCK', 'BYBLOCK', ''),
61 ('CONTINUOUS', 'CONTINUOUS', ''),
62 ('DOT', 'DOT', ''),
63 ('DASHED', 'DASHED', ''),
64 ('DASHDOT', 'DASHDOT', ''),
65 ('BORDER', 'BORDER', ''),
66 ('HIDDEN', 'HIDDEN', '')
68 material_toItems = (
69 ('NO', 'Do not export', ''),
70 ('COLOR', 'COLOR', ''),
71 ('LAYER', 'LAYER', ''),
72 ('..LINESTYLE', '..LINESTYLE', ''),
73 ('..BLOCK', '..BLOCK', ''),
74 ('..XDATA', '..XDATA', ''),
75 ('..INI-File', '..INI-File', '')
77 projectionItems=(
78 ('NO', 'No projection', 'Export 3D scene without any 2D projection'),
79 ('TOP', 'TOP view', 'Use TOP view for projection'),
80 ('BOTTOM', 'BOTTOM view', 'Use BOTTOM view for projection'),
81 ('LEFT', 'LEFT view', 'Use LEFT view for projection'),
82 ('RIGHT', 'RIGHT view', 'Use RIGHT view for projection'),
83 ('FRONT', 'FRONT view', 'Use FRONT view for projection'),
84 ('REAR', 'REAR view', 'Use REAR view for projection')
86 mesh_asItems = (
87 ('NO', 'Do not export', ''),
88 ('3DFACEs', '3DFACEs', ''),
89 ('POLYFACE', 'POLYFACE', ''),
90 ('POLYLINE', 'POLYLINE', ''),
91 ('LINEs', 'LINEs', 'export Mesh as multiple LINEs'),
92 ('POINTs', 'POINTs', 'Export Mesh as multiple POINTs')
94 # curve_asItems = (
95 # ('NO', 'Do not export', ''),
96 # ('LINEs', 'LINEs', ''),
97 # ('POLYLINE', 'POLYLINE', ''),
98 # ('..LWPOLYLINE r14', '..LWPOLYLINE r14', ''),
99 # ('..SPLINE r14', '..SPLINE r14', ''),
100 # ('POINTs', 'POINTs', '')
102 # surface_asItems = (
103 # ('NO', 'Do not export', ''),
104 # ('..3DFACEs', '..3DFACEs', ''),
105 # ('..POLYFACE', '..POLYFACE', ''),
106 # ('..POINTs', '..POINTs', ''),
107 # ('..NURBS', '..NURBS', '')
109 # meta_asItems = (
110 # ('NO', 'Do not export', ''),
111 # ('..3DFACEs', '..3DFACEs', ''),
112 # ('..POLYFACE', '..POLYFACE', ''),
113 # ('..3DSOLID', '..3DSOLID', '')
115 # text_asItems = (
116 # ('NO', 'Do not export', ''),
117 # ('TEXT', 'TEXT', ''),
118 # ('..MTEXT', '..MTEXT', ''),
119 # ('..ATTRIBUT', '..ATTRIBUT', '')
121 # empty_asItems = (
122 # ('NO', 'Do not export', ''),
123 # ('POINT', 'POINT', ''),
124 # ('..INSERT', '..INSERT', ''),
125 # ('..XREF', '..XREF', '')
127 # group_asItems = (
128 # ('NO', 'Do not export', ''),
129 # ('..GROUP', '..GROUP', ''),
130 # ('..BLOCK', '..BLOCK', ''),
131 # ('..ungroup', '..ungroup', '')
133 ## parent_asItems = ['..BLOCK','..ungroup'] # ???
134 # proxy_asItems = (
135 # ('NO', 'Do not export', ''),
136 # ('..BLOCK','..BLOCK', ''),
137 # ('..XREF', '..XREF', ''),
138 # ('..ungroup', '..ungroup', ''),
139 # ('..POINT', '..POINT', '')
141 # camera_asItems = (
142 # ('NO', 'Do not export', ''),
143 # ('..BLOCK', '..BLOCK', ''),
144 # ('..A_CAMERA', '..A_CAMERA', ''),
145 # ('VPORT', 'VPORT', ''),
146 # ('VIEW', 'VIEW', ''),
147 # ('POINT', 'POINT', '')
149 # light_asItems = (
150 # ('NO', 'Do not export', ''),
151 # ('..BLOCK', '..BLOCK', ''),
152 # ('..A_LIGHT', '..A_LIGHT', ''),
153 # ('POINT', 'POINT', '')
155 # --------- CONTROL PROPERTIES --------------------------------------------
156 projectionThrough: EnumProperty(name="Projection", default="NO",
157 description="Select camera for use to 2D projection",
158 items=projectionItems)
160 onlySelected: BoolProperty(name="Only selected", default=True,
161 description="What object will be exported? Only selected / all objects")
163 apply_modifiers: BoolProperty(name="Apply modifiers", default=True,
164 description="Shall be modifiers applied during export?")
165 # GUI_B -----------------------------------------
166 mesh_as: EnumProperty( name="Export Mesh As", default='3DFACEs',
167 description="Select representation of a mesh",
168 items=mesh_asItems)
169 # curve_as: EnumProperty( name="Export Curve As:", default='NO',
170 # description="Select representation of a curve",
171 # items=curve_asItems)
172 # surface_as: EnumProperty( name="Export Surface As:", default='NO',
173 # description="Select representation of a surface",
174 # items=surface_asItems)
175 # meta_as: EnumProperty( name="Export meta As:", default='NO',
176 # description="Select representation of a meta",
177 # items=meta_asItems)
178 # text_as: EnumProperty( name="Export text As:", default='NO',
179 # description="Select representation of a text",
180 # items=text_asItems)
181 # empty_as: EnumProperty( name="Export empty As:", default='NO',
182 # description="Select representation of a empty",
183 # items=empty_asItems)
184 # group_as: EnumProperty( name="Export group As:", default='NO',
185 # description="Select representation of a group",
186 # items=group_asItems)
187 ## parent_as: EnumProperty( name="Export parent As:", default='NO',
188 ## description="Select representation of a parent",
189 ## items=parent_asItems)
190 # proxy_as: EnumProperty( name="Export proxy As:", default='NO',
191 # description="Select representation of a proxy",
192 # items=proxy_asItems)
193 # camera_as: EnumProperty( name="Export camera As:", default='NO',
194 # description="Select representation of a camera",
195 # items=camera_asItems)
196 # light_as: EnumProperty( name="Export lamp As:", default='NO',
197 # description="Select representation of a lamp",
198 # items=light_asItems)
199 # ----------------------------------------------------------
200 entitylayer_from: EnumProperty(name="Entity Layer", default="obj.data.name",
201 description="Entity LAYER assigned to?",
202 items=entitylayer_from_items)
203 entitycolor_from: EnumProperty(name="Entity Color", default="default_COLOR",
204 description="Entity COLOR assigned to?",
205 items=layerColorFromItems)
206 entityltype_from: EnumProperty(name="Entity Linetype", default="CONTINUOUS",
207 description="Entity LINETYPE assigned to?",
208 items=entityltype_fromItems)
210 layerName_from: EnumProperty(name="Layer Name", default="LAYERNAME_DEF",
211 description="From where will layer name be taken?",
212 items=layerNameFromItems)
213 # GUI_A -----------------------------------------
214 # layFrozen_on: BoolProperty(name="LAYER.frozen status", description="(*todo) Support LAYER.frozen status on/off", default=False)
215 # materialFilter_on: BoolProperty(name="Material filtering", description="(*todo) Material filtering on/off", default=False)
216 # colorFilter_on: BoolProperty(name="Color filtering", description="(*todo) Color filtering on/off", default=False)
217 # groupFilter_on: BoolProperty(name="Group filtering", description="(*todo) Group filtering on/off", default=False)
218 # objectFilter_on: BoolProperty(name="Object filtering", description="(*todo) Object filtering on/off", default=False)
219 # paper_space_on: EnumProperty(name="Space of export:", default="2",
220 # description="Select space that will be taken for export.",
221 # items=spaceItems)
222 # material_to: EnumProperty(name="Material assigned to?:", default="NO",
223 # description="Material assigned to?.",
224 # items=material_toItems)
226 # prefix_def: StringProperty(name="Prefix for LAYERs", default="DX_",
227 # description='Type Prefix for LAYERs')
228 # layername_def: StringProperty(name="default LAYER name", default="DEF_LAY",
229 # description='Type default LAYER name')
230 # layercolor_def: StringProperty(name="Default layer color:", default="1",
231 # description='Set default COLOR. (0=BYBLOCK,256=BYLAYER)')
232 # layerltype_def: StringProperty(name="Default LINETYPE", default="DEF_LAY_TYPE",
233 # description='Set default LINETYPE')
235 verbose: BoolProperty(name="Verbose", default=False,
236 description="Run the exporter in debug mode. Check the console for output")
238 def execute(self, context):
239 filePath = bpy.path.ensure_ext(self.filepath, ".dxf")
240 config = {
241 'projectionThrough' : self._checkNO(self.projectionThrough),
242 'onlySelected' : self.onlySelected,
243 'apply_modifiers' : self.apply_modifiers,
244 # GUI B
245 'mesh_as' : self._checkNO(self.mesh_as),
246 # 'curve_as' : self._checkNO(self.curve_as),
247 # 'surface_as' : self._checkNO(self.surface_as),
248 # 'meta_as' : self._checkNO(self.meta_as),
249 # 'text_as' : self._checkNO(self.text_as),
250 # 'empty_as' : self._checkNO(self.empty_as),
251 # 'group_as' : self._checkNO(self.group_as),
252 # 'proxy_as' : self._checkNO(self.proxy_as),
253 # 'camera_as' : self._checkNO(self.camera_as),
254 # 'light_as' : self._checkNO(self.light_as),
256 'entitylayer_from' : self.entitylayer_from,
257 'entitycolor_from' : self.entitycolor_from,
258 'entityltype_from' : self.entityltype_from,
259 'layerName_from' : self.layerName_from,
261 # NOT USED
262 # 'layFrozen_on' : self.layFrozen_on,
263 # 'materialFilter_on' : self.materialFilter_on,
264 # 'colorFilter_on' : self.colorFilter_on,
265 # 'groupFilter_on' : self.groupFilter_on,
266 # 'objectFilter_on' : self.objectFilter_on,
267 # 'paper_space_on' : self.paper_space_on,
268 # 'layercolor_def' : self.layercolor_def,
269 # 'material_to' : self.material_to,
271 'verbose' : self.verbose
274 from .export_dxf import exportDXF
275 exportDXF(context, filePath, config)
276 return {'FINISHED'}
278 def _checkNO(self, val):
279 if val == 'NO': return None
280 else: return val
282 def invoke(self, context, event):
283 if not self.filepath:
284 self.filepath = bpy.path.ensure_ext(bpy.data.filepath, ".dxf")
285 WindowManager = context.window_manager
286 WindowManager.fileselect_add(self)
287 return {'RUNNING_MODAL'}