I've been seeing a lot more usage of code like
raise ValueError("Invalid path selected") in the Python examples. As I understand it, these errors tend to get surfaced in the Console - which is useful to developers, but less useful to Users.
Here's a simple script that asks a user to select an image in a folder containing multiple images.
import c4d def get_images_path(): image_path = c4d.storage.LoadDialog( type=c4d.FILESELECTTYPE_IMAGES, title="Select an image in the folder you want to bulk rename", flags=c4d.FILESELECT_LOAD ) if not image_path: raise ValueError("Valid image path not selected.") return image_path def main(): images_path = get_images_path() c4d.gui.MessageDialog(images_path) if __name__=='__main__': main()
How should I gracefuly accept a user hitting "Cancel"? How should I provide the user with a helpful error if they've selected the wrong filetype (let's for example pretend I'm looking for
.png files rather than misc image formats)?
Should we use popup messages? Status bar updates? Console prints?
Do I need to do something like:
try: images_path = get_images_path() except ValueError as error: c4d.gui.MessageDialog(error)
...every time I call any method that might throw an error? Or is there a way to auto-promote exceptions/errors as alert dialogs/status updates?