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