Okay, new version of the script.
This one checks the document for existing textbox annotations. If one is found that is on the same page and has the same X and Y coordinates, then instead of adding a new box, it modifies the existing box, setting its appearance based on the token values, and appending the text from the token to the end of the existing text in the textbox.
namespace WorkflowActivity.Scripting.SDKScript
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Laserfiche.RepositoryAccess;
using Laserfiche.RepositoryAccess.Common;
/// <summary>
/// Provides one or more methods that can be run when the workflow scripting activity is performed.
/// </summary>
public class Script1 : RAScriptClass104 //modify this line if Workflow is a different version than 10.4
{
/// <summary>
/// This method is run when the activity is performed.
/// </summary>
protected override void Execute()
{
//Make sure that we are working with a document...
if(this.BoundEntryInfo.EntryType == EntryType.Document)
{
//Retrieve all Token values from the Workflow
int pToken = Convert.ToInt32(this.GetTokenValue("Textbox Page Number"));
int xToken = Convert.ToInt32(this.GetTokenValue("Textbox X Position"));
int yToken = Convert.ToInt32(this.GetTokenValue("Textbox Y Position"));
int wToken = Convert.ToInt32(this.GetTokenValue("Textbox Width"));
int hToken = Convert.ToInt32(this.GetTokenValue("Textbox Height"));
int fToken = Convert.ToInt32(this.GetTokenValue("Textbox Font Size"));
string tToken = this.GetTokenValue("Textbox Text").ToString();
string cToken = this.GetTokenValue("Textbox Comment").ToString();
bool appendText = false;
//Get a reference to page 1 of the entry...
DocumentInfo di = Document.GetDocumentInfo(this.BoundEntryId, this.RASession);
PageInfo pi = di.GetPageInfo(pToken);
//Retrieve all existing textBox annotations on the document
//If an annotation exists that is on the same page, at the same coordinates,
//then we will want to append the text to it, instead of creating a new textbox.
List<AnnotationBase> anns = (List<AnnotationBase>)di.GetAnnotations();
foreach(AnnotationBase ann in anns)
{
if (ann.AnnotationType == AnnotationType.TextBox)
{
TextBoxAnnotation tb = (TextBoxAnnotation)ann;
if(tb.PageNumber == pToken && tb.Coordinates.X == xToken && tb.Coordinates.Y == yToken)
{
appendText = true;
tToken = tb.Text + "\n" + tToken;
tb.Text = tToken;
tb.Comment = cToken;
LfPoint tbPosition = new LfPoint(xToken, yToken);
LfSize tbSize = new LfSize(wToken, hToken);
tb.Coordinates = new LfRectangle(tbPosition, tbSize);
tb.TextSize = fToken;
tb.Save();
}
}
}
//If the text was not appended to an existing textbox, create a new textbox.
if (!appendText)
{
//Create a new TextBoxAnnotation...
TextBoxAnnotation textBox = new TextBoxAnnotation();
//Set the coordinates and other properties from the token values...
LfPoint textBoxPosition = new LfPoint(xToken, yToken);
LfSize textBoxSize = new LfSize(wToken, hToken);
textBox.Coordinates = new LfRectangle(textBoxPosition, textBoxSize);
textBox.TextSize = fToken;
textBox.BorderColor = LfColor.TRANSPARENT;
textBox.FillColor = LfColor.TRANSPARENT;
textBox.Text = tToken;
textBox.Comment = cToken;
//Add the annotation to the page...
pi.AddAnnotation(textBox);
}
}
}
}
}