-
Notifications
You must be signed in to change notification settings - Fork 5
/
importObject.py
36 lines (28 loc) · 1013 Bytes
/
importObject.py
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
import bpy
import os.path
import time
import json
import mathutils
file_path_obj = './scans/scan.obj'
file_path_coords = './scans/coordinates.json'
pasted = False
def checkPaste():
global file_path
global pasted
if os.path.isfile(file_path_obj) and not(pasted):
imported_object = bpy.ops.import_scene.obj(filepath=file_path_obj)
obj_object = bpy.context.selected_objects[0]
print('Imported name: ', obj_object.name)
# store the current location
loc = obj_object.location
# read coordinates
with open(file_path_coords) as json_file:
coordinates = json.load(json_file)
# adjustment values
(x,y,z) = (coordinates['x'],coordinates['y'],0.0)
# adding adjustment values to the property
obj_object.location = loc + mathutils.Vector((x,y,z))
bpy.ops.wm.save_as_mainfile(filepath=bpy.data.filepath)
pasted = True
return 1.0
bpy.app.timers.register(checkPaste)