[Date Prev][Date Next] [Thread Prev][Thread Next]
[Date Index] [Thread Index] [New search]

SOLVED: FDK:Duplicating an element hierarchy



I solved this problem, but not exactly in the manner that I thought. Instead
of traversing the structure in the source, I got a list of TextItems and
used them to write the target structure and text. This worked for me because
I knew that my source element was always a single paragraph in a table cell.

Get TextList InObject(vFromPgf) NewVar(vTextList)
  MarkerAnchor XRefBegin ElementBegin String;

The nice thing about using TextItems is that you can use the TextOffset
property to correctly write the object to the target paragraph. Here is my
subroutine (FrameScript), with some comments.

Sub WriteElement
//
// Make a local variable to store the offset from the front of the
paragraph.
Local vOffset = 0;
Local i = 0;

// Get a list of text items in the source paragraph.
Get TextList InObject(vFromPgf) NewVar(vTextList)
  MarkerAnchor XRefBegin ElementBegin String;

// Loop through the text items.
Loop While(i <= vTextList.Count) LoopVar(i) Init(1) Incr(1)
  Get Member Number(i) From(vTextList) NewVar(vTextItem);
  // Set the text offset for the target paragraph.
  Set vTextOffset = vTextItem.TextOffset - vOffset;
  If vTextOffset < 0
    Set vTextOffset = 0;
  EndIf

  // Make a text location in the target paragraph.
  New TextLoc NewVar(vTextLoc) Object(vToPgf) Offset(vTextOffset);

  // If the text item is a string, write it to the target paragraph.
  If vTextItem.TextType = 'String'
    New Text TextLoc(vTextLoc) vTextItem.TextData;
  Else
    // If it is an element, insert the element and apply the attributes.
    If vTextItem.TextType = 'ElementBegin'
      New Element ElementDefName(vTextItem.TextData.ElementDef.Name)
        TextLoc(vTextLoc) NewVar(vNewElem);
      Set vNewElem.Attributes = vTextItem.TextData.Attributes;
    Else
      // If it is a marker or cross-reference, do not write it, but increase
the
      // offset variable. This is subtracted from the vTextOffset variable
above.
      Set vOffset = (vOffset + 1);
    EndIf
  EndIf
EndLoop
//
EndSub
//---------------------------------------------------------------------

A special thanks to Eric Dunn and Martin Smith for sending me some code to
test. Because of time constraints, I haven't tested it yet but when I do, I
will report back. Thanks to every one that responded.

Rick Quatro
Carmen Publishing
585-659-8267
rick@frameexpert.com
http://www.frameexpert.com
Author of FrameScript: A Crash Course



** To unsubscribe, send a message to majordomo@omsys.com **
** with "unsubscribe framers" (no quotes) in the body.   **