Jump to content

Iterated Scribedocload, Scribedocsubstitute, Scribedocappend in large, multisection document?


Recommended Posts

I have an important application where I build a very large document in optional, themed sections.  Currently, my process is to append a template section, make text substitutions against placeholders in each section, and then append another section, until the entire master document is built.  However, in practice this means that when I add a new section, Scribedocsubstitute must scan, find, and replace against an increasingly large document - even though only the new (short) section has any replacements to be made.  This means that the overall script slows exponentially with each added section.

Is there an elegant way to load a section, perform substitutions in *just* that section, and then append it to another loaded master document? 

The best way I can think of is the following:

  1. Save master document to container field.
  2. Load template section.
  3. Make substitutions to template section.
  4. Save changed template section to temporary container field.
  5. Load master document.
  6. Append changed template section to master document.
  7. Repeat.

While this "swapping out" might do the trick, I'm also concerned that I'm just trading one exponential problem for another; I'm using Filemaker Server, with container fields saved as files to disk.  That means that the "swapping out" solution results in a lot of larger and larger files getting transmitted back and forth.  It's probably still faster, but far from ideal.

Hoping to find some trickery with Scribedocload / append where I can work with two documents simultaneously.

Recommendations?

 

Edited by ghagen
Link to post
Share on other sites

Hello,

 

 The good news is that you can call ScribeDocAppend multiple times in a row without saving and reloading the master document.  I think this would make your workflow much easier.  You could easily have your assortment of optional sections saved to their own container fields, and have the substitutions performed to create the new sections.  Then, load your master document and call append for your needed sections, however many times.  Once you have finished the append calls, then save the final file.

 

There are several ways you could handle this in your script, here is a simple example:

If you have a master document and 3 optional sections to substitute and then append onto that master document, you could have six container fields for holding your templates.  1a, 1b, 2a, 2b, 3a, 3b.  In the A container, load your original template.  Loop through, performing substitutions, and saving the new/finalized sections in the B field.  You now have your finalized sections in containers 1b, 2b, and 3b.  

At this point, ScribeDocLoad your master document, and call append in succession. Once all have been appended, save your new document. You do not need to save between appends, so it would look a bit like:

 

ScribeDocLoad[Container or Url: Database::LoadMasterDocumentContainer]

ScribeDocAppend[Data: Database::Container1B]

ScribeDocAppend[Data: Database::Container2B]

ScribeDocAppend[Data: Database::Container3B]

ScribeDocSaveContainer[Select;Result: Database::SaveNewMasterDocumentContainer; New Name: "NewMasterDoc.docx"

 

While this is obviously a simplified version of what you may be doing, I believe this sort of set up would save you some overheard and speed up your workflow.

 

I hope this is helpful for your solution.

 

 

 

 

Link to post
Share on other sites

This worked, although it required adding a bunch of container fields to my schema.

Specifically, what ended up working best was creating a layout (script accessible only) that was connected to a "user" table (because the temporary files might need to be created in a multiuser environment) that had an abstracted link to a document templates table, and another abstracted link to the destination table/record where the resulting file needed to be saved.  This let me just refer to the object names without ever changing / losing context.

I did discover after much troubleshooting, that appending Microsoft Word documents likes to throw "corrupted file" errors if the document contains pictures in format other than JPEG.  PNG, GIF files embedded in the document, or ScribeDocSubstitute'd would create a "broken style" error dialog in Word.  Just in case anyone else runs against that wall.  

Thanks for the suggestion.

Edited by ghagen
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.