if (enumElement != null)
{
findElement = enumElement.Next();
while (findElement != null)
{
if (findElement is IParagraphTextElement)
{
findTextElement = findElement as ITextElement;
if (findTextElement.Text.EndsWith("></CLR>"))
{
MessageBox.Show("The Disclaimer Text, which autoupdates the time and date, is already placed in the map.");
}
else
{
graphicsContainer.AddElement(element, 0);
graphicsContainerSelect.UnselectAllElements();
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
}
findElement = enumElement.Next();
}
}
// Find certain pre-labeled graphics in the map and set their text IGraphicsContainer igc = whatever code you have that will return a PageLayout TextElement textelement; igc.reset(); IElement element = igc.next(); while(element != null){ if(element instanceof TextElement){ textelement = (TextElement)element; if(textelement.getName().equals("the_name_of_your_graphic_element")){ textelement.setText(somevalue); } } element = igc.next(); } // End Find pre-labeled graphics
I can give you a Java sample:
Your text elements would have to have names, that you defined when creating the element in ArcMap.// Find certain pre-labeled graphics in the map and set their text IGraphicsContainer igc = whatever code you have that will return a PageLayout TextElement textelement; igc.reset(); IElement element = igc.next(); while(element != null){ if(element instanceof TextElement){ textelement = (TextElement)element; if(textelement.getName().equals("the_name_of_your_graphic_element")){ textelement.setText(somevalue); } } element = igc.next(); } // End Find pre-labeled graphics
Dim graphicsContainer As ESRI.ArcGIS.Carto.IGraphicsContainer Dim pElement As ESRI.ArcGIS.Carto.IElement dim HasParagraph as Boolean = False graphicsContainer = CType(pMxDoc.FocusMap, ESRI.ArcGIS.Carto.IGraphicsContainer) graphicsContainer.Reset() pElement = graphicsContainer.Next While Not pElement Is Nothing If TypeOf pElement Is ESRI.ArcGIS.Carto.IParagraphTextElement Then HasParagraph = True pElement = graphicsContainer.Next End While If Not HasParagraph then graphicsContainer.AddElement (pParagraphElement, 0)
public void PerformTest() { const string myParaTextID = "MyDisclaimerTextID"; string paraText = "Sample disclaimer paragraph text"; IGraphicsContainer graphicsContainer = ArcMap.Document.PageLayout as IGraphicsContainer; IElement element; IElementProperties elementProperties; // Check if the disclaimer text element already exists in layout graphicsContainer.Reset(); while ((element = graphicsContainer.Next()) != null) { if (element is IParagraphTextElement) { elementProperties = element as IElementProperties; if (elementProperties.Name == myParaTextID) { MessageBox.Show("The Disclaimer Text, which autoupdates " + "the time and date, is already placed in the map."); return; } } } // No disclaimer found, so make one IParagraphTextElement paraTextElement = new ParagraphTextElementClass(); ITextElement textElement = paraTextElement as ITextElement; elementProperties = paraTextElement as IElementProperties; element = paraTextElement as IElement; // Set this so it can be found if this method called again elementProperties.Name = myParaTextID; // Set the actual text to display textElement.Text = paraText; // Set the size and location of the text box IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(0, 0, 3, 1); element.Geometry = envelope; // Add the text box to the layout graphicsContainer.AddElement(element, 0); ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
Here's an example, although written in VB.NETDim graphicsContainer As ESRI.ArcGIS.Carto.IGraphicsContainer Dim pElement As ESRI.ArcGIS.Carto.IElement dim HasParagraph as Boolean = False graphicsContainer = CType(pMxDoc.FocusMap, ESRI.ArcGIS.Carto.IGraphicsContainer) graphicsContainer.Reset() pElement = graphicsContainer.Next While Not pElement Is Nothing If TypeOf pElement Is ESRI.ArcGIS.Carto.IParagraphTextElement Then HasParagraph = True pElement = graphicsContainer.Next End While If Not HasParagraph then graphicsContainer.AddElement (pParagraphElement, 0)
Ann, if I understand you correctly, there could be other ParagraphTextElements on the layout, and you need to add your disclaimer element if it doesn't exist.
The following method will do that:public void PerformTest() { const string myParaTextID = "MyDisclaimerTextID"; string paraText = "Sample disclaimer paragraph text"; IGraphicsContainer graphicsContainer = ArcMap.Document.PageLayout as IGraphicsContainer; IElement element; IElementProperties elementProperties; // Check if the disclaimer text element already exists in layout graphicsContainer.Reset(); while ((element = graphicsContainer.Next()) != null) { if (element is IParagraphTextElement) { elementProperties = element as IElementProperties; if (elementProperties.Name == myParaTextID) { MessageBox.Show("The Disclaimer Text, which autoupdates " + "the time and date, is already placed in the map."); return; } } } // No disclaimer found, so make one IParagraphTextElement paraTextElement = new ParagraphTextElementClass(); ITextElement textElement = paraTextElement as ITextElement; elementProperties = paraTextElement as IElementProperties; element = paraTextElement as IElement; // Set this so it can be found if this method called again elementProperties.Name = myParaTextID; // Set the actual text to display textElement.Text = paraText; // Set the size and location of the text box IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(0, 0, 3, 1); element.Geometry = envelope; // Add the text box to the layout graphicsContainer.AddElement(element, 0); ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
Note that the "Name" property used to ID the disclaimer element is visible and editable to the user on the properties dialog for the element in ArcMap. If you want more robust tagging of elements (ie, hidden from the user), you need to attach a custom object such as a PropertySet.
-Jeff