macro command to designate but not open a file?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

macro command to designate but not open a file?

Bill Christens-Barry-2
In a macro I'd like to navigate to and choose but not open a file so I can assign its name (or full path) to a variable. I haven't identified a means of doing this using the File.* or getDirectory() macro commands. Is there a way to do this?

Also, I'd like to specify a default starting path for the getDirectory() macro command, but don't see a way to do this. Is there a means for doing this in the macro language?

Thanks,

Bill

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: macro command to designate but not open a file?

Aryeh Weiss
On 12/11/2015 5:00 PM, Bill Christens-Barry wrote:
> In a macro I'd like to navigate to and choose but not open a file so I can assign its name (or full path) to a variable. I haven't identified a means of doing this using the File.* or getDirectory() macro commands. Is there a way to do this?
Try this:


inputPath = File.openDialog("choose an image file");

if (inputPath == "") {
     exit("User canceled the dialog");
}
inputName = File.getName(inputPath);
inputDir = File.getParent(inputPath);
print(inputPath);
print(inputDir);
print(inputName);
inputPrefix = substring(inputName, 0, lastIndexOf(inputName, "."));
print(inputPrefix);

> Also, I'd like to specify a default starting path for the getDirectory() macro command, but don't see a way to do this. Is there a means for doing this in the macro language?
Dont know about this, but maybe you can do it with the dialog commands.
> Thanks,
>
> Bill
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: macro command to designate but not open a file?

ctrueden
In reply to this post by Bill Christens-Barry-2
Hi Bill,

> I'd like to navigate to and choose but not open a file
> so I can assign its name (or full path) to a variable.

The relevant function is File.openDialog.

Here is an example:
http://imagej.net/macros/OpenDialogDemo.txt

Or, you can use the ImageJ2 parameterized scripting approach and add a File
parameter to the very top of your script. E.g.:

  // @File path
  print("Path:", path);

For further details, see:
http://imagej.net/Script_parameters

Regards,
Curtis

On Thu, Nov 12, 2015 at 9:00 AM, Bill Christens-Barry <[hidden email]>
wrote:

> In a macro I'd like to navigate to and choose but not open a file so I can
> assign its name (or full path) to a variable. I haven't identified a means
> of doing this using the File.* or getDirectory() macro commands. Is there a
> way to do this?
>
> Also, I'd like to specify a default starting path for the getDirectory()
> macro command, but don't see a way to do this. Is there a means for doing
> this in the macro language?
>
> Thanks,
>
> Bill
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: macro command to designate but not open a file?

gankaku
In reply to this post by Bill Christens-Barry-2
Hi Bill,

the following command does what you need for the first part of your
question:


path = File.openDialog(title);


cheers,
Jan


2015-11-12 16:00 GMT+01:00 Bill Christens-Barry <[hidden email]>:

> In a macro I'd like to navigate to and choose but not open a file so I can
> assign its name (or full path) to a variable. I haven't identified a means
> of doing this using the File.* or getDirectory() macro commands. Is there a
> way to do this?
>
> Also, I'd like to specify a default starting path for the getDirectory()
> macro command, but don't see a way to do this. Is there a means for doing
> this in the macro language?
>
> Thanks,
>
> Bill
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>



--

CEO: Dr. rer. nat. Jan Brocher
phone:  +49 (0)6234 917 03 39
mobile: +49 (0)176 705 746 81
e-mail: [hidden email]
info: [hidden email]
inquiries: [hidden email]
web: www.biovoxxel.de

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: macro command to designate but not open a file?

Bill Christens-Barry-2
In reply to this post by Bill Christens-Barry-2
Jan,

I gave this a try, and it's just what I wanted.

Thanks for pointing me to this.

Bill

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: macro command to designate but not open a file?

Bill Christens-Barry-2
In reply to this post by Aryeh Weiss
Aryeh,

Thanks for pointing me to the File.openDialog() command and giving an
example - works great.

Bill

On Thu, Nov 12, 2015 at 10:22 AM, Aryeh Weiss <[hidden email]> wrote:

> On 12/11/2015 5:00 PM, Bill Christens-Barry wrote:
>
>> In a macro I'd like to navigate to and choose but not open a file so I
>> can assign its name (or full path) to a variable. I haven't identified a
>> means of doing this using the File.* or getDirectory() macro commands. Is
>> there a way to do this?
>>
> Try this:
>
>
> inputPath = File.openDialog("choose an image file");
>
> if (inputPath == "") {
>     exit("User canceled the dialog");
> }
> inputName = File.getName(inputPath);
> inputDir = File.getParent(inputPath);
> print(inputPath);
> print(inputDir);
> print(inputName);
> inputPrefix = substring(inputName, 0, lastIndexOf(inputName, "."));
> print(inputPrefix);
>
> Also, I'd like to specify a default starting path for the getDirectory()
>> macro command, but don't see a way to do this. Is there a means for doing
>> this in the macro language?
>>
> Dont know about this, but maybe you can do it with the dialog commands.
>
>> Thanks,
>>
>> Bill
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>>
>
> --
> Aryeh Weiss
> Faculty of Engineering
> Bar Ilan University
> Ramat Gan 52900 Israel
>
> Ph:  972-3-5317638
> FAX: 972-3-7384051
>
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: macro command to designate but not open a file?

gankaku
In reply to this post by Bill Christens-Barry-2
Hi Bill,

Actually, Curtis was first with his dual option answer. It's hard beating
Curtis' speed in answering ;-)

happy that it helped.
regards,
Jan

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: macro command to designate but not open a file?

Bill Christens-Barry-2
In reply to this post by Bill Christens-Barry-2
Thanks, Curtis. It's good to learn how to do this from you and other generous list members.

Bill

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: macro command to designate but not open a file?

Michael Schmid-3
In reply to this post by Aryeh Weiss
Bill Christens-Barry wrote:

> Also, I'd like to specify a default starting path for the getDirectory() macro command, but don't see a way to do this. Is there a means for doing this in the macro language?

This is not obvious, but you can use the 'call' method of the macro language to access a static java method such as setting the default directory for ImageJ 'open' commands:

  call("ij.io.OpenDialog.setDefaultDirectory", myNewDefaultDirectory);

By the way, you can also get the current default:

  currentDefaultDirectory = call("ij.io.OpenDialog.getDefaultDirectory");

Michael

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html