[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3855] contrib/py/scripts/addons/ io_mesh_xyz:
Clemens Barth
barth at root-1.de
Sun Oct 14 13:57:01 CEST 2012
Revision: 3855
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3855
Author: blendphys
Date: 2012-10-14 11:57:01 +0000 (Sun, 14 Oct 2012)
Log Message:
-----------
New feature: export xyz - One can now export selected atoms into a xyz file. The
code is basically the same as the one for the PDB exporter.
Modified Paths:
--------------
contrib/py/scripts/addons/io_mesh_xyz/__init__.py
Added Paths:
-----------
contrib/py/scripts/addons/io_mesh_xyz/export_xyz.py
Modified: contrib/py/scripts/addons/io_mesh_xyz/__init__.py
===================================================================
--- contrib/py/scripts/addons/io_mesh_xyz/__init__.py 2012-10-14 11:54:11 UTC (rev 3854)
+++ contrib/py/scripts/addons/io_mesh_xyz/__init__.py 2012-10-14 11:57:01 UTC (rev 3855)
@@ -21,11 +21,11 @@
# Authors : Clemens Barth (Blendphys at root-1.de), ...
#
# Homepage(Wiki) : http://development.root-1.de/Atomic_Blender.php
-# Tracker : ... soon
+# Tracker : http://projects.blender.org/tracker/index.php?func=detail&aid=29646&group_id=153&atid=468
#
# Start of project : 2011-12-01 by Clemens Barth
# First publication in Blender : 2011-12-18
-# Last modified : 2012-10-13
+# Last modified : 2012-10-14
#
# Acknowledgements: Thanks to ideasman, meta_androcto, truman, kilon,
# dairin0d, PKHG, Valter, etc
@@ -51,7 +51,7 @@
import bpy
import bmesh
from bpy.types import Operator, Panel
-from bpy_extras.io_utils import ImportHelper
+from bpy_extras.io_utils import ImportHelper, ExportHelper
from bpy.props import (StringProperty,
BoolProperty,
EnumProperty,
@@ -59,6 +59,8 @@
FloatProperty)
from . import import_xyz
+from . import export_xyz
+
ATOM_XYZ_ERROR = ""
ATOM_XYZ_NOTE = ""
ATOM_XYZ_PANEL = ""
@@ -829,21 +831,56 @@
return {'FINISHED'}
+# This is the class for the file dialog of the exporter.
+class CLASS_ExportXYZ(Operator, ExportHelper):
+ bl_idname = "export_mesh.xyz"
+ bl_label = "Export XYZ (*.xyz)"
+ filename_ext = ".xyz"
+
+ filter_glob = StringProperty(
+ default="*.xyz", options={'HIDDEN'},)
+
+ atom_xyz_export_type = EnumProperty(
+ name="Type of Objects",
+ description="Choose type of objects",
+ items=(('0', "All", "Export all active objects"),
+ ('1', "Elements", "Export only those active objects which have"
+ " a proper element name")),
+ default='1',)
+
+ def draw(self, context):
+ layout = self.layout
+ row = layout.row()
+ row.prop(self, "atom_xyz_export_type")
+
+ def execute(self, context):
+ # This is in order to solve this strange 'relative path' thing.
+ export_xyz.ATOM_XYZ_FILEPATH = bpy.path.abspath(self.filepath)
+ export_xyz.DEF_atom_xyz_export(self.atom_xyz_export_type)
+
+ return {'FINISHED'}
+
+
# The entry into the menu 'file -> import'
-def menu_func(self, context):
+def DEF_menu_func(self, context):
self.layout.operator(CLASS_ImportXYZ.bl_idname, text="XYZ (.xyz)")
+# The entry into the menu 'file -> export'
+def DEF_menu_func_export(self, context):
+ self.layout.operator(CLASS_ExportXYZ.bl_idname, text="XYZ (.xyz)")
def register():
DEF_panel_yes_no()
bpy.utils.register_module(__name__)
- bpy.types.INFO_MT_file_import.append(menu_func)
+ bpy.types.INFO_MT_file_import.append(DEF_menu_func)
+ bpy.types.INFO_MT_file_export.append(DEF_menu_func_export)
bpy.types.Scene.atom_xyz = bpy.props.CollectionProperty(type=CLASS_atom_xyz_Properties)
bpy.context.scene.atom_xyz.add()
def unregister():
bpy.utils.unregister_module(__name__)
- bpy.types.INFO_MT_file_import.remove(menu_func)
+ bpy.types.INFO_MT_file_import.remove(DEF_menu_func)
+ bpy.types.INFO_MT_file_export.remove(DEF_menu_func_export)
if __name__ == "__main__":
Added: contrib/py/scripts/addons/io_mesh_xyz/export_xyz.py
===================================================================
--- contrib/py/scripts/addons/io_mesh_xyz/export_xyz.py (rev 0)
+++ contrib/py/scripts/addons/io_mesh_xyz/export_xyz.py 2012-10-14 11:57:01 UTC (rev 3855)
@@ -0,0 +1,104 @@
+# ##### 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 #####
+
+import bpy
+import io
+import math
+import os
+import copy
+from math import pi, cos, sin
+from mathutils import Vector, Matrix
+from copy import copy
+
+from . import import_xyz
+
+ATOM_XYZ_FILEPATH = ""
+ATOM_XYZ_XYZTEXT = ( "This XYZ file has been created with Blender "
+ + "and the addon Atomic Blender - XYZ. "
+ + "For more details see: wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/XYZ\n")
+
+
+class CLASS_atom_xyz_atoms_export(object):
+ __slots__ = ('element', 'location')
+ def __init__(self, element, location):
+ self.element = element
+ self.location = location
+
+
+def DEF_atom_xyz_export(obj_type):
+
+ list_atoms = []
+ counter = 0
+ for obj in bpy.context.selected_objects:
+
+ if "Stick" in obj.name:
+ continue
+
+ if obj.type != "SURFACE" and obj.type != "MESH":
+ continue
+
+ name = ""
+ for element in import_xyz.ATOM_XYZ_ELEMENTS_DEFAULT:
+ if element[1] in obj.name:
+ if element[2] == "Vac":
+ name = "X"
+ else:
+ name = element[2]
+ elif element[1][:3] in obj.name:
+ if element[2] == "Vac":
+ name = "X"
+ else:
+ name = element[2]
+
+ if name == "":
+ if obj_type == "0":
+ name = "?"
+ else:
+ continue
+
+ if len(obj.children) != 0:
+ for vertex in obj.data.vertices:
+ location = obj.matrix_world*vertex.co
+ list_atoms.append(CLASS_atom_xyz_atoms_export(
+ name,
+ location))
+ counter += 1
+ else:
+ if not obj.parent:
+ location = obj.location
+ list_atoms.append(CLASS_atom_xyz_atoms_export(
+ name,
+ location))
+ counter += 1
+
+ xyz_file_p = open(ATOM_XYZ_FILEPATH, "w")
+ xyz_file_p.write(str(counter)+"\n")
+ xyz_file_p.write(ATOM_XYZ_XYZTEXT)
+
+ for i, atom in enumerate(list_atoms):
+ string = "%3s%15.5f%15.5f%15.5f\n" % (
+ atom.element,
+ atom.location[0],
+ atom.location[1],
+ atom.location[2])
+ xyz_file_p.write(string)
+
+ xyz_file_p.close()
+
+ return True
+
More information about the Bf-extensions-cvs
mailing list