Script access to favourite formats

I'd like to be able to enumerate user defined favourite formats. Could this be added to the existing list of useful script objects, perhaps as UserFormats?

Regards, AB

We'll add this to the next update, it'll be accessed via DOpus.favoriteformats.

Thanks Jon

I should probably have been more explicit when I asked for this. I want to define a button that will cycle through the application of favourite formats to the current folder using Set Format = "Fav Format Name". In order to do this I need a list of favourite format names. I can scan defined.off for path name="Fav Format Name" entries but it would be nice if the format object provided a simpler property-driven way of doing this. For example:

path_name = "MyFav"
format_type = "favorite"

or perhaps more generally useful:

path_name = "MyFav"
format_source = "defined"

which would also let me see when a standard format was in use...

path_name = "Images"
format_source = "contenttype"

Regards, AB

You should be able to use Format.format_explain to find out if there's a favorite format in use.

Yes I can, but if I want to find out what favourite formats are available I enumerate DOpus.favouriteformats and when I interrogate these the format_explain property is empty.

var v = DOpus.create.vector();
v.assign(DOpus.favoriteformats);
DOpus.output("v.count = " + v.count);
for (var i = 0; i < v.count; i++) DOpus.output(DOpus.TypeOf(v.format_explain));

which generates..

v.count = 2
empty
empty

Regards, AB

You need to interrogate the format_explain property of the Tab in question. The list of formats you get from favoriteformats is just a list of formats, they aren't "attached" to any particular tab or Lister.

Understood. So back to my original objective... other that interrogating defined.off to extract the names of saved favourite formats in order to construct Set Format = "My Fav" commands, is there a more elegant way of doing this?

Yes, enumerate DOpus.favoriteformats. Maybe I'm missing something in your request but that's exactly what it's for - getting a list of favorite formats, and your request is why we added it.

E.g. this will print the names of your favorite formats to the script log:

For Each fmt in DOpus.favoriteformats
	DOpus.Output fmt
Next

Your VB example works (of course!). My shaky grasp of OO infers that the "default" value for the Format object is the name of the format. However, when I try to apply that theory in JScript it doesn't work for me.

var ff;
for (var i = 0; i < DOpus.favoriteformats.count; i++){
ff = DOpus.favoriteformats(i);
DOpus.output("ff(" + i + ") = " + ff);
}

Output is...

ff(0) =
ff(1) =

No doubt a simple user error.... :smile:

This seems to work:

for (var e = new Enumerator(DOpus.favoriteformats);!e.atEnd();e.moveNext()) {
	var ff = e.item();
	DOpus.output(ff);
}