Jump to content

Rich Text Files (RTF)


sdavenport

Recommended Posts

I am attempting to CreateResource to return a RTF. The RulesSystemGuide p.78 indicates this is possible...

 

CreateResource...This function creates a resource from the given file, using the given type. "Type" must be one of the following values: "graphic", "plain text file", "tagged text file", or "RTF text file"...

 

Anyone have success doing this???

Link to comment
Share on other sites

You need to use the content property of the FusionProResource object to return the tagged markup that the Resource object represents. Try this:

var MyResource = CreateResource(Rule("Random Quote") + ".txt", "plain text file");

var fullString = MyResource.content;

And go from there.

You have to use the content property because the default toString method on the FusionProResource object returns the name of the resource. The reason for this is so that if you create a basic rule that returns one of a set of formatted text resources, like this:

switch (Field("Destination"))

{

case "Ireland":

return Resource("Story-Ireland.TXT");

case "Italy":

return Resource("Story-Italy.TXT");

// etc.

default:

return Resource("Story-Generic.TXT");

}

And you validate the rule in the Rule Editor, you see the name of the resource that was returned, instead of a bunch of markup tags.

Link to comment
Share on other sites

I am attempting to CreateResource to return a RTF. The RulesSystemGuide p.78 indicates this is possible...

 

CreateResource...

This function creates a resource from the given file, using the given type. "Type" must be one of the following values: "graphic", "plain text file", "tagged text file", or "RTF text file"...

 

Anyone have success doing this???

Sorry, that's a mistake in the documentation. External RTF resource files are not supported.

 

If you have an RTF files whose content you want to use in FusionPro, you can create a Formatted Text Resources and copy-and-paste the contents from your favorite RTF editor application into the Variable Text Editor. If you need to externalize the file again, you can click OK in the Text Editor, then click "View Source" in the Resource Editor dialog to get the tagged markup, which you can then paste into a text file and use it as a Tagged File Resource.

Link to comment
Share on other sites

  • 3 months later...

Mark/ Dan,

 

Is there a way to encapsulate multiple tagged entries into one tagged text file?I see that i can use <variable name="XXX"> for rule usage in a tagged file but is there a way to encapsulate it similar to the way the .def file separates formatted resources?

Link to comment
Share on other sites

Is there a way to encapsulate multiple tagged entries into one tagged text file?I see that i can use <variable name="XXX"> for rule usage in a tagged file but is there a way to encapsulate it similar to the way the .def file separates formatted resources?

Sorry, I'm not sure I understand what you mean by "encapsulate" here, nor what you're ultimately trying to accomplish. Can you provide an example of the multiple tagged entries that you're trying to "encapsulate" and what the desired result is?

 

The <variable> tag brings in the value of a field or the result of a rule. It can't be used to import another resource directly. In order to include a resource within another text resource, you would need to make a rule which returns the first resource and then use the rule's name in a <variable> tag in the second resource. The Data Definition (.def) file simply stores the resources by name, but simply having those in the job doesn't do anything; you still need rules to access them.

 

If you want to just paste a few resources together, I think the simplest way is with a rule like so:

return Resource("Resource1").content + Resource("Resource2").content + Resource("Resource3").content; //etc 

Or, you can just open up each Tagged File resource in a text editor (or click "View Source" for any Formatted Text Resources), copy the markup, and paste each one in turn into a new file and save that file, which can then be used as a Tagged File resource with the combined contents.

Link to comment
Share on other sites

Or, you can just open up each Tagged File resource in a text editor (or click "View Source" for any Formatted Text Resources), copy the markup, and paste each one in turn into a new file and save that file, which can then be used as a Tagged File resource with the combined contents.

 

 

I am currently doing this with the following.

 

if(FusionPro.isMac)

{

Asset = new ExternalDataFileEx("AssetDB.txt", "\t");

ImagePath = ":bodytext:";

}

if(FusionPro.isWindows)

{

Asset = new ExternalDataFileEx("E:\\HM\\datafiles\\AssetDB.txt", "\t");

ImagePath = ("E:\\ftpHome\\bodytext\\");

}

 

FindMe = Asset.FindRecord("School", (Field("School")));

dnl = Asset.GetFieldValue(FindMe, "Asset");

 

function BodyResourceExists(){

try

{

btf = CreateResource(ImagePath + dnl + ".txt", "tagged text file", true);

return true;

}

catch (e)

{

return false;

}

}

 

if (BodyResourceExists() == true)

{

return btf;

}

 

if (BodyResourceExists() == false)

{

btf = "";

return btf;

}

 

The idea would be to have one file that has a somethig similar to this (from the .def file) where i can use "Name" to have the javascript find the correct resource. i know i would probably have to alter the code above.

 

<FormattedResource

Name = "1061"

Comment = "2008"

>

<![CDATA[<p style="(no style)" quad="C" findent="0" lindent="0" rindent="0" leadbefore="0" leadafter="0" widows="2" kerning="true" hyphenate="false" skipifempty="false" skipifemptyvar="false" noparabreakoncopyfit="false"><tracking newsize="0.000000"><f Name="Times LT Std"><z newsize="10.0"><color Name="Black">An interest-free monthly installment plan is available.]]></FormattedResource>

 

<FormattedResource

Name = "1066"

Comment = "2008"

>

<![CDATA[<p style="(no style)" quad="C" findent="0" lindent="0" rindent="0" leadbefore="0" leadafter="0" widows="2" kerning="true" hyphenate="false" skipifempty="false" skipifemptyvar="false" noparabreakoncopyfit="false"><tracking newsize="0.000000"><f Name="Times LT Std"><z newsize="10.0"><color Name="Black">An interest-free annual installment plan is available.]]></FormattedResource>

Link to comment
Share on other sites

The idea would be to have one file that has a somethig similar to this (from the .def file) where i can use "Name" to have the javascript find the correct resource. i know i would probably have to alter the code above.

Well, the two Formatted Text Resources in your example look exactly the same to me, other than the word "monthly" or "annual", so I would think it would be simpler just to make a rule that returns one of those two words, or just the plain text. But if you just want to use Formatted Text Resources instead of external tagged text resource files, you can call the Resource() function to access them by name from the Data Definition instead of calling CreateResource() to load the external resources from disk. So replace this:

btf = CreateResource(ImagePath + dnl + ".txt", "tagged text file",  true);

with this:

btf = Resource(dnl);

Link to comment
Share on other sites

the job consists of over 300 brochure varieties. An external data file has the name of the organization and a "sku" such as "1160" that is also used on individual tagged text files in a separate directory. The javascript from earlier checks for the existence of said file and returns the appropriate tagged file. I was wondering if instead of having the individual text files, can one text file be used to hold all the tagged text. I do not know if any markup can be used to individualize each tagged instance in one file that javascript can parse through for say resource/ tagged text "1160".
Link to comment
Share on other sites

the job consists of over 300 brochure varieties. An external data file has the name of the organization and a "sku" such as "1160" that is also used on individual tagged text files in a separate directory. The javascript from earlier checks for the existence of said file and returns the appropriate tagged file. I was wondering if instead of having the individual text files, can one text file be used to hold all the tagged text. I do not know if any markup can be used to individualize each tagged instance in one file that javascript can parse through for say resource/ tagged text "1160".

So you want to somehow parse through this big combined tagged markup file to extract a particular section? I haven't tried to do anything like that.

 

In theory, you could set it up so that the whole "combined" file is a tab-delimited external data file, where each line (record) has the SKU number, a tab, and then the corresponding tagged markup. You would just need to remove any other new line and carriage return characters, but those are ignored by FusionPro's tag parser anyway. Then you could access that with ExternalDataFileEx. I haven't tried this, and I'm not sure it's the most easily maintainable solution, but that's my idea.

Link to comment
Share on other sites

I thought about that and tried it out and it becomes a pretty big problem when revising. I managed to actually get individual files from the .def file using applescript and automator. Not clean but less error prone. Thanks for your help.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...