path name and file name ?

got an old script but not working anymore!

got this for the file path name




 def execute(self, context):
 
               # set the string path for the file here.
               # this is a variable created from the top to start it
  bpy.context.scene.custompath = self.properties.path
  print(self.properties.path)      # display the file name and current path
 
 # Call function to check file type and read file's datas
 
  print ()
  print ('File s name =', self.properties.path   )
  print ('bpy.context.scene.custompath =', bpy.context.scene.custompath   )
 


after I select a file in current folder
it does not have the file’s name anymore

so how can this be corrected ?

also is there a way to separate the path - filename and the extension for the selected file ?

I need to check that the file extention is the right one !

thanks
happy bl

I’m not sure which filepath you need… If it’s the blend file path you can use this command:
http://www.blender.org/documentation/blender_python_api_2_72b_release/bpy.types.BlendData.html?highlight=filepath#bpy.types.BlendData.filepath

To split path+filename and extension, the easiest way I know of is to import the os module and use splitext:
https://docs.python.org/3.4/library/os.path.html#os.path.splitext

Happy bl =)

i’m opening a txt file in the same folder then the blend file
so not a problem to open it as such!

but the path var does not show the path name with filename !

mid this was working 2 years ago but there might be some changes done meanwhile!

thanks

You can check out this example:
http://www.blender.org/documentation/blender_python_api_2_66_4/bpy.types.Operator.html#calling-a-file-selector
It’s pretty clearly commented and you get access to your filepath+name+extension via the filepath variable :wink:

I file selector seems to work
but cannot write to txt file !
would be nice to see it work!

but if I transfer the oath command to my file
I cannot print the file path I get this

###########################################
here filepath1 = (<built-in function StringProperty>, {‘subtype’: 'FILE_PATH
'})
here name filepath1 =

&&&&&

got empty = nothing !

what is going on here ?
where is the name and path ?

thanks

I basically have same operator but mine is not working
not certain why !

try it



 
########  
   
class OBJECT_OT_CustomPath(bpy.types.Operator):
 
 global p
 bl_idname = "object.custom_path"
 bl_label = "Custom Path"
 __doc__ = "OBJECT_OT_CustomPath"
 
 #this can be look into the one of the export or import python file.
 #settings
 #need to set a path so so we can get the file name and path
 
# path = p1.StringProperty(name="file path", description="getting file path", maxlen= 1024, default= "")
 
 filepath1 = bpy.props.StringProperty(subtype="FILE_PATH")
 
 print(' before  here filepath1  = ',filepath1)
 
 
 
 def execute(self, context):
               # set the string path for the file here.
               # this is a variable created from the top to start it
 
#  print('      here filepath1  = ',filepath1)      # error 
 
  print('  here name filepath1  = ',self.properties.filepath1)      # display the file name and current path
 
  bpy.context.scene.custompath = self.properties.filepath1
 
  print ( ' ok    path =', self.filepath1 )
  print ()
 
  return {'FINISHED'}
 
 
 
 
# def invoke(self, context, event):
#  wm = bpy.context.window_manager  
#  bpy.context.window_manager.fileselect_add(self)
 
 
 def invoke(self, context, event):
 
  bpy.context.window_manager.fileselect_add(self)
  return {'RUNNING_MODAL'}
 
 
 
 
#  return {'RUNNING_MODAL'}
 
 
#####
 


thanks

filepath1 = (<built-in function StringProperty>, {‘subtype’: ‘FILE_PATH’})

it indicates that you try to register a property on a unsupported type.

I use same prop from the working "file selector " example from wiki
the 2 class operator are identical except for names!

I did change the names but that should not make any difference

so what else is not working ?

only difference is that I’m calling it from a panel class
but that should work like it was a few months ago!

I can upload whole script with panel class if needed
let me know

thanks

Ah, the dreaded panel class limitations. They keep rearing their ugly heads (ugh). Try the same code in the object context and it might work.

I’ve read through the API, and it seems that you can’t change the filepath name to filepath1 as Blender specifically uses “filepath” to store the path.
See: http://www.blender.org/documentation/blender_python_api_2_66_4/bpy.types.WindowManager.html#bpy.types.WindowManager.fileselect_add

After a bit of testing and documenting I’ve managed to fully understand how the file selector works and I’ve broken it down for you in a simple example using your code as basis. Let me just explain a few facts first.
The file selector can return 4 properties:

  • filepath: full path of selected item (path+filename)
  • filename: name of selected item
  • directory: directory of the selected item
  • files: a collection containing all the selected items’ filenames (if you selected multiple files in the file selector)
    So basically filepath = directory+filename.
    If you selected multiple files, you can get the nth file’s path through: directory+files[n].name

The first 3 properties are of StringProperty type. It is recommended to set the subtype to ‘FILE_PATH’ as well as options to ‘HIDDEN’ and ‘SKIP_SAVE’ so that the properties cannot be manipulated (via drivers, IPOs…) or saved in presets, and to prevent further access.
The last is a CollectionProperty of a special type (OperatorFileListElement) which is not listed in the bpy.props elements but in bpy.types. It is also recommended to use the ‘HIDDEN’ and ‘SKIP_SAVE’ options for this property.

Here’s my test code:

import bpy


class OBJECT_OT_CustomPath(bpy.types.Operator):
    bl_idname = "object.custom_path"
    bl_label = "Custom Path"
    
    # Props
    filepath = bpy.props.StringProperty(subtype='FILE_PATH', options={'HIDDEN', 'SKIP_SAVE'})
    filename = bpy.props.StringProperty(subtype='FILE_PATH', options={'HIDDEN', 'SKIP_SAVE'})
    directory = bpy.props.StringProperty(subtype='FILE_PATH', options={'HIDDEN', 'SKIP_SAVE'})
    files = bpy.props.CollectionProperty(type=bpy.types.OperatorFileListElement, options={'HIDDEN', 'SKIP_SAVE'})
    
    def execute(self, context):
        print()
        
        # print props
        print("filepath:", self.filepath)
        print("filename:", self.filename)
        print("directory:", self.directory)
        for f in enumerate(self.files):
            print("file {0}:".format(f[0]), f[1].name)
        
        # save filepath to custom scene prop
        context.scene.custompath = self.filepath
        print("scene custom path property:", context.scene.custompath)
        return {'FINISHED'}

    def invoke(self, context, event):
        bpy.context.window_manager.fileselect_add(self)
        return {'RUNNING_MODAL'}


if __name__=="__main__":
    bpy.types.Scene.custompath = bpy.props.StringProperty(subtype="FILE_PATH")
    bpy.utils.register_module(__name__)

One last somehow unrelated thing: in your code you used self.properties.filepath1, I’ve never used the “properties” term and it’s always worked fine. I don’t really know if it’s necessary to use it…

Hopefully I made myself clear in explaining all this, sorry for the long post :wink:

nice description you should add this to the wiki !

I change the prop name to filepath and now it works!
very strange indeed

what would this filepath var is ?
a system var or property reserve API keyword ?

i will continue to experiment with other parameters and see if it can works nicely

thanks

the modal c operator tried to set certain properties with hardcoded names, that’s all.

a bit confusing in this case
I mean left var of equation is supposed to be independent !
but anyway I take note in my file for this special case

I guess here it is same thing for the filename or path !
cannot change name too

thanks

anyone know anything about the old file std IGES for CAD

I got the math model for some of the entities

spline line
arc circle
line
vert

but don’t have the other ones

thanks