[Bf-python] Extending Blender's Python API: expandpath(), GetAbsolutePath(), Get('scenefile'), Get('scenefiledir'), image.filenameAbsolute
Dietrich Bollmann
diresu at web.de
Tue Jul 17 06:25:10 CEST 2007
Hi,
I needed some functionality to get the absolute path of a texture
image - and as I couldn't find anything and nobody responded to my
posting ( http://www.blender.org/forum/viewtopic.php?p=62764#62764 )
I finally implemented my own method:
Blender.GetAbsolutePath()
Example:
the scene file is '/home/dietrich/blender/scene/cube.blend'
>>> Blender.GetAbsolutePath('//../foo/bar')
'/home/dietrich/blender/foo/bar'
Today by chance I found the function `Blender.sys.expandpath()'
which more or less does what I want - but not as nice as my
function, as the returned path is not brought into the
canonical form (/.//foo/../bar/./ --> /bar/):
>>>
Blender.sys.expandpath('//../.././/.///.././/../././foo//././/.////one/./two/../three/../../bar')
'/home/dietrich/blender/yafray/textures/tiles/exp/../.././/.///.././/../././foo//././/.////one/./two/../three/../../bar'
>>>
Blender.GetAbsolutePath('//../.././/.///.././/../././foo//././/.////one/./two/../three/../../bar')
'/home/dietrich/blender/foo/bar'
I thought to create a patch with my new function but now don't know
how to proceed...
Different ideas are:
- leave my new function as it is (`Blender.GetAbsolutePath()')
probably not a good idea as there would be two similar functions
at different places
- rename my function to `Blender.sys.expandpathSimplify()'
- put my function into `expandpath()'
- give the function `expandpath()' a second facultative argument
which might be 'raw' or 'simplify' with one of the two the default
- make a third function `simplify()' which could be used to simplify
whatever path there is
- other ideas?
What do you think would be best?
* second question
I implemented two new setting keys usable with Blender.Get() as I
couldn't find anything similar in the documentation:
- Blender.Get('scenefile')
- Blender.Get('scenefiledir')
The first returnes the path of the scenefile, the second its
directory:
>>> Blender.Get('scenefile')
'/home/dietrich/blender/scene/cube.blend'
>>> Blender.Get('scenefiledir')
'/home/dietrich/blender/scene/'
I this usable for others also and should I make it a patch?
* third question
My first solution to my problem - obtaining the absolute path of an
image - was to implement `image.filenameAbsolute':
Example:
with the scene file: '/home/dietrich/blender/scene/cube.blend'
and the image: '//../tex/stone.png'
>>> image.filenameAbsolute
'/home/dietrich/blender/tex/stone.png'
which would result in the same as:
>>> Blender.GetAbsolutePath(image.filename)
'/home/dietrich/blender/tex/stone.png'
Is this worth a path? Or should people just use something like the
second form?
* a last question
When loading a new image into a texture with:
>>> image.filenameAbsolute = '/home/dietrich/blender/tex/stone.png'
>>> image.reload()
and redrawing the windows with
>>> Blender.Redraw()
or
>>> Blender.Window.RedrawAll()
The image preview window still shows the old image. Only hitting the
[Reload] button on the GUI or reselecting the images in the outliner
etc. redraws the preview window.
Is this a bug? Is there some other redraw function?
Sorry for too many subjects in one mail and thanks for your help :)
Dietrich
More information about the Bf-python
mailing list