Hi,
According to your documentation, LayoutCollector->GetEnity is not able to return any information regarding position in the document for Runs. However, it seems like the behaviour of LayoutCollector is to ignore any other sibling nodes within a given parent node once a Run is encountered.
I have the following situation
{IF {MERGEFIELD A1} = “SomeValue” “{MERGEFIELD A2}” “[SomeBookmark]”}
This breaks down into the following nodes
FieldStart:
Run: IF
FieldStart:
Run: MERGEFIELD A1
FieldSeparator:
Run: «A1»
FieldEnd:
Run: = "SomeValue
Run: " "
FieldStart:
Run: MERGEFIELD A2
FieldSeparator:
FieldEnd:
Run: " "
Run: SomeBookmark
Run: "
FieldSeparator:
Run: BOOKMARK4
FieldEnd:
The first GetEntity returns the correct position for the first FieldStart, but any other node after the first Run simply returns null.
eg. code:
var doc = new Document(@"D:\LeTest.docx");
var layoutCollector = new LayoutCollector(doc);
var ifStart = doc.Sections[0].Range.Fields[0];
var positions = ifStart.Start.ParentNode.ChildNodes.ToArray().Select(x => new { Node = x, PositionObj = layoutCollector.GetEntity(x) });LeTest.zip (9.9 KB)