01-31-2024, 09:08 AM
The culprit code is like this:
The message you have is clear: variable newlayer2 doesn't exist, and in Python this means it has never been assigned.
Since it seems to have been assigned in the few lines above, WTF?
Notice that the lines above are bracketed by a try/except, so if anything bad happens in the first three lines, instead of stopping with an exception, the Python code jumps to the code after the except. So, something bad happened in the three lines, but where?
But even then... this code has a major flaw: it replaces the exception raised by the copy or load steps (that could have explanatory messages), by an anonymous exception (that doesn't tell you anything). So it is pointless... you can just as well remove it, this won't prevent errors but at least you will have a better idea of where and what they are.
(although why you need to copy the file to a new file to load it is beyond me)
Also do yourself a favor and replace line #81 by
And there are still a few weird bits left
Code:
# put it as a new layer in the opened image
try:
darktablefile = os.path.join(tempfile.gettempdir(), "ShellOutDTTempFile.tif")
copyfile( darktablefile, tempfilename )
newlayer2 = pdb.gimp_file_load_layer(tempimage, tempfilename)
except:
RuntimeError
tempimage.add_layer(newlayer2,-1)
The message you have is clear: variable newlayer2 doesn't exist, and in Python this means it has never been assigned.
Since it seems to have been assigned in the few lines above, WTF?
Notice that the lines above are bracketed by a try/except, so if anything bad happens in the first three lines, instead of stopping with an exception, the Python code jumps to the code after the except. So, something bad happened in the three lines, but where?
- first line not too likely (join() is mostly about splicing string, it doesn't check if the name is valid)
- copyfile is a candidate if the path created in the previous line is bad, or there are other systems problems (no enough space, write permissions)
- pdb.gimp_file_load_layer is another candidate if the tempimage doesn't exist or if the file cannot be loaded for some reason (not an image file...)
But even then... this code has a major flaw: it replaces the exception raised by the copy or load steps (that could have explanatory messages), by an anonymous exception (that doesn't tell you anything). So it is pointless... you can just as well remove it, this won't prevent errors but at least you will have a better idea of where and what they are.
Code:
# put it as a new layer in the opened image
darktablefile = os.path.join(tempfile.gettempdir(), "ShellOutDTTempFile.tif")
copyfile( darktablefile, tempfilename )
newlayer2 = pdb.gimp_file_load_layer(tempimage, tempfilename)
tempimage.add_layer(newlayer2,-1)
(although why you need to copy the file to a new file to load it is beyond me)
Also do yourself a favor and replace line #81 by
Code:
raise RuntimeError('Cannot create temporary image')
And there are still a few weird bits left