define a path at export and store it in a variable - filemaker

I want to export some data from Filemaker. Is there a posibility to start a script with an export dialog were the user defines the export location and store this path in a variable so that the user does not have to define the location for following export scripts?
Thanks for your help!
Dan

If you're willing to use a FileMaker plugin, the free BaseElements plugin has a function called BE_SelectFolder(prompt) which opens an open/save dialog, allows the user to select a folder, and returns the location of the folder as a string. So you'd define two variables
Set Variable [$thePath; value: “BE_SelectFolder("Please choose a folder:")”]
Set Variable [$theRef; value: “"filemac:" & $thePath & "/exportfile.fmp12"”]
(that's for Mac, you'd need to adjust the second variable calc for Windows) and then use $theRef as the file reference to save the exports to.
BaseElements is available from http://www.goya.com.au/baseelements/plugin. It's got a lot of other useful functions besides, it's worth checking out.

There is no FileMaker built-in functionality to return the file path for the exported file.
If the user runs the same export twice in a row, the folder selection dialogue will open at the same location. I suspect this is not what you need.
The easiest way to work around the problem is to use AppleScript on a Mac or VBScript on PC to popup a folder select dialogue, return it back to FileMaker and store in a variable. The rest is down to your workflow.

New in FileMaker 14, from May 2015, in the "Miscellaneus script Step" you may find "Get Directory" which is the right one for your question.
His purpose is described as "Sets a variable to the fully qualified path of a specified folder."
You may also create a new folder, in case of needs, if "Allow Folder Creation" parameter is set.
Note: it is not compatible with FileMaker Go while, instead, you may use it for a RunTime distribution.

Related

FileMaker best practice regarding user data directories etc.?

I'm working on a FileMaker 18 solution. One of the things I have to solve is executing an external Python script and reading its results back. That script can run for some seconds. Since my solution should work cross-platform (I develop on MacOS, but most users will be on Windows), I settled on the Basic Elements plugin to do the script execution.
Since this is a custom script that we'll deliver together with the solution, FileMaker needs to know in which directory it is located (and also to import the resulting XML). To my surprise, BE_ExecuteSystemCommand defaults to the root directory, not to the directory the solution is installed in.
What is the best practice to get and store a data or other directory that could be user and/or system specific?
My current thought was to create a simple "globals" key/value pair table to store paths and such, and write a script that on launch checks if a value with a key of "datapath" is set, if yes, store it in a global variable other scripts can reference. If not, prompt the user with a file open dialog to select that directory. He would only have to do that once, when launching the solution the first time.
Before doing all that myself, I'm asking here if there is a best practice on how to do that, specifically, or if I'm thinking wrong and should be doing it in some other way?
I will likely be needing the data directory for a few other purposes (data import, etc.) as well.
Filemaker has native functions that return some common paths:
Get(FileMakerPath) - path to the FileMaker application running the current file;
Get(FilePath) - path to the current file;
Get(DocumentsPath) - path to the Documents folder of the current user;
Get(DesktopPath) - path to the desktop folder of the current user;
Get(PreferencesPath) - path to the preferences folder of the current user.
Get(TemporaryPath) - path to the temporary folder of the current user;
Note that the paths returned by these functions are Filemaker paths, not OS paths.

How do you copy using multi-select from Windows.Forms.OpenDialog in PowerShell using folder.copyHere() method?

Nubie question ... but you've got to start somewhere.
In my powershell console, I call Windows.Forms.OpenDialog to open a GUI file picker and browse to a location on my system and multi-select files that I want to copy. I stash that list in a variable.
Next, I use browseForFolder to choose my destination folder path and stash that in a variable
I run folder.copyHere() to copy a file using the Windows default file xfer GUI.
One file at a time works.
I want to present my multi-selected filename list to folder.copyhere and have it process the list ...
Instead, I'm stuck in my ignorance using foreach($file in $list and sending that to folder.copyhere one at a time. It's unpretty.
I tried turning my list of full-path file names into an array, and feeding folder.copyhere() the $vararray - but it wouldn't copy even the first file. One at a time yes, but that's not what I want.
If I send my list to robocopy, it processes each item in order, like a champ.
But I have GUI users and they want the GUI. Ideas on how to get folder.copyhere() to accept an array of names to process?

Calling user defined function anywhere? (matlab)

Where can i save my document "function.m", so i can call this function from any code in any path of my pc?
I already made some custom functions, but i dont know where to save those codes to be able to call them from any part.
Save them in a logical place where you can find them back. Then, use addpath to add that folder to MATLAB's search path, i.e. when you use a function it will try that folder as well to find it.
You can do this either per script, or edit startup.m with this, so that it's automatically included when MATLAB starts.
Alternatively to Adriaan's best practice answer, the fastest option is to save your function.m in the %USERPROFILE%/Documents/MATLAB directory on your PC ($home/Documents/MATLAB on Linux and Mac). This directory is on your MATLAB Search Path by default. This might be an acceptable solution if you use the function commonly across different projects.
Finally, there is a "manual" solution: Execute pathtool in MATLAB, add the directory containing your function.m via the GUI and hit save.

How can I add a custom package to the startup path in Dymola/Modelica?

I have a custom package that I find myself reusing repeatedly in Dymola models, and I'd like to put this package in a common directory that is automatically loaded whenever I start Dymola. My current strategy is to load the custom package when a model I'm working on is loaded and then save total. This is not elegant because the contents of the custom package end up saved in multiple locations across my hard drive, and if I change one of them, the changes are not reflected everywhere. I would like a more robust way of distributing this custom package to all of my models. Is there a way to tell Dymola to automatically load my custom packaged every time?
The trick is to add the following lines to settings.mos in c:/Users/USERNAME/AppData/Roaming/Dynasim:
Utilities.setenv("MODELICAPATH", "C:\Users\USERNAME\Documents\Dymola");
openModel("c:\Users\USERNAME\Documents\Dymola\UserDefined\package.mo")
The first line adds the directory to the path that Dymola uses to search for packages that have not been loaded prior to the first run of a model, and the second line loads the specified package. These two commands may be somewhat redundant, but I am doing both because I want to make sure my custom packages are on the path in addition to loading the UserDefined package.
Two suggestions. First, you need to add your package to the MODELICAPATH. You'll have to consult the Dymola documentation to figure out exactly what you need to do. But normally, what this means is that you have to set an environment variable that gives a list of directories (; separated) to be searched for your package. Now that will put it in your path so it can find it automatically, but it won't load it until it needs it.
If you want it to always appear in the package browser, you'll probably need to set up a .mos file (script) to load it. Dymola has that capability, but you'll have to read the manual to figure out what that script has to be called and where Dymola expects to find it.
I hope that helps.
In the instalation folder of Dymola 2018 -> insert -> dymola.mos
I've added the lines:
Utilities.setenv("MODELICAPATH", "C:\Users\XXXX\Documents\Dymola");
openModel("C:\Users\XXXX\Documents\Dymola\DCOL\package.mo");
openModel(“C:\Users\XXXX\Documents\Dymola\Annex60 1.0.0\package.mo”);
Now I don't get the utilities sentence, as the DCOL package loads fine without it and the added 'utilities' package in the package menu is useless.
But it does not open the Annex60 package.
I've tried a lot of different combinations and can't get multiple packages to load. I doubt that "cd" and "Advanced.ParallelizeCode", which are also added in the text work.
The accepted answer does not work since Dymola 2017 FD01, as the file settings.mos is not used anymore. User settings are stored in the setup.dymx file instead, located in
C:\Users\USERNAME\AppData\Roaming\DassaultSystemes\Dymola
In contrast to the setup.mos file you can not include custom lines with modelica script in setup.dymx.
The answer using dymola.mos still works, but you need admin privileges to modify this file.
Here is a simple solution which works with all Dyomola versions:
You can pass a .mos-script as first parameter to the dymola.exe.
This can e.g. be done like this:
Create a .mos script somewhere with commands like openModel(), etc.
Create a desktop shortcut to Dymola.exe
Open the properties of the shortcut and add the path to the .mos script in the Target text field. It will then look something like this:
"C:\Program Files\Dymola 2018 FD01\bin64\Dymola.exe" "C:\<some-path>\startup.mos"
Start Dymola with the desktop shortcut. The script will be executed and eventual errors or messages are displayed in the Commands window
Another suggestion where you don't need to hardcode your package into an environment variable of your operating system (and maybe more safe for inexperienced programmers):
Go to the folder where Dymola is installed (e.g. C:\Program Files\Dymola 2020).
Search for the Dymola.mos file in the insert-folder. 'insert' folder
Open the script (e.g., in notepad++)
Add the link(s) to your Dymola-library-package.mo file(s) here with the openModel statement
e.g., openModel("C:/IDEAS/package.mo"); Dymola.mos script
Save the script. Now, every time you open Dymola, your libraries will be loaded automatically.

MATLAB: Enter to confirm input-dialog?

I know there's a way to make the enter-key on the keyboard confirm the inputdlg() dialog, see here:
http://www.mathworks.de/support/solutions/en/data/1-39UWQT/index.html?product=ML&solution=1-39UWQT
Okay it's a workaround, the problem is, I have to store it in the matlab directory (because as said on the page: "Since it is dependent on several private functions, newid.m will only work if stored in this location.").. The problem now is, I want to make a code which doesn#t rely on user changes in the Matlab directory because of missing privileges... Is there still another (perhaps dirty) way to achieve this behaviour?
Thanks!
Solution:
Copy the newid.m from http://www.mathworks.de/support/solutions/en/data/1-39UWQT/index.html?product=ML&solution=1-39UWQT to a arbitrary folder, e.g. into your projects folder
Go into the folder where the original inputdlg() is stored; you can find this out via which inputdlg (e.g. C:\Program Files\MATLAB\R2011b\toolbox\matlab\uitools\inputdlg.m)
Go into the private-subdirectory and copy the two files getnicedialoglocation.m and setdefaultbutton.m and paste them into your project's folder where the newid.m is located. Now call all your input dialogs by using newid() instead of inputdlg()