# ##### BEGIN GPL LICENSE BLOCK ####### This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# of the License, or (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software Foundation,# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## ##### END GPL LICENSE BLOCK #####bl_info = { "name": "Export Engrid (.begc)", "author": "test", "version": (0, 1), "blender": (2, 6, 0), "api": 36079, "location": "File > Export > Engrid (.begc)", "description": "Export mesh Engrid data (.begc)", "warning": "", "wiki_url": "", "tracker_url": "", "category": "Import-Export"}'''Usage Notes:'''import bpyfrom bpy.props import *import mathutils, math, structfrom os import removeimport timefrom bpy_extras.io_utils import ExportHelperdef do_export(context, props, filepath): out = open(filepath, "w") out.write('%d\n' % len(bpy.data.meshes)) node_offset = 0 for mesh in bpy.data.meshes: out.write(mesh.name) out.write('\n') for mesh in bpy.data.meshes: faces = mesh.faces nodes = mesh.vertices out.write('%d' % len(nodes)) out.write(' %d\n' % len(faces)) for n in nodes: out.write("%e " % n.co[0]) out.write("%e " % n.co[1]) out.write("%e\n" % n.co[2]) for f in faces: out.write("%d" % len(f.vertices)) for v in f.vertices: out.write(' %d' % (v + node_offset)) out.write('\n') node_offset = node_offset + len(nodes) out.flush() out.close() return True###### EXPORT OPERATOR #######class Export_engrid(bpy.types.Operator, ExportHelper): bl_idname = "export_shape.engrid" bl_label = "Export Engrid (.begc)" filename_ext = ".begc" @classmethod def poll(cls, context): return context.active_object.type in {'MESH', 'CURVE', 'SURFACE', 'FONT'} def execute(self, context): start_time = time.time() print('\n_____START_____') props = self.properties filepath = self.filepath filepath = bpy.path.ensure_ext(filepath, self.filename_ext) exported = do_export(context, props, filepath) if exported: print('finished export in %s seconds' %((time.time() - start_time))) print(filepath) return {'FINISHED'} def invoke(self, context, event): wm = context.window_manager if True: # File selector wm.fileselect_add(self) # will run self.execute() return {'RUNNING_MODAL'} elif True: # search the enum wm.invoke_search_popup(self) return {'RUNNING_MODAL'} elif False: # Redo popup return wm.invoke_props_popup(self, event) elif False: return self.execute(context)### REGISTER ###def menu_func(self, context): self.layout.operator(Export_engrid.bl_idname, text="Engrid (.begc)")def register(): bpy.utils.register_module(__name__) bpy.types.INFO_MT_file_export.append(menu_func)def unregister(): bpy.utils.unregister_module(__name__) bpy.types.INFO_MT_file_export.remove(menu_func) if __name__ == "__main__": register()
# ##### BEGIN GPL LICENSE BLOCK ####### This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# of the License, or (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software Foundation,# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## ##### END GPL LICENSE BLOCK #####bl_info = { "name": "Export to enGrid (.begc)", "author": "Unknown Author", "version": (0, 1), "blender": (2, 5, 9), "api": 36079, "location": "File > Export > enGrid (.begc)", "description": "Export objects as boundaries to enGrid's Blender exchange format (*.begc)", "warning": "", "wiki_url": "http://engits.eu/wiki", "tracker_url": "http://sourceforge.net/apps/mantisbt/engrid", "category": "Import-Export"}'''Usage Notes:'''import bpyfrom bpy.props import *import mathutils, math, structfrom os import removeimport timefrom bpy_extras.io_utils import ExportHelperdef do_export(context, props, filepath): out = open(filepath, "w") out.write('%d\n' % len(bpy.data.meshes)) node_offset = 0 for obj in bpy.data.objects: if obj.type == 'MESH': out.write(obj.name) out.write('\n') for obj in bpy.data.objects: if obj.type == 'MESH': mesh = obj.data mesh.transform(obj.matrix_world) faces = mesh.faces nodes = mesh.vertices out.write('%d' % len(nodes)) out.write(' %d\n' % len(faces)) for n in nodes: out.write("%e " % n.co[0]) out.write("%e " % n.co[1]) out.write("%e\n" % n.co[2]) for f in faces: out.write("%d" % len(f.vertices)) for v in f.vertices: out.write(' %d' % (v + node_offset)) out.write('\n') node_offset = node_offset + len(nodes) out.flush() out.close() return True###### EXPORT OPERATOR #######class Export_engrid(bpy.types.Operator, ExportHelper): bl_idname = "export_shape.engrid" bl_label = "Export enGrid (.begc)" filename_ext = ".begc" @classmethod def poll(cls, context): return context.active_object.type in {'MESH', 'CURVE', 'SURFACE', 'FONT'} def execute(self, context): start_time = time.time() print('\n_____START_____') props = self.properties filepath = self.filepath filepath = bpy.path.ensure_ext(filepath, self.filename_ext) exported = do_export(context, props, filepath) if exported: print('finished export in %s seconds' %((time.time() - start_time))) print(filepath) return {'FINISHED'} def invoke(self, context, event): wm = context.window_manager if True: # File selector wm.fileselect_add(self) # will run self.execute() return {'RUNNING_MODAL'} elif True: # search the enum wm.invoke_search_popup(self) return {'RUNNING_MODAL'} elif False: # Redo popup return wm.invoke_props_popup(self, event) elif False: return self.execute(context)### REGISTER ###def menu_func(self, context): self.layout.operator(Export_engrid.bl_idname, text="enGrid (.begc)")def register(): bpy.utils.register_module(__name__) bpy.types.INFO_MT_file_export.append(menu_func)def unregister(): bpy.utils.unregister_module(__name__) bpy.types.INFO_MT_file_export.remove(menu_func) if __name__ == "__main__": register()
# ##### BEGIN GPL LICENSE BLOCK ####### This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# of the License, or (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software Foundation,# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## ##### END GPL LICENSE BLOCK #####bl_info = { "name": "Export to enGrid (.begc)", "author": "Unknown Author", "version": (0, 2), "blender": (2, 5, 9), "api": 36079, "location": "File > Export > enGrid (.begc)", "description": "Export objects as boundaries to enGrid's Blender exchange format (*.begc)", "warning": "", "wiki_url": "http://engits.eu/wiki", "tracker_url": "http://sourceforge.net/apps/mantisbt/engrid", "category": "Import-Export"}'''Usage Notes:'''import bpyfrom bpy.props import *import mathutils, math, structfrom os import removeimport timefrom bpy_extras.io_utils import ExportHelperdef do_export(context, props, filepath): mat_x90 = mathutils.Matrix.Rotation(-math.pi/2, 4, 'X') obmnames="" obmcount=0 for obj in bpy.data.objects: if obj.type == 'MESH': obmcount+=1 obmnames+=obj.name+'\n' if obmcount!=0: node_offset = 0 out = open(filepath, "w") out.write('%d' % obmcount) out.write('\n') out.write(obmnames) for obj in bpy.data.objects: if obj.type == 'MESH': mesh = obj.to_mesh(context.scene, props.apply_modifiers, 'PREVIEW') if props.world_space: mesh.transform(obj.matrix_world) if props.rot_x90: mesh.transform(mat_x90) faces = mesh.faces nodes = mesh.vertices out.write('%d' % len(nodes)) out.write(' %d\n' % len(faces)) for n in nodes: out.write("%e " % n.co[0]) out.write("%e " % n.co[1]) out.write("%e\n" % n.co[2]) for f in faces: out.write("%d" % len(f.vertices)) for v in f.vertices: out.write(' %d' % (v + node_offset)) out.write('\n') node_offset = node_offset + len(nodes) out.flush() out.close() return True###### EXPORT OPERATOR #######class Export_engrid(bpy.types.Operator, ExportHelper): bl_idname = "export_shape.engrid" bl_label = "Export enGrid (.begc)" filepath = "untitled" filename_ext = ".begc" rot_x90 = BoolProperty(name="Convert to Y-up", description="Rotate 90 degrees around X to convert to y-up", default=False, ) world_space = BoolProperty(name="Export into Worldspace", description="Transform the Vertexcoordinates into Worldspace", default=True, ) apply_modifiers = BoolProperty(name="Apply Modifiers", description="Applies the Modifiers", default=True, ) @classmethod def poll(cls, context): return context.active_object.type in {'MESH', 'CURVE', 'SURFACE', 'FONT'} def execute(self, context): start_time = time.time() print('\n_____START_____') print(self.filepath) props = self.properties filepath = self.filepath filepath = bpy.path.ensure_ext(filepath, self.filename_ext) print(self.filepath) exported = do_export(context, props, filepath) if exported: print('finished export in %s seconds' %((time.time() - start_time))) print(filepath) return {'FINISHED'} def invoke(self, context, event): wm = context.window_manager if True: # File selector wm.fileselect_add(self) # will run self.execute() return {'RUNNING_MODAL'} elif True: # search the enum wm.invoke_search_popup(self) return {'RUNNING_MODAL'} elif False: # Redo popup return wm.invoke_props_popup(self, event) elif False: return self.execute(context)### REGISTER ###def menu_func(self, context): self.layout.operator(Export_engrid.bl_idname, text="enGrid (.begc)")def register(): bpy.utils.register_module(__name__) bpy.types.INFO_MT_file_export.append(menu_func)def unregister(): bpy.utils.unregister_module(__name__) bpy.types.INFO_MT_file_export.remove(menu_func)if __name__ == "__main__": register()
#!BPY# # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++# + +# + This file is part of enGrid. +# + +# + Copyright 2008-2010 enGits GmbH +# + +# + enGrid is free software: you can redistribute it and/or modify +# + it under the terms of the GNU General Public License as published by +# + the Free Software Foundation, either version 3 of the License, or +# + (at your option) any later version. +# + +# + enGrid is distributed in the hope that it will be useful, +# + but WITHOUT ANY WARRANTY; without even the implied warranty of +# + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# + GNU General Public License for more details. +# + +# + You should have received a copy of the GNU General Public License +# + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +# + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++# """Name: 'Engrid (*.begc)'Blender: 249Group: 'Export'Tooltip: 'Export to Engrid'"""import Blenderimport bpydef write(filename): Blender.Window.WaitCursor(1) if not filename.lower().endswith('.begc'): filename += '.begc' out = file(filename, "w") objects = Blender.Object.GetSelected() num_objects = 0 for object in objects: if object.type == 'Mesh': num_objects = num_objects + 1 out.write('%d\n' % num_objects) node_offset = 0 for object in objects: if object.type == 'Mesh': out.write(object.name) out.write('\n') for object in objects: if object.type == 'Mesh': mesh = object.getData(0,1) faces = mesh.faces nodes = mesh.verts out.write('%d' % len(nodes)) out.write(' %d\n' % len(faces)) for n in nodes: out.write("%e " % n.co[0]) out.write("%e " % n.co[1]) out.write("%e\n" % n.co[2]) for f in faces: N = len(f.verts) if N < 3 and N > 4: Blender.Draw.PupMenu('Error%t|Only triangles and quads allowed') return out.write("%d" % N) for v in f.verts: out.write(' %d' % (v.index + node_offset)) out.write('\n') node_offset = node_offset + len(nodes) Blender.Window.WaitCursor(0)Blender.Window.FileSelector(write, "Export", Blender.sys.makename(ext='.begc'))
import bpyimport mathimport xml.dom.minidomfrom xml.dom.minidom import Nodedef parse_osm(filename): doc = xml.dom.minidom.parse(filename) lon_min = 180.0 lon_max = 0.0 lat_min = 180.0 lat_max = 0.0 for node in doc.getElementsByTagName("node"): lon = float(node.getAttribute("lon")) lat = float(node.getAttribute("lat")) if lon_min>lon: lon_min=lon if lon_max<lon: lon_max=lon if lat_min>lat: lat_min=lat if lat_max<lat: lat_max=lat lon_c=(lon_max+lon_min)/2 lat_c=(lat_max+lat_min)/2 r=6378245.0 l=math.pi*r/2 nodes={} for node in doc.getElementsByTagName("node"): id = str(node.getAttribute("id")) lon = float(node.getAttribute("lon")) lat = float(node.getAttribute("lat")) lonm = lon-lon_c n = l*(lat-lat_c)/90 e = l*math.cos(math.radians(lat))*(lon-lon_c)/90 nodes[id]=(e,n,0) for way in doc.getElementsByTagName("way"): id=way.getAttribute("id") bpy.ops.curve.primitive_nurbs_path_add() curve = bpy.context.object curve.name="id"+id bpy.ops.object.editmode_toggle() bpy.ops.curve.delete(type='ALL') for tag in way.getElementsByTagName("tag"): k = tag.getAttribute("k") v = tag.getAttribute("v") curve[k]=v for noderef in way.getElementsByTagName("nd"): ref = noderef.getAttribute("ref") nd = nodes[ref] bpy.ops.curve.vertex_add(location=nd) bpy.ops.curve.select_all(action='SELECT') bpy.ops.curve.handle_type_set(type='VECTOR') bpy.ops.object.editmode_toggle() def main(): filename = '... insert name xml datafile ...' parse_osm(filename)main()