Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Exporting from Tinderbox >> Export Key Attributes and Text
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1191772724

Message started by steve harf on Oct 7th, 2007, 11:58am

Title: Export Key Attributes and Text
Post by steve harf on Oct 7th, 2007, 11:58am

Is there a simple export script that can export the key attributes of a note and its text without explicitly naming each member of the key attributes set? My idea is to have the script examine the contents of KeyAttributes and then export the label and value of each attribute found there, then append the note text.

Title: Re: Export Key Attributes and Text
Post by Mark Bernstein on Oct 8th, 2007, 12:32pm

I don't see a clean way to do this.

But often, key attributes are used to define a class of things: a BOOK has KeyAttributes of "author;title.publisher".  If that's your situation, and if you aren't exporting *too* many classes, you might just assign a different export template to each class.

Author: ^get(Author)
Title: ^get(Title)
Publisher: ^get(Publisher)

^text

Title: Re: Export Key Attributes and Text
Post by Lew Friedland on Jan 13th, 2008, 11:55am

I just tried creating this template, which answers my earlier request about a bibliographic template. When I try to choose it, the selection does not stick. It was created in TextEdit, saved as plain text, and placed in the same file as other Text Export templates. Any ideas?

Also, can this template be assigned to a prototype, e.g. the book prototype so that all notes inheriting the book proto also inherit the template? I'm pretty sure it can, but not sure how to assign it.
Thanks.

Title: Re: Export Key Attributes and Text
Post by Mark Bernstein on Jan 13th, 2008, 12:57pm

I'm not sure what you mean by "the selection does not stick".  If the template is disabled/greyed out. Tinderbox isn't sure it's a text file.  If the template is not in the menu, perhaps it's not stored in the right folder.  If the template changes after you have set it, perhaps an agent is trying to set it, too?

Yes, templates inherited from prototypes.

Title: Re: Export Key Attributes and Text
Post by Amber Vaesca on Feb 27th, 2008, 11:48am

The solution to this one requires only an action and a macro. First you need a macro that will print out the name of an attribute and then the value of an attribute:

Macro: printSetPair

Code:
$1: ^get($1)^<br />


Next you need an action. This can be a rule attached to the note which will be displaying these values, an agent, or event a stamp. Depends on how you want this data to be updated. Since KeyAttributes will probably not be changing a lot, I would suggest something low-impact. Once the template string is generated and stored in the note's attribute, it probably won't change often.

So the next step is getting every attribute and its value, listed in KeyAttributes, stored into another attribute as template code. Let's call this attribute HTMLExportKeyAttributes. Insert this expression into the action of your choice (to play around with it, try using a Rule, as that will update constantly and you can tweak the behaviour as you see fit).

Example note: Rule

Code:
HTMLExportKeyAttributes=format($KeyAttributes, "", "^do(printSetPair, '", "')^\n", "")


The format() function allows you to create a "pretty" list generated from a set. First you specify the set attribute KeyAttributes, and then four strings to determine what the list will look like. But we are going to use this function to create Tinderbox code! For simple explanation purposes, we do not need to delimit the whole list, so the first and last strings have been left empty, but if you want to wrap this section in a DIV or something, that would be where you put it. The important ones are the two strings that get inserted around the name of each value in the set. Here we are just creating the template code for a macro call around where Tinderbox will stick the set variable.

This will generate a text string of valid template export code, looking something like:


Code:
^do(printSetPair, 'Created')^
^do(printSetPair, 'Name')^
^do(printSetPair, 'WordCount')^


Note the carriage returns ("\n") will look funny in Tinderbox if you look at it in the attribute inspector, but they will export fine. At this point, you are pretty much done. All you need to do now is put this template call in your export template:


Code:
^get(HTMLExportKeyAttributes)


Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.