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
78
79
80
81
82
83
84
85
86
87
88
89
90
use std::env::temp_dir;
use std::fs::File;
use std::io::Write;
use std::process::Command;
pub fn install_mesh_to_json() -> std::io::Result<()> {
let addon_file_path = temp_dir().join("blender-mesh-to-json.py");
let mesh_to_json_addon = include_str!("../../blender-mesh-to-json.py");
let mut addon_file = File::create(&addon_file_path)?;
addon_file.write_all(mesh_to_json_addon.as_bytes()).unwrap();
let install_mesh_to_json_script = format!(
r#"
# Install the addon and save the user's preferences
import bpy
import os
# Get the absolute path to the addon
dir = os.path.dirname(__file__)
addonFilePath = r'{}'
# Install the addon, enable it and save the user's preferences so that it
# is available whenever Blender is opened in the future
bpy.ops.preferences.addon_install(filepath=addonFilePath)
bpy.ops.preferences.addon_enable(module='blender-mesh-to-json')
bpy.ops.wm.save_userpref()
"#,
addon_file_path.display()
);
let blender_executable = "blender";
Command::new(blender_executable)
.arg("--background")
.args(&["--python-expr", &install_mesh_to_json_script])
.arg("-noaudio")
.spawn()
.unwrap()
.wait()
.unwrap();
Ok(())
}
pub fn install_armature_to_json() -> std::io::Result<()> {
let addon_file_path = temp_dir().join("blender-armature-to-json.py");
let armature_to_json = include_str!("../../blender-armature-to-json.py");
let mut addon_file = File::create(&addon_file_path)?;
addon_file.write_all(armature_to_json.as_bytes()).unwrap();
let install_armature_to_json_script = format!(
r#"
import bpy
addonFilePath = r'{}'
# Install the addon, enable it and save the user's preferences so that it
# is available whenever Blender is opened in the future
bpy.ops.preferences.addon_install(filepath=addonFilePath)
bpy.ops.preferences.addon_enable(module='blender-armature-to-json')
bpy.ops.wm.save_userpref()
"#,
addon_file_path.display()
);
let blender_executable = "blender";
Command::new(blender_executable)
.arg("--background")
.args(&["--python-expr", &install_armature_to_json_script])
.arg("-noaudio")
.spawn()
.unwrap()
.wait()
.unwrap();
Ok(())
}