[proFit-list] opening a data window using Applecscript

proFit Support profit at quansoft.com
Thu Nov 24 22:53:43 CST 2011


Jeremy

This is becoming somewhat complex now. I suggest moving this off the list (unless someone objects). Could you send us, directly to profit at quansoft.com, a step-by-step description that either leads up to the error message you describe or that leads to loading the data into the wrong window? This would be helpful.

Thanks

Kurt Sutter
QuantumSoft


On 24. Nov 2011, at 17:41, Harbinson, Jeremy wrote:

> Hi,
> Thanks for replying so promptly and sorry for posting from the wrong (unregistered) Email address. If I understand your interpretation of the script correctly, then you seem to believe that it should be doing just what I want it to do. I did some more tests and the rather long email I hope conveys what is going on. 
> 
> The purpose for writing the script was to automate the procedure of transferring data from Python to Profit for purposes of charting (etc)  - I had been doing this manually in the ways you suggest, but it seemed that it should be possible to script this procedure. 
> 
> Unlike you, when I ran the script in the Profit environment in which I first tested it I got no error message (a bit worrying). This environment had lots of Profit windows open. When I ran the script in this environment a data window called JA260793_mod.csv.data happened to be open and in the foreground. The script does not create a window called python_2_row_b.csv (which you think it should), it creates a window called 'Untitled data 40', and the data is not loaded into 'Untitled data 40' but into 'JA260793_mod.csv.data' (two extra columns are created in this window). The script also plots the first two columns of 'JA260793_mod.csv.data'. If I run the script again it creates another data window 'Untitled data 41' but this time loads the data into 'Untitled data 40' and plots the first two columns of this data sheet. So, it creates a new window but uses the previously opened one. 
> 
> If I shut Profit down and restart it to produce a virgin environment (no data windows etc) running the script does indeed produce a error message. If I then rem out the faulty line the script works just fine (and just as you describe it should work). If I then create (or load) a data window (junk.data) with some data and run the script it adds the data to this open window (which seems reasonable) and keeps the original name of the window. However, if I then add a 'make data table' line to the script in place of the bad line (which I had previously remmed out), running the script produces a similar result to that which I first reported: a data window is created (untitled data) but the data is loaded not into 'untitled data' but into the table I opened/created previously (junk.data) and the first two columns of junk.data are plotted. 
> 
> So, how can I force the data to be loaded into the newly created table ('untitled data') and not into the already opened table 'junk.data' ? One option, of course, would be to remove the 'make data table' line, and before running the script create a new data table by hand into which the data would be loaded, but I guess it should be possible to write a script that opens and uses a table.
> 
> I had likewise considered doing this with Python in Profit (maybe using Pydataframe?) and calling that script by means of an Applescript, but for various reasons I have trying to improve my knowledge of Applescript. 
> all the best,
> Jeremy
> 
> 
> 
> ________________________________________
> From: profit-list-bounces at quantum-soft.com [profit-list-bounces at quantum-soft.com] On Behalf Of pro Fit Support [profit at quansoft.com]
> Sent: Thursday, November 24, 2011 5:40 AM
> To: all things about pro Fit
> Subject: Re: [proFit-list] opening a data window using Applecscript
> 
> Dear Jeremy
> 
> The "open" command will generate a new data window unless a window of that file is already open, in which case it just brings that window to front.
> 
> Hence the new window that you create with "make new table" (why do you have a "data window" appended to that -- it generates a syntax error for me) is ignored. The first time you run the script, a window named python_2_row_b.csv will be opened. The second time you run the script, the open command first checks if the file python_2_row_b.csv is already open as a window and, if yes, it just selects that window.
> 
> To do what you want, I see the following possibilities:
> 
> 1. Do not open a window of your own at all. Just open the csv file using the open command, then plot it, then close the data window. Now you can e.g. modify the contents of the csv file and run the script again.
> 
> 2. Alternatively, after opening the csv file, copy its contents to the data window you have opened, then close the csv window.
> 
> 3. Alternatively, use a script within pro Fit to open a data window, read the csv file into that data window, and plot the data (using the csv module of Python).
> 
> BTW: pro Fit 6.2.4 (to be released soon) should fix the issues in the Apple Script Dictionary that we see in your script, such as "«class as  »:data window"
> 
> Best regards
> 
> Kurt Sutter
> QuantumSoft
> 
> 
> On 23 Nov 2011, at 5:36, Jeremy Harbinson wrote:
> 
> Hi,
> I am trying to write an Applescript that will create a new data window, load a two column csv file into that window, and then plot these two columns.
> 
> Using the record tool of the Applescript editor I was able to get a sequence of commands that do this, except that when run it creates a new data window (I will call this window 2) but then imports the data into the last used  data window and plots the first two columns of this older window (not good). If I rerun the script, it creates a new data window (window 3) and then imports the data into window 2 (created the first time the script was run) and plots that data - data window 3 remaining empty unless I run the script again.
> 
> What I would like is to be able to create a data window, load data into that newly created widow (and not into another one), and plot data from it (and not from the other window). The script I have been using is (in its current form):
> 
> tell application "pro Fit 6.2.2"
> activate
> make new table  data window
> (*make new table*)
> data import options mode custom headerLines 0 title delimiter "," title length 0 delimiter "f," line length 0 terminator "\\R<smb://R>" date format "yyyy-MM-dd hh:mm:ss" with titles without copyInfo, useDoublequotes and dates
> open "/Users/jeremyharbinson1/IBM/Python files/temp_files/python_2_row_b.csv" with «class impo» given «class as  »:data window
> plot data xAxisColumn 1 yAxisColumn {2} zAxisColumn {} xScaling lin yScaling lin xAxis 1 yAxis 1 point opacity 1.0 curve opacity 1.0 fill opacity 1.0 with autoX, autoY, new window, new graph and connected without selected only and error bars
> end tell
> 
> This script is not the same as the recorded version - I have been trying (I get the feeling more or less randomly) various combinations of 'make', 'new', 'data', 'table', 'window' etc in place of what is currently 'make new table data window' to create a window that will be the target window for the import and plot commands- nothing worked, resulting in either the same problem described above or an error message. I do not like Applescript.......
> 
> I would be grateful for any suggestions!
> all the best,
> Jeremy
> _______________________________________________
> proFit-list mailing list
> proFit-list at quantum-soft.com<mailto:proFit-list at quantum-soft.com>
> http://quantum-soft.com/mailman/listinfo/profit-list_quantum-soft.com
> 
> 
> 
> _______________________________________________
> proFit-list mailing list
> proFit-list at quantum-soft.com
> http://quantum-soft.com/mailman/listinfo/profit-list_quantum-soft.com




More information about the proFit-list mailing list