Changeset View
Changeset View
Standalone View
Standalone View
node_wrangler.py
| Context not available. | |||||
| options={'HIDDEN', 'SKIP_SAVE'} | options={'HIDDEN', 'SKIP_SAVE'} | ||||
| ) | ) | ||||
| use_relative_path: BoolProperty( | |||||
| name='Relative Path', | |||||
| description='Select the file relative to the blend file', | |||||
| default=True | |||||
| ) | |||||
| order = [ | order = [ | ||||
| "filepath", | "filepath", | ||||
| "files", | "files", | ||||
| ] | ] | ||||
| def draw(self, context): | |||||
| layout = self.layout | |||||
| layout.alignment = 'LEFT' | |||||
| layout.prop(self, 'use_relative_path') | |||||
| @classmethod | @classmethod | ||||
| def poll(cls, context): | def poll(cls, context): | ||||
| valid = False | valid = False | ||||
| Context not available. | |||||
| print('No matching images found') | print('No matching images found') | ||||
| return {'CANCELLED'} | return {'CANCELLED'} | ||||
| # Don't override path earlier as os.path is used to check the absolute path | |||||
| import_path = self.directory | |||||
| if self.use_relative_path: | |||||
| if bpy.data.filepath: | |||||
| import_path = bpy.path.relpath(self.directory) | |||||
| else: | |||||
| self.report({'WARNING'}, 'Relative paths cannot be used with unsaved scenes!') | |||||
| print('Relative paths cannot be used with unsaved scenes!') | |||||
| # Add found images | # Add found images | ||||
| print('\nMatched Textures:') | print('\nMatched Textures:') | ||||
| texture_nodes = [] | texture_nodes = [] | ||||
| Context not available. | |||||
| # DISPLACEMENT NODES | # DISPLACEMENT NODES | ||||
| if sname[0] == 'Displacement': | if sname[0] == 'Displacement': | ||||
| disp_texture = nodes.new(type='ShaderNodeTexImage') | disp_texture = nodes.new(type='ShaderNodeTexImage') | ||||
| img = bpy.data.images.load(self.directory+sname[2]) | img = bpy.data.images.load(path.join(import_path, sname[2])) | ||||
| disp_texture.image = img | disp_texture.image = img | ||||
| disp_texture.label = 'Displacement' | disp_texture.label = 'Displacement' | ||||
| if disp_texture.image: | if disp_texture.image: | ||||
| Context not available. | |||||
| if not active_node.inputs[sname[0]].is_linked: | if not active_node.inputs[sname[0]].is_linked: | ||||
| # No texture node connected -> add texture node with new image | # No texture node connected -> add texture node with new image | ||||
| texture_node = nodes.new(type='ShaderNodeTexImage') | texture_node = nodes.new(type='ShaderNodeTexImage') | ||||
| img = bpy.data.images.load(self.directory+sname[2]) | img = bpy.data.images.load(path.join(import_path, sname[2])) | ||||
| texture_node.image = img | texture_node.image = img | ||||
| # NORMAL NODES | # NORMAL NODES | ||||
| Context not available. | |||||