Forum: Poser Python Scripting


Subject: How do you avoid UAC problems writing to poser.AppLocation() subfolders ?

3dcheapskate opened this issue on Apr 23, 2020 ยท 38 posts


3dcheapskate posted Fri, 24 April 2020 at 9:35 AM

Might as well post the relevant bits of the script as it stands,so you can see what I was doing.

For the Smart+ script this is how I find the datafile:

    ...
    # Locate the smart plus datafile
    sDatafile = os.path.join('Runtime','Python','poserScripts','3DCheapskate','SmartPlus','SmartPlusData.txt')
    smartdatafile = locateDataFile(sDatafile
    ...

...and this is the locateDataFile() function, which checks the Poser applocation first, and then each mapped runtime in turn

    
# sFilename is the path in OS-specific format starting at Runtime
def locateDataFile(sFilename):
    locatedfile = ""
    filetocheck = ""
    global sTempErrLog
    # Check for the data file in the application location (Poser 6 PoserPython doesn't provide a method to scan mapped runtimes)
    poserpath=os.path.split(poser.AppLocation())
    filetocheck =  os.path.join(poserpath[0],sFilename)
    if os.path.exists(filetocheck):
        locatedfile = filetocheck
    else:
        # If it's not found then log it so we can inform user later if necessary
        sTempErrLog = sTempErrLog+"nFILE NOT FOUND: "+filetocheck
    # Check for the data file in the mapped libraries (if already found we still check for multiple copies, but use the first one we found)
    try:
        aLibs = poser.Libraries()
        for lib in aLibs:
            filetocheck =  os.path.join(lib,'Runtime','Python','poserScripts','3DCheapskate','SmartPlus','SmartPlusData.txt')
            if os.path.exists(filetocheck):
                if locatedfile == "":
                    locatedfile = filetocheck
                else:
                    poser.DialogSimple.MessageBox("Multiple 'SmartPlusData.txt' files found")
            else:
                # If it's not found then log it so we can inform user later if necessary
                sTempErrLog = sTempErrLog+"nFILE NOT FOUND: "+filetocheck
    except: # Poser 6 will always cause an exception because the Libraries() function doesn't exist
        pass
    return locatedfile

The 3Dcheapskate (also available in DAZ and HiveWire3D flavours) occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.