1 # SPDX-License-Identifier: GPL-2.0-or-later
4 from bpy
.types
import Operator
, AddonPreferences
5 from bpy_extras
.io_utils
import ImportHelper
, ExportHelper
6 from bpy
.props
import (
14 from io_mesh_atomic
.xyz_import
import import_xyz
15 from io_mesh_atomic
.xyz_import
import ALL_FRAMES
16 from io_mesh_atomic
.xyz_import
import ELEMENTS
17 from io_mesh_atomic
.xyz_import
import STRUCTURE
18 from io_mesh_atomic
.xyz_import
import build_frames
19 from io_mesh_atomic
.xyz_export
import export_xyz
21 # -----------------------------------------------------------------------------
24 # This is the class for the file dialog.
25 class IMPORT_OT_xyz(Operator
, ImportHelper
):
26 bl_idname
= "import_mesh.xyz"
27 bl_label
= "Import XYZ (*.xyz)"
28 bl_options
= {'PRESET', 'UNDO'}
31 filter_glob
: StringProperty(default
="*.xyz", options
={'HIDDEN'},)
33 use_camera
: BoolProperty(
34 name
="Camera", default
=False,
35 description
="Do you need a camera?")
36 use_lamp
: BoolProperty(
37 name
="Lamp", default
=False,
38 description
= "Do you need a lamp?")
41 description
="Choose ball",
42 items
=(('0', "NURBS", "NURBS balls"),
43 ('1', "Mesh" , "Mesh balls"),
44 ('2', "Meta" , "Metaballs")),
46 mesh_azimuth
: IntProperty(
47 name
= "Azimuth", default
=32, min=1,
48 description
= "Number of sectors (azimuth)")
49 mesh_zenith
: IntProperty(
50 name
= "Zenith", default
=32, min=1,
51 description
= "Number of sectors (zenith)")
52 scale_ballradius
: FloatProperty(
53 name
= "Balls", default
=1.0, min=0.0001,
54 description
= "Scale factor for all atom radii")
55 scale_distances
: FloatProperty (
56 name
= "Distances", default
=1.0, min=0.0001,
57 description
= "Scale factor for all distances")
58 atomradius
: EnumProperty(
59 name
="Type of radius",
60 description
="Choose type of atom radius",
61 items
=(('0', "Pre-defined", "Use pre-defined radius"),
62 ('1', "Atomic", "Use atomic radius"),
63 ('2', "van der Waals", "Use van der Waals radius")),
65 use_center
: BoolProperty(
66 name
= "Object to origin (first frames)", default
=False,
67 description
= "Put the object into the global origin, the first frame only")
68 use_center_all
: BoolProperty(
69 name
= "Object to origin (all frames)", default
=True,
70 description
= "Put the object into the global origin, all frames")
71 datafile
: StringProperty(
72 name
= "", description
="Path to your custom data file",
73 maxlen
= 256, default
= "", subtype
='FILE_PATH')
74 use_frames
: BoolProperty(
75 name
= "Load all frames?", default
=False,
76 description
= "Do you want to load all frames?")
77 skip_frames
: IntProperty(
78 name
="", default
=0, min=0,
79 description
="Number of frames you want to skip")
80 images_per_key
: IntProperty(
81 name
="", default
=1, min=1,
82 description
="Choose the number of images between 2 keys")
84 # This thing here just guarantees that the menu entry is not active when the
85 # check box in the addon preferences is not activated! See __init__.py
87 def poll(cls
, context
):
88 pref
= context
.preferences
89 return pref
.addons
[__package__
].preferences
.bool_xyz
91 def draw(self
, context
):
94 row
.prop(self
, "use_camera")
95 row
.prop(self
, "use_lamp")
97 row
.prop(self
, "use_center")
99 row
.prop(self
, "use_center_all")
103 row
.label(text
="Balls / atoms")
106 col
.prop(self
, "ball")
108 row
.active
= (self
.ball
== "1")
109 col
= row
.column(align
=True)
110 col
.prop(self
, "mesh_azimuth")
111 col
.prop(self
, "mesh_zenith")
114 col
.label(text
="Scaling factors")
115 col
= row
.column(align
=True)
116 col
.prop(self
, "scale_ballradius")
117 col
.prop(self
, "scale_distances")
119 row
.prop(self
, "atomradius")
123 row
.label(text
="Frames")
125 row
.prop(self
, "use_frames")
127 row
.active
= self
.use_frames
129 col
.label(text
="Skip frames")
131 col
.prop(self
, "skip_frames")
133 row
.active
= self
.use_frames
135 col
.label(text
="Frames/key")
137 col
.prop(self
, "images_per_key")
139 def execute(self
, context
):
140 # Switch to 'OBJECT' mode when in 'EDIT' mode.
141 if bpy
.context
.mode
== 'EDIT_MESH':
142 bpy
.ops
.object.mode_set(mode
='OBJECT', toggle
=False)
148 # This is to determine the path.
149 filepath_xyz
= bpy
.path
.abspath(self
.filepath
)
151 # Execute main routine
152 import_xyz(self
.ball
,
155 self
.scale_ballradius
,
157 self
.scale_distances
,
165 if len(ALL_FRAMES
) > 1 and self
.use_frames
:
167 build_frames(self
.images_per_key
, self
.skip_frames
)
172 # This is the class for the file dialog of the exporter.
173 class EXPORT_OT_xyz(Operator
, ExportHelper
):
174 bl_idname
= "export_mesh.xyz"
175 bl_label
= "Export XYZ (*.xyz)"
176 filename_ext
= ".xyz"
178 filter_glob
: StringProperty(
179 default
="*.xyz", options
={'HIDDEN'},)
181 atom_xyz_export_type
: EnumProperty(
182 name
="Type of Objects",
183 description
="Choose type of objects",
184 items
=(('0', "All", "Export all active objects"),
185 ('1', "Elements", "Export only those active objects which have"
186 " a proper element name")),
189 # This thing here just guarantees that the menu entry is not active when the
190 # check box in the addon preferences is not activated! See __init__.py
192 def poll(cls
, context
):
193 pref
= context
.preferences
194 return pref
.addons
[__package__
].preferences
.bool_xyz
196 def draw(self
, context
):
199 row
.prop(self
, "atom_xyz_export_type")
201 def execute(self
, context
):
202 export_xyz(self
.atom_xyz_export_type
, bpy
.path
.abspath(self
.filepath
))