Custom Function in Pan X

Thank you, Gary! I did not know the commonpath( function before.

Reading the documentation, I see that the code even can be simpler:

makefolder commonpath("appsupport")+{/PanoramaX/Libraries}
saveas commonpath("appsupport")+{/PanoramaX/Libraries/TestCustomFunctions}

I think the documentation of the makefolder statement should clarify what Gary explained:

The makefolder statement creates a folder (and – if necessary – surrounding folders to complete the given path) if it is not already there. So there is no risk to accidentally delete older contents of an already existing folder.

Here is a custom statement using Bruce’s and my code from above that will add the current database containing custom functions or statements to the Libraries folder of the PanoramaX Application Support folder. I have named the statement CustomLibrarySave (the procedure name actually must be all caps as “CUSTOMLIBRARYSAVE”).

/*
<PROCEDUREINFO>
<description>saves the current file containing a custom library to the 
    Application Support Libraries folder.</description>
<breadcrumb>Panorama>Procedures>Files</breadcrumb>
<tags>files</tags>
<parameter NAME=DATABASE TYPE=TEXT>New name to save file as or use "" 
    to save under current database name.</parameter>
<body>This statement will save the current database to the use's
    Library/Application Support/PanoramaX/Libraries
    folder where the custom functions and statements contained in the file 
    will be automatically loaded when Panorama starts.

This example copies the current database under the new name of 
    "MyCustomTools" to the Library/Application Support/PanoramaX/Libraries 
    folder and creates the necessary folder and subfolders if they do not 
    already exist.

    customlibrarysave "MyCustomTools</body>

<seealso>@files</seealso>
<history>>New in this version.</revision></history>
</PROCEDUREINFO>
*/

local filename
filename=parameter(1)

If filename=""
    filename=info("databasename")
Endif
makefolder commonpath("appsupport")+{/PanoramaX/Libraries}
saveas commonpath("appsupport")+{/PanoramaX/Libraries/}+filename

Hello Gary and KJM,

Sorry to be so dense.

The code you show in the above note is said to be a “custom” statement. But to run a custom statement, don’t you already need the PanoramaX:etc folders? So why have the custom statement make those folders with the makefolder command?

Where do you place the code you provided?

Regards,
Vic

You could put another procedure in the database where you put that code. It would have just one line.

call "CUSTOMLIBRARYSAVE", ""

Run that procedure, and that file becomes your first custom statement library. You could have your .InitializeFunctions procedure in that same database.

Hi Vic, sorry to have been so vague regarding the custom statement I posted. You can open a new database and enter the above custom statement code in a new procedure named CUSTOMLIBRARYSAVE. Next create another procedure that you can leave named Procedure_A and enter this code:

makefolder commonpath("appsupport")+{/PanoramaX/Libraries}
saveas commonpath("appsupport")+{/PanoramaX/Libraries/}+"_VicsCustomLib"

Note that the name of the file should be started with an underline character and end in Lib to match the normal Panorama library files. This name will only be used for the title of the saved library file and not change the original database name. You can of course use whatever name you prefer. If you now run these two lines of code you will create all the PanoramaX subfolders in the Library/Applications Support folder and create the library file itself in the Libraries folder with the name “VicsCustomLib”. Next time you start Panorama X you will have the CustomLibrarySave statement available. You should also be able to load and register the new statement without quitting Panorama by running this line of code:

loadlibrary commonpath("appsupport")+{/PanoramaX/Libraries},"VicsCustomLib"

I hope this makes things a little clearer and I apologize for my brief previous explanation.

I just learned something new. Looking at the menus for the View Organizer, I found this.

I wasn’t aware that I had a file named “Thompson, David’s Custom Statements”, but I chose it anyway and this opened.

Looking inside ~/Library/Application Support I found a PanoramaX folder that had been created that very minute. Inside that was a Libraries folder that was also brand new. Inside that was “Thompson, David’s Custom Statements.pandb” that had just been modified, but had been created January 3, 2017.

It looks like Panorama X already has a quick and easy way to create a custom statement library, and put it in the appropriate folder.

Dave/Gary,

You guys are fantastic!

Dave, I did what you did with the View Organizer, and I found the same thing. Of course, my name was where yours was. And my invisible Application Support folder had all the necessary sub-folders and files automatically created.

So Pan X had this all figured out already. I wonder if Jim knows how clever his creation is. Else why didn’t he just respond as you did?

Thanks to all. I think I’m now on firm ground and can manage the rest.

Best regards,
Vic

For the first time (I think), I’m ahead of you Dave - Yea! I included this feature in a draft Help wizard entry that I sent to Jim several months back.