(self, context)
| 378 | |
| 379 | |
| 380 | def import_node_tree(self, context): |
| 381 | if context.scene.node_io_import_type == "1": # single file |
| 382 | import_path = bpy.path.abspath(context.scene.node_io_import_path_file) |
| 383 | folder_path = path.dirname(import_path) |
| 384 | else: # all files in folder |
| 385 | import_path = bpy.path.abspath(context.scene.node_io_import_path_dir) |
| 386 | folder_path = import_path |
| 387 | |
| 388 | # check file path |
| 389 | if not import_path: |
| 390 | self.report({"ERROR"}, "NodeIO: Empty Import Path") |
| 391 | return |
| 392 | elif not path.exists(import_path): |
| 393 | self.report({"ERROR"}, "NodeIO: Filepath '{}' Does Not Exist".format(import_path)) |
| 394 | return |
| 395 | elif context.scene.node_io_import_type == "1" and not import_path.endswith(".bnodes") and \ |
| 396 | not import_path.endswith('.zip'): |
| 397 | self.report({"ERROR"}, "NodeIO: Filepath Does Not End With .bnodes") |
| 398 | return |
| 399 | |
| 400 | # collect filepaths |
| 401 | import_list = [] |
| 402 | |
| 403 | if context.scene.node_io_import_type == "2" and not import_path.endswith('.zip'): # import all files in folder |
| 404 | files = listdir(import_path) |
| 405 | |
| 406 | for file in files: |
| 407 | if file.endswith(".bnodes"): |
| 408 | import_list.append(import_path + os_file_sep + file) |
| 409 | elif import_path.endswith('.zip'): |
| 410 | zip_folder = zipfile.ZipFile(import_path) |
| 411 | folder_path = path.dirname(import_path) + os_file_sep + path.basename(import_path).split(".")[0] |
| 412 | |
| 413 | try: |
| 414 | mkdir(folder_path) # create new folder |
| 415 | except FileExistsError: |
| 416 | self.report({"INFO"}, "NodeIO: Folder Already Exists") |
| 417 | |
| 418 | for file_name in zip_folder.namelist(): # open zip file and write it to new directory |
| 419 | f = open(folder_path + os_file_sep + file_name, 'wb') |
| 420 | f.write(zip_folder.open(file_name, 'r').read()) |
| 421 | f.close() |
| 422 | |
| 423 | if file_name.endswith('.bnodes'): |
| 424 | import_list.append(folder_path + os_file_sep + file_name) |
| 425 | else: |
| 426 | import_list.append(import_path) |
| 427 | |
| 428 | # for each .bnodes file import and create material |
| 429 | for file_path in import_list: |
| 430 | file = open(file_path, 'r') |
| 431 | root = json.load(file) |
| 432 | file.close() |
| 433 | |
| 434 | node_tree, nodes, links = None, None, None |
| 435 | |
| 436 | # determine type |
| 437 | if root['__info__']['node_tree_id'] == 'ShaderNodeTree': |
no test coverage detected