Help with menu item opening a project

Here's where to discuss using Stéphane Leys' very well done alternative runtime editor. If you're a control freak at runtime you have to check this out!

Help with menu item opening a project

Postby drpitcairn » Fri May 29, 2009 9:38 am

Hi,
I set up a menu item to open another project, one in which I will copy some cards to be saved. I set it up with the file path:
Code: Select all
on itemSelect
  open project "MBAir HD:Documents:Boger General Analysis:Saved Cases"
end itemSelect

And I think this is the correct path to the file. Yet, when I use the menu item it asks me where it is in a dialog. Am I just not doing it right?

Also, if I convert this to a standalone with the two projects interacting, does that work? What about the file path part? Would not be the same on another person's computer.

Thanks,
Richard
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: Help with menu item opening a project

Postby S. Leys » Fri May 29, 2009 9:57 am

rpitcairn wrote:I set up a menu item to open another project, one in which I will copy some cards to be saved. I set it up with the file path:
Code: Select all
on itemSelect
  open project "MBAir HD:Documents:Boger General Analysis:Saved Cases"
end itemSelect

And I think this is the correct path to the file. Yet, when I use the menu item it asks me where it is in a dialog. Am I just not doing it right?


If SC asks where is you project, it means that the path is not correct.
Try
get exists(file, pathName)
with the same pathname, it will probably return false.
Try to ask file to get the correct path.

S.
User avatar
S. Leys
 
Posts: 628
Joined: Sun Jul 06, 2008 11:03 am

Re: Help with menu item opening a project

Postby JoeKoomen2011 » Fri May 29, 2009 10:08 am

What I like to do is create a userProperty for the project that I store the filepath in.

The first time you use the project, you do something like the vague code below.

Code: Select all
on mouseUp
  if exists(the projectStoredPath of this project) then
         -- get the file path from the userProp
  else
          define projectStoredPath of this project
          answer file "Select project to open:"
          if it is empty then exit mouseUp
          put it into the projectStoredPath of this project
          -- get the file path from the userProp
  end if
  -- do your open project routine
  -- which should include an "if exists file tProjectData"
  -- routine to check it the path is valid, otherwise
  -- repeat the "else" routine above
  open file tProjectData
  -- do stuff
 
end mouseUp
Joe Koomen
>> Random! ...Damn near killed 'em! <<
User avatar
JoeKoomen2011
 
Posts: 464
Joined: Thu Mar 12, 2009 1:38 pm

Re: Help with menu item opening a project

Postby drpitcairn » Fri May 29, 2009 10:14 am

Code: Select all
get exists(file, "MBAir HD:Users:drpitcairn:Documents:Boger General Analysis:Saved Cases")

When I use this, no response.

How do I do this?
Try to ask file to get the correct path.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: Help with menu item opening a project

Postby drpitcairn » Fri May 29, 2009 10:19 am

Joe,
Looks good. I will try using it (once I get the path figured out!)
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: Help with menu item opening a project

Postby drpitcairn » Fri May 29, 2009 10:26 am

Also before I go too far in this direction, is it going to work to make this project a standalone if there are two projects included? I am thinking of maintaining some sort of automatic path connection.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: Help with menu item opening a project

Postby S. Leys » Fri May 29, 2009 10:50 am

rpitcairn wrote:
Code: Select all
get exists(file, "MBAir HD:Users:drpitcairn:Documents:Boger General Analysis:Saved Cases")

When I use this, no response.

when you get something, it goes into it.
Code: Select all
get exists(file, "MBAir HD:Users:drpitcairn:Documents:Boger General Analysis:Saved Cases")
put it

will put true if the file exists.

How do I do this?
Try to ask file to get the correct path.

Look at "ask file" in the LG.
It also returns its result into it.

S.
User avatar
S. Leys
 
Posts: 628
Joined: Sun Jul 06, 2008 11:03 am

Re: Help with menu item opening a project

Postby johnjohnston1 » Fri May 29, 2009 10:52 am

rpitcairn wrote:
Code: Select all
get exists(file, "MBAir HD:Users:drpitcairn:Documents:Boger General Analysis:Saved Cases")

When I use this, no response.

How do I do this?
Try to ask file to get the correct path.


try looking in it after getting
or
Code: Select all
put exists(file, "MBAir HD:Users:drpitcairn:Documents:Boger General Analysis:Saved Cases")


ask file "?"
put it

I use a script:
Code: Select all
on pf
  answer file "Choose a file:"
  put it
end pf

so that I can type pf in the message box and hit return to get the path to any file.
User avatar
johnjohnston1
 
Posts: 196
Joined: Sun Jul 06, 2008 10:42 am
Location: Glasgow, UK

Re: Help with menu item opening a project

Postby S. Leys » Fri May 29, 2009 10:59 am

Joe Koomen wrote:
Code: Select all
          put it into the projectStoredPath of this project


The correct syntax is :
Code: Select all
          set the projectStoredPath of this project to it


And I would recommend to do :
Code: Select all
    define "projectStoredPath" of this project

(with quotes)

S.
User avatar
S. Leys
 
Posts: 628
Joined: Sun Jul 06, 2008 11:03 am

Re: Help with menu item opening a project

Postby Scott » Fri May 29, 2009 12:59 pm

Just to avoid confusion... the folks here mentioning "ask file" are really referring to "answer file". "Answer file" will return the path to an existing file. "Ask file" is used to return a path for a new file you wish to name (and most commonly write to disk).
User avatar
Scott
Site Admin
 
Posts: 1217
Joined: Sat Jul 05, 2008 1:37 pm
Location: Northern Sierra Nevada

Re: Help with menu item opening a project

Postby drpitcairn » Fri May 29, 2009 4:22 pm

Code: Select all
    on pf
      answer file "Choose a file:"
      put it
    end pf

This worked great and I found the problem with my file path was the lack of file type at the end of the file. I did not expect that thinking that was not usually part of the name on a Mac. So this is the path:
Code: Select all
MBAir HD:Users:drpitcairn:Documents:Boger General Analysis:Saved Cases.sc45
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: Help with menu item opening a project

Postby Scott » Fri May 29, 2009 4:46 pm

rpitcairn wrote:I found the problem with my file path was the lack of file type at the end of the file. I did not expect that thinking that was not usually part of the name on a Mac.


It has been since OS X... but the Finder's default settings don't show your file extensions which, IMHO, causes confusion.

The Finder's prefs has an option to show all file extensions.
User avatar
Scott
Site Admin
 
Posts: 1217
Joined: Sat Jul 05, 2008 1:37 pm
Location: Northern Sierra Nevada

Re: Help with menu item opening a project

Postby drpitcairn » Fri May 29, 2009 4:58 pm

Well obviously I got confused so that confirms it.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: Help with menu item opening a project

Postby S. Leys » Fri May 29, 2009 11:11 pm

supercardus wrote:Just to avoid confusion... the folks here mentioning "ask file" are really referring to "answer file". "Answer file" will return the path to an existing file. "Ask file" is used to return a path for a new file you wish to name (and most commonly write to disk).


Ah, yes, ask, answer, I've never been able to remember which one is doing what.

S.
User avatar
S. Leys
 
Posts: 628
Joined: Sun Jul 06, 2008 11:03 am


Return to Using MPI

Who is online

Users browsing this forum: No registered users and 1 guest

cron