forked from pfalkingham/XROMM_BlenderTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctExp.py
More file actions
77 lines (60 loc) · 2.62 KB
/
Copy pathctExp.py
File metadata and controls
77 lines (60 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
###############################
# Script to export XYZ translations of markers in Blender XROMM toolkit
# Written By Peter FAlkingham July 2023
###############################
import bpy
from bpy.types import Operator
from bpy_extras.io_utils import ExportHelper
from bpy.props import StringProperty, BoolProperty, EnumProperty
import os
def write_marker_data(context, filepath):
f = open(filepath, 'w', encoding='utf-8')
# write the header row
#for obj in selected objects,
for obj in bpy.context.selected_objects[:-1]:
f.write(obj.name+"_x, ")
f.write(obj.name+"_y, ")
f.write(obj.name+"_z, ")
#write the last object without a comma
f.write(bpy.context.selected_objects[-1].name+"_x, ")
f.write(bpy.context.selected_objects[-1].name+"_y, ")
f.write(bpy.context.selected_objects[-1].name+"_z")
f.write("\n")
for obj in bpy.context.selected_objects[:-1]:
f.write(str(obj.location.x)+", ")
f.write(str(obj.location.y)+", ")
f.write(str(obj.location.z)+", ")
#write the last object without a comma
f.write(str(bpy.context.selected_objects[-1].location.x)+", ")
f.write(str(bpy.context.selected_objects[-1].location.y)+", ")
f.write(str(bpy.context.selected_objects[-1].location.z))
f.write("\n")
return {'FINISHED'}
###########################
# The below invokes the file picker and passes the file name to the function.
# I reused this from my ArchBooMaker scripts: https://github.com/pfalkingham/ArchBooBlender/blob/main/exportValues.py
###########################
# ExportHelper is a helper class, defines filename and
# invoke() function which calls the file selector.
class ExportMarkerData(Operator, ExportHelper):
"""This appears in the tooltip of the operator and in the generated docs"""
bl_idname = "export_data.marker_data" # important since its how bpy.ops.import_test.some_data is constructed
bl_label = "Export Marker Location Data"
# ExportHelper mixin class uses this
filename_ext = ".csv"
filter_glob: StringProperty(
default="*.csv",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
def execute(self, context):
return write_marker_data(context, self.filepath)
# Register and add to the "file selector" menu (required to use F3 search "Text Export Operator" for quick access).
def register():
bpy.utils.register_class(ExportMarkerData)
def unregister():
bpy.utils.unregister_class(ExportMarkerData)
if __name__ == "__main__":
register()
# test call
bpy.ops.export_test.some_data('INVOKE_DEFAULT')