I want to write a image to the disc at a specific directory and I want it to work just the same after packing it to a .p3d file.
import os
from panda3d.core import Filename
from direct.showbase.AppRunnerGlobal import appRunner
if appRunner:
path=Filename.fromOsSpecific(appRunner.p3dFilename.getDirname())
else:
path=Filename.fromOsSpecific(os.getcwd())
from panda3d.core import *
saveName="/maps/map/"
p=PNMImage(512, 512)
p.write(Filename(path+saveName+"test.png").toOsSpecific()) #no output
file(Filename(path+saveName+"test.txt").toOsSpecific(), 'w') #txt file made
a image is saved… but it will be saved in the wrong place after packing it to a .p3d file.
In other words:
I have a valid path e.g: path=Filename("/c/MyGame/maps/map/")
I have a valid image e.g: image=PNMImage(512, 512)
Why can’t I save my image at my path?
What am I doing wrong this time? …or is this a bug?
I imagine that the problem is likely a matter of what directory the program considers to be its “working” or “current” directory, and that all saves are being made relative to that – perhaps the “fromOsSpecific” call is ending up with something like “//”.
Have you tried, both with and without the “path” element, putting your Filename objects – those used in the actual saving operation – in to a temporary variable and printing out the result of “getFullPath”, something like this:
fName = Filename(path+saveName+"test.png") # or Filename(saveName+"test.png") -- sans "path"
osSpecificName = fName.toOsSpecific()
print fName
print osSpecificName
p.write(osSpecificName) #no output
Where is the image ending up when you save from a P3D?
Ah wait, I think that I see: the problem was that you had “toOsSpecific” in a file-writing call offered by Panda3D, which was presumably expecting Panda3D’s directory format – forward-slashes between directories – and not the format used by Windows – back-slashes between directories.
Well, one way or another, you seem to have fixed the problem, I’m glad to see.