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