Forum: Poser - OFFICIAL


Subject: Rendering Preset File Location

ThunderStone opened this issue on Mar 12, 2020 · 23 posts


structure posted Wed, 18 March 2020 at 9:23 AM Forum Coordinator

This version loads and saves render and sketch presets : renaming the sketch presets to pzs as it goes

# -*- coding: utf-8 -*- 
# ©copyright structure 2001 - 2020
# Firefly Preset Manager
# ================================

import os
import os.path
import poser
import wx

Engines = ["FireFly Presets", "Sketch Presets"]
options = ["Load Preset", "Save Preset", "Delete Preset"]
pref = poser.PrefsLocation()
folder = os.path.join( pref, "structure","rpm" )
file = "lastpath.pth"


def checkprefs( folder, file, lastpath = None ):
    if not os.path.exists( folder ):
        os.makedirs( folder )

    if not os.path.isfile( os.path.join( folder, file) ):
        with open( os.path.join( folder, file), "w" ) as outfile:
            outfile.write( start )

    return True

def choose( title = '' , prompt = '' , OptionList = [] , response = None ):
    dialog = wx.SingleChoiceDialog( None, prompt, title, OptionList )                   # prepare the dialog
    
    if not OptionList == []:                                                            # ensure the list is not empty

        return dialog.GetStringSelection() if dialog.ShowModal() == wx.ID_OK else None  # check the dialog response

def getlastfolder( folder, file ):
    with open( os.path.join( folder, file), "r" ) as infile:
         data = infile.read()
    return data

def managefile( types, start, op = 0 ):
    if not op == 1 and not op == 2:
        return False
    elif op == 1:
        style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
    else:
        style = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT

    dialog = wx.FileDialog(None, "Save a RenderPreset file", start , "" ,  types , style )

    return dialog.GetPath() if dialog.ShowModal() == wx.ID_OK else False

def okcancel( title = None , alertmessage = None, okonly = False ):

    if okonly:
        style = ( wx.OK|wx.ICON_INFORMATION|wx.STAY_ON_TOP )                # test if the dialog requires only an ok button
    else:
        style = ( wx.OK|wx.CANCEL|wx.ICON_INFORMATION|wx.STAY_ON_TOP )      

    ok_dialog = wx.MessageDialog(None, alertmessage, title, style)          # prepare the dialog
    
    return True if ok_dialog.ShowModal() == wx.ID_OK else False             # test dialog response

def putlastfolder( folder, file, path = None ):
    if path == None:
        path = start
    with open( os.path.join( folder, file), "w" ) as outfile:
         outfile.write( path )

def yesno( title = "" , message = "" , answer = None ):
    # get working folder
    YN_dialog = wx.MessageDialog(None, message, style=wx.YES|wx.NO )

    return True if YN_dialog.ShowModal() == wx.ID_YES else False

scene = poser.Scene()
option = choose("Preset Manager","Select an option", options )
savetype = choose("Preset Manager", "Select an Engine", Engines )

if savetype == "FireFly Presets":
    start = os.path.join( pref, "RenderPresets" )
    types = "Render Presets (*.prp)|*.prp|" 
    scene.SetCurrentRenderEngine(poser.kRenderEngineCodeFIREFLY)
else:
    start = os.path.join( pref, "SketchPresets" )
    types = "Sketch Presets (*.pzs)|*.pzs|"
    scene.SetCurrentRenderEngine(poser.kRenderEngineCodeSKETCH)


prefsfile = checkprefs( folder, file )
lastfolder = getlastfolder( folder, file )
start = lastfolder

if option:
    if option == "Load Preset":
        preset = scene.CurrentFireFlyOptions().LoadPreset
        load = managefile( types, start, 1 )
        save = None
        if load:
            okcancel ("Render Preset Manager","%s has been Loaded" %load, True )
            preset( load )

    elif option == "Save Preset":
        preset = scene.CurrentFireFlyOptions().SavePreset
        save = managefile( types, start, 2 )
        load = None
        if save:
            okcancel ("Render Preset Manager","%s has been Saved" %save, True )
            preset( save )
            if types == "Sketch Presets (*.pzs)|*.pzs|":
                save = os.path.splitext(save)[0] + ".prp"
                newext = os.path.splitext(save)[0] + ".pzs"
                os.rename(r"" + save, r'' + newext)
            putlastfolder( folder, file, os.path.dirname(save) )

    else:
        deletefile = managefile( types, start, 1 )
        if deletefile:
            deletefileok = yesno("Render Preset Manager", "Delete %s are you sure?" %deletefile )
            if deletefileok:
                os.remove( deletefile )
                okcancel( "Render Preset Manager", "%s Deleted" %deletefile, True )
            else:
                okcancel( "Render Preset Manager", "Deletion of %s Aborted!" %deletefile, True )

Locked Out