Write PNMImage with full path

I’m having a bit of a problem.

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: 
from panda3d.core import *

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

if I skip the “path” part


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?

I’ve yet to find the file saved from a .p3d file :mrgreen:
The text file is where it should be.
writing just:


pops the file into \Documents and Settings…\Local Settings\Application Data\Panda3D\start\



writes test5.png into the folder where the .p3d file was lunched (on windows )



…did nothing (no file saved)

finally this worked:


printing the Filename gives a perfectly fine panda3d filename string i.e: “/c/test_file/maps/map” or"/c/test_file/maps/map/test.png"

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. :slight_smile: