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(); } }
Ann, Jeff, please could put code in Visual Basic Net, it happens that I can not do the equivalent = (.. I'm still very puppy programming on these issues. Greetings!
Public Sub PerformTest() Const myParaTextID As String = "MyDisclaimerTextID" Dim paraText As String = "Sample disclaimer paragraph text" Dim graphicsContainer As ESRI.ArcGIS.Carto.IGraphicsContainer = TryCast(ArcMap.Document.PageLayout, ESRI.ArcGIS.Carto.IGraphicsContainer) Dim element As ESRI.ArcGIS.Carto.IElement Dim elementProperties As ESRI.ArcGIS.Carto.IElementProperties ' Check if the disclaimer text element already exists in layout graphicsContainer.Reset() element = graphicsContainer.Next() While element IsNot Nothing If TypeOf element Is ESRI.ArcGIS.Carto.IParagraphTextElement Then elementProperties = TryCast(element, ESRI.ArcGIS.Carto.IElementProperties) If elementProperties.Name = myParaTextID Then MessageBox.Show("The Disclaimer Text, which autoupdates " & "the time and date, is already placed in the map.") Return End If End If element = graphicsContainer.Next() End While ' No disclaimer found, so make one Dim paraTextElement As ESRI.ArcGIS.Carto.IParagraphTextElement = New ESRI.ArcGIS.Carto.ParagraphTextElementClass() Dim textElement As ESRI.ArcGIS.Carto.ITextElement = TryCast(paraTextElement, ESRI.ArcGIS.Carto.ITextElement) elementProperties = TryCast(paraTextElement, ESRI.ArcGIS.Carto.IElementProperties) element = TryCast(paraTextElement, ESRI.ArcGIS.Carto.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 Dim envelope As ESRI.ArcGIS.Geometry.IEnvelope = New esri.ArcGIS.Geometry.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(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics, Nothing, Nothing) End Sub
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
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.NET 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)
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)
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
// 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
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.