Skip to main content
Tweeted twitter.com/StackBlender/status/682399725342081024
image, markup
Source Link
p2or
  • 16.1k
  • 10
  • 87
  • 146

enter image description here

*Update*

I now have the file browser, and I've found out how to load the texture into the node but not from the file browser. I have to type the file path in manually, and I had to put it in a different class that was activated with a bool...soo so, how can I make the file browser activate it instead?how can I activate the file browser instead?

Code:enter image description here

code

import bpy
import os
from bpy.types import (Menu, PropertyGroup)
from bpy.props import (BoolProperty, FloatProperty, EnumProperty, StringProperty)
from bpy_extras.io_utils import ImportHelper

def update_texture(self, context):
    path = self.screen_texture.value
    img = bpy.data.images.load(filepath = path)

    nt = bpy.data.materials['Screen'].node_tree
    n = nt.nodes["screen_texture"].image = img
    
class IgnitProperties(bpy.types.PropertyGroup):
    
    screen_path = StringProperty(
       name="Browse Image:",
       description="Loads the texture for the screen",
       maxlen= 1024,
       subtype='FILE_PATH',
       update=update_texture
   )
   
class IdentifierFileSelector(bpy.types.Operator, ImportHelper):
    bl_label = "File Browser"
    bl_idname = "macbook_controller.identifier_file_selector"

    def execute(self, context):
        fdir = self.properties.filepath
        
        # Screen Texture
        

        return{'FINISHED'}

class IGLayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "MacBook Controller"
    bl_idname = "macbook_controller.macbook_controller"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        
        # Screen Texture
        layout.label(text = "Screen Texture:")
        layout.prop(scene.ignit_panel, "screen_path", text="")

enter image description here

*Update*

I now have the file browser, and I've found out how to load the texture into the node but not from the file browser. I have to type the file path in manually, and I had to put it in a different class that was activated with a bool...soo, how can I make the file browser activate it instead?

Code:

import bpy
import os
from bpy.types import (Menu, PropertyGroup)
from bpy.props import (BoolProperty, FloatProperty, EnumProperty, StringProperty)
from bpy_extras.io_utils import ImportHelper

def update_texture(self, context):
    path = self.screen_texture.value
    img = bpy.data.images.load(filepath = path)

    nt = bpy.data.materials['Screen'].node_tree
    n = nt.nodes["screen_texture"].image = img
    
class IgnitProperties(bpy.types.PropertyGroup):
    
    screen_path = StringProperty(
       name="Browse Image:",
       description="Loads the texture for the screen",
       maxlen= 1024,
       subtype='FILE_PATH',
       update=update_texture
   )
   
class IdentifierFileSelector(bpy.types.Operator, ImportHelper):
    bl_label = "File Browser"
    bl_idname = "macbook_controller.identifier_file_selector"

    def execute(self, context):
        fdir = self.properties.filepath
        
        # Screen Texture
        

        return{'FINISHED'}

class IGLayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "MacBook Controller"
    bl_idname = "macbook_controller.macbook_controller"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        
        # Screen Texture
        layout.label(text = "Screen Texture:")
        layout.prop(scene.ignit_panel, "screen_path", text="")

I now have the file browser, and I've found out how to load the texture into the node but not from the file browser. I have to type the file path in manually, and I had to put it in a different class that was activated with a bool... so, how can I activate the file browser instead?

enter image description here

code

import bpy
import os
from bpy.types import (Menu, PropertyGroup)
from bpy.props import (BoolProperty, FloatProperty, EnumProperty, StringProperty)
from bpy_extras.io_utils import ImportHelper

def update_texture(self, context):
    path = self.screen_texture.value
    img = bpy.data.images.load(filepath = path)

    nt = bpy.data.materials['Screen'].node_tree
    n = nt.nodes["screen_texture"].image = img
    
class IgnitProperties(bpy.types.PropertyGroup):
    
    screen_path = StringProperty(
       name="Browse Image:",
       description="Loads the texture for the screen",
       maxlen= 1024,
       subtype='FILE_PATH',
       update=update_texture
   )
   
class IdentifierFileSelector(bpy.types.Operator, ImportHelper):
    bl_label = "File Browser"
    bl_idname = "macbook_controller.identifier_file_selector"

    def execute(self, context):
        fdir = self.properties.filepath
        
        # Screen Texture
        

        return{'FINISHED'}

class IGLayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "MacBook Controller"
    bl_idname = "macbook_controller.macbook_controller"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        
        # Screen Texture
        layout.label(text = "Screen Texture:")
        layout.prop(scene.ignit_panel, "screen_path", text="")
edited title
Source Link
zeffii
  • 39.9k
  • 9
  • 106
  • 189

How to make a file browser and change a texture in a node using pythonuse the File Browser's (with ImportHelper) execute function?

I have a basic panel and I want to be able to browse for a texture and load it into a image texture node. I found the example script for this in the templates but its a little bit over my head. I think I can load it into the node myself but I need some assistance on putting the file browser into a panel.

Something a little bit like this:

enter image description here

*Update*

I now have the file browser, and I've found out how to load the texture into the node but not from the file browser. I have to type the file path in manually, and I had to put it in a different class that was activated with a bool...soo, how can I make the file browser activate it instead?

Code:

import bpy
import os
from bpy.types import (Menu, PropertyGroup)
from bpy.props import (BoolProperty, FloatProperty, EnumProperty, StringProperty)
from bpy_extras.io_utils import ImportHelper

def update_texture(self, context):
    path = self.screen_texture.value
    img = bpy.data.images.load(filepath = path)

    nt = bpy.data.materials['Screen'].node_tree
    n = nt.nodes["screen_texture"].image = img
    
class IgnitProperties(bpy.types.PropertyGroup):
    
    screen_path = StringProperty(
       name="Browse Image:",
       description="Loads the texture for the screen",
       maxlen= 1024,
       subtype='FILE_PATH',
       update=update_texture
   )
   
class IdentifierFileSelector(bpy.types.Operator, ImportHelper):
    bl_label = "File Browser"
    bl_idname = "macbook_controller.identifier_file_selector"

    def execute(self, context):
        fdir = self.properties.filepath
        
        # Screen Texture
        

        return{'FINISHED'}

class IGLayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "MacBook Controller"
    bl_idname = "macbook_controller.macbook_controller"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        
        # Screen Texture
        layout.label(text = "Screen Texture:")
        layout.prop(scene.ignit_panel, "screen_path", text="")

How to make a file browser and change a texture in a node using python?

I have a basic panel and I want to be able to browse for a texture and load it into a image texture node. I found the example script for this in the templates but its a little bit over my head. I think I can load it into the node myself but I need some assistance on putting the file browser into a panel.

Something a little bit like this:

enter image description here

*Update*

I now have the file browser, and I've found out how to load the texture into the node but not from the file browser. I have to type the file path in manually, and I had to put it in a different class that was activated with a bool...soo, how can I make the file browser activate it instead?

Code:

import bpy
import os
from bpy.types import (Menu, PropertyGroup)
from bpy.props import (BoolProperty, FloatProperty, EnumProperty, StringProperty)
from bpy_extras.io_utils import ImportHelper

def update_texture(self, context):
    path = self.screen_texture.value
    img = bpy.data.images.load(filepath = path)

    nt = bpy.data.materials['Screen'].node_tree
    n = nt.nodes["screen_texture"].image = img
    
class IgnitProperties(bpy.types.PropertyGroup):
    
    screen_path = StringProperty(
       name="Browse Image:",
       description="Loads the texture for the screen",
       maxlen= 1024,
       subtype='FILE_PATH',
       update=update_texture
   )
   
class IdentifierFileSelector(bpy.types.Operator, ImportHelper):
    bl_label = "File Browser"
    bl_idname = "macbook_controller.identifier_file_selector"

    def execute(self, context):
        fdir = self.properties.filepath
        
        # Screen Texture
        

        return{'FINISHED'}

class IGLayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "MacBook Controller"
    bl_idname = "macbook_controller.macbook_controller"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        
        # Screen Texture
        layout.label(text = "Screen Texture:")
        layout.prop(scene.ignit_panel, "screen_path", text="")

How to use the File Browser's (with ImportHelper) execute function?

enter image description here

*Update*

I now have the file browser, and I've found out how to load the texture into the node but not from the file browser. I have to type the file path in manually, and I had to put it in a different class that was activated with a bool...soo, how can I make the file browser activate it instead?

Code:

import bpy
import os
from bpy.types import (Menu, PropertyGroup)
from bpy.props import (BoolProperty, FloatProperty, EnumProperty, StringProperty)
from bpy_extras.io_utils import ImportHelper

def update_texture(self, context):
    path = self.screen_texture.value
    img = bpy.data.images.load(filepath = path)

    nt = bpy.data.materials['Screen'].node_tree
    n = nt.nodes["screen_texture"].image = img
    
class IgnitProperties(bpy.types.PropertyGroup):
    
    screen_path = StringProperty(
       name="Browse Image:",
       description="Loads the texture for the screen",
       maxlen= 1024,
       subtype='FILE_PATH',
       update=update_texture
   )
   
class IdentifierFileSelector(bpy.types.Operator, ImportHelper):
    bl_label = "File Browser"
    bl_idname = "macbook_controller.identifier_file_selector"

    def execute(self, context):
        fdir = self.properties.filepath
        
        # Screen Texture
        

        return{'FINISHED'}

class IGLayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "MacBook Controller"
    bl_idname = "macbook_controller.macbook_controller"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        
        # Screen Texture
        layout.label(text = "Screen Texture:")
        layout.prop(scene.ignit_panel, "screen_path", text="")
Added code
Source Link
mr-matt
  • 1.2k
  • 1
  • 11
  • 27

I have a basic panel and I want to be able to browse for a texture and load it into a image texture node. I found the example script for this in the templates but its a little bit over my head. I think I can load it into the node myself but I need some assistance on putting the file browser into a panel.

Something a little bit like this:

enter image description here

*Update*

I now have the file browser, and I've found out how to load the texture into the node but not from the file browser. I have to type the file path in manually, and I had to put it in a different class that was activated with a bool...soo, how can I make the file browser activate it instead?

Code:

import bpy
import os
from bpy.types import (Menu, PropertyGroup)
from bpy.props import (BoolProperty, FloatProperty, EnumProperty, StringProperty)
from bpy_extras.io_utils import ImportHelper

def update_texture(self, context):
    path = self.screen_texture.value
    img = bpy.data.images.load(filepath = path)

    nt = bpy.data.materials['Screen'].node_tree
    n = nt.nodes["screen_texture"].image = img
    
class IgnitProperties(bpy.types.PropertyGroup):
    
    screen_path = StringProperty(
       name="Browse Image:",
       description="Loads the texture for the screen",
       maxlen= 1024,
       subtype='FILE_PATH',
       update=update_texture
   )
   
class IdentifierFileSelector(bpy.types.Operator, ImportHelper):
    bl_label = "File Browser"
    bl_idname = "macbook_controller.identifier_file_selector"

    def execute(self, context):
        fdir = self.properties.filepath
        
        # Screen Texture
        

        return{'FINISHED'}

class IGLayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "MacBook Controller"
    bl_idname = "macbook_controller.macbook_controller"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        
        # Screen Texture
        layout.label(text = "Screen Texture:")
        layout.prop(scene.ignit_panel, "screen_path", text="")

I have a basic panel and I want to be able to browse for a texture and load it into a image texture node. I found the example script for this in the templates but its a little bit over my head. I think I can load it into the node myself but I need some assistance on putting the file browser into a panel.

Something a little bit like this:

enter image description here

*Update*

I now have the file browser, and I've found out how to load the texture into the node but not from the file browser. I have to type the file path in manually, and I had to put it in a different class that was activated with a bool...soo, how can I make the file browser activate it instead?

I have a basic panel and I want to be able to browse for a texture and load it into a image texture node. I found the example script for this in the templates but its a little bit over my head. I think I can load it into the node myself but I need some assistance on putting the file browser into a panel.

Something a little bit like this:

enter image description here

*Update*

I now have the file browser, and I've found out how to load the texture into the node but not from the file browser. I have to type the file path in manually, and I had to put it in a different class that was activated with a bool...soo, how can I make the file browser activate it instead?

Code:

import bpy
import os
from bpy.types import (Menu, PropertyGroup)
from bpy.props import (BoolProperty, FloatProperty, EnumProperty, StringProperty)
from bpy_extras.io_utils import ImportHelper

def update_texture(self, context):
    path = self.screen_texture.value
    img = bpy.data.images.load(filepath = path)

    nt = bpy.data.materials['Screen'].node_tree
    n = nt.nodes["screen_texture"].image = img
    
class IgnitProperties(bpy.types.PropertyGroup):
    
    screen_path = StringProperty(
       name="Browse Image:",
       description="Loads the texture for the screen",
       maxlen= 1024,
       subtype='FILE_PATH',
       update=update_texture
   )
   
class IdentifierFileSelector(bpy.types.Operator, ImportHelper):
    bl_label = "File Browser"
    bl_idname = "macbook_controller.identifier_file_selector"

    def execute(self, context):
        fdir = self.properties.filepath
        
        # Screen Texture
        

        return{'FINISHED'}

class IGLayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "MacBook Controller"
    bl_idname = "macbook_controller.macbook_controller"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        
        # Screen Texture
        layout.label(text = "Screen Texture:")
        layout.prop(scene.ignit_panel, "screen_path", text="")
*Update*
Source Link
mr-matt
  • 1.2k
  • 1
  • 11
  • 27
Loading
Source Link
mr-matt
  • 1.2k
  • 1
  • 11
  • 27
Loading