0

Trying to let user select the path to the folder they have. I will need that path to attach custom texture images to the object. But all I can get now is D:\Full\Path\To\Folder\With\Blend_file\..\..\My_selected_folder\.

I read many posts here and found some examples that says to use DIR_PATH or FILE_PATH (Like here: How can I get the full path of the selected file from the file explorer?). But then how do they use this abspath with \..\..\?

import bpy
import os
from bpy.types import Scene
from bpy.props import (BoolProperty,FloatProperty)

class RECOLORSETTINGS(bpy.types.PropertyGroup): root_folder: bpy.props.StringProperty(name="Root Folder", description="Select Recolor textures folder", default="", maxlen=1024, subtype="DIR_PATH")

Button

class TEX_BUTTON_COLOR(bpy.types.Operator): bl_label = "TEX_BUTTON_COLOR" bl_idname = "object.tex_button_color" bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
    scene = context.scene
    path = scene.recolor_path

    #print ("REL:", path.root_folder)
    print ("ABS:", bpy.path.abspath(path.root_folder))        

    return {'FINISHED'} 


#PANEL UI

#################################### class RECOLOR_MENU(bpy.types.Panel): bl_label = "Recolor Menu" bl_idname = "OBJECT_PT_panel" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = "Recolor"

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


    ######### Re-color ###########
    row = layout.row()
    row.prop(recolor_path, "root_folder", text="Folder")
    row = layout.row()
    row.operator("object.tex_button_color", text = "Print Path")


#CLASS REGISTER 

########################################## classes = ( RECOLORSETTINGS, TEX_BUTTON_COLOR, RECOLOR_MENU )

def register(): for c in classes: bpy.utils.register_class(c) bpy.types.Scene.recolor_path = bpy.props.PointerProperty(type=RECOLORSETTINGS)

def unregister(): for c in classes: bpy.utils.unregister_class(c) del bpy.types.Scene.recolor_settings

if name == "main": register()

ADD in: Seems like my problem is partially solved.. Just realized that when you work with the new Blend instance - the code works, but when you open existing blend file - same code still shows \..\..\.. Have any suggestion on this pls

  • ADD in: Seems like my problem is partially solved.. Just realized that when you work with the new Blend instance - the code works, but when you open existing blend file - same code still shows \..\..\.. Have any suggestion on this pls – Blender_noob Oct 06 '22 at 01:17

1 Answers1

0

Ended up found solution myself. The issue is - when you work with addon code in Blender Scripting window the path always shown as \..\..\. But when you add it to Blender as an actual addon - it start showing the correct path.

Edited on 25.11.22: the real problem was default setting in blender set to use relative path, so whenever you select the folder it will just replace abs path to rel path.. This option was always selected by default

enter image description here

So in my code i make the default selection to be abs path, so now it always appear correct.