Paragrapgh text in Pagelayout

857
10
04-05-2011 12:30 PM
Highlighted
New Contributor II
Hi: I am new to ArcObjects. I am trying to implement paragraph text through Addins in the page layout so as to customize the size  and shape of the envelope surrounding the text. Textelement doesn't give that option. Could you help me with the sample script of paragraphtext in C# ? Any help is highly appreciated.
Thanks
Ann
Reply
0 Kudos
10 Replies
Highlighted
New Contributor II
wow-so many views and no reply. I hope somebody can help me to jump start ArcObjects. The unfortunate part with ArcObjects is the lack of books-just instructor led training only. I am deeply disappointed.
Waiting your help.
Thanks in advance
-Ann
Reply
0 Kudos
Highlighted
New Contributor III
Hi Ann,

I am working on converting some VBA to C# Add-Ins. Next on my plate is one that builds some ParagraphText boxes. I'll post a snip of C# here in the next few days.

If you post a few more details on what you want to accomplish, that would help.

-Jeff
Reply
0 Kudos
Highlighted
Occasional Contributor III
Here is a sample that will report the size of a single selected text element from the page layout:

 
Dim pMxDoc As IMxDocument
    Dim pPageLayout As IPageLayout
    Dim pGraphics As IGraphicsContainerSelect
   
    Set pMxDoc = ThisDocument
    Set pPageLayout = pMxDoc.PageLayout
    Set pGraphics = pPageLayout
    If pGraphics.ElementSelectionCount <> 1 Then
        MsgBox "Select only 1 map element.", vbOKOnly
        Exit Sub
    End If
    If TypeOf pGraphics.DominantElement Is ITextElement Then
        Dim te As ITextElement
        Set te = pGraphics.DominantElement
       
        Dim e As IElement
        Set e = te
       
        Dim p As IPolygon
        Set p = New Polygon
       
        e.QueryOutline pMxDoc.activeView.ScreenDisplay, p
       
        MsgBox "Width: " & p.Envelope.Width & "    Height: " & p.Envelope.Height
    End If
Reply
0 Kudos
Highlighted
New Contributor II
Thank you very much Jeff for your reply. Basically, I was trying to put together a big disclaimer kind of text in the map. I got it organized using verbatim literal in C# and defining it as a textelement. I wanted to get the full functionality of paragraph text element which will help me to define border and contain text within the defined rectangle. I started implementing it, but got nowhere (it's still a text element). Please see the code below and let me know where I am wrong:


--------------------------------------------------------------------------------------------
if (activeView is IPageLayout)
                {
                IScreenDisplay screenDisplay = activeView.ScreenDisplay;
                IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;
                IPoint point = displayTransformation.ToMapPoint(arg.X, arg.Y);
                ITextElement textElement = new TextElementClass();

                ITextElement paraTextElement = new ParagraphTextElementClass();
                paraTextElement.Text = strDisclaimer;
                ITextSymbol textSymbol = new TextSymbolClass();
                paraTextElement.Symbol = textSymbol;
                textSymbol.Size = 6;
                textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull;
                textElement.Symbol = textSymbol;
                textElement.Text = strDisclaimer;
                IElement element = textElement as IElement;
                IEnvelope textboxEnvelope = new EnvelopeClass();
                IEnvelope printEnvelope = pageLayout.Page.PrintableBounds;
                element.Geometry = point;
                graphicsContainer.AddElement(element, 0);
                graphicsContainerSelect.UnselectAllElements();
                activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                }
------------------------------------------------------------------------------------
string strDisclaimer=@"---some multi line text"
---------------------------------------------------------------------------------
Thanks in advance for your help!
Ann




Hi Ann,

I am working on converting some VBA to C# Add-Ins. Next on my plate is one that builds some ParagraphText boxes. I'll post a snip of C# here in the next few days.

If you post a few more details on what you want to accomplish, that would help.

-Jeff
Reply
0 Kudos
Highlighted
New Contributor III
Here is code that will drop a ParagraphTextElement on the layout in the lower left corner. This was banged together quickly, but does work and shows how to get at the various options available for ParagraphTextElement.



using System.Drawing;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.ADF.COMSupport;
// Also add references to "stdole" and "ESRI.ArcGIS.ADF.Local" to the project.
//...
// Call the method in your add-in button click such as:
//   string txt = @"This is just a bunch of text to place...";
//   BuildParaText(txt);

private void BuildParaText(string paraText)
{
    IActiveView activeView = ArcMap.Document.ActiveView;
  
    if (activeView is IPageLayout)
    {

        ITextElement paraTextElement = new ParagraphTextElementClass();
        // notice casts here
        IFrameProperties frameProperties = paraTextElement as IFrameProperties;
        IMarginProperties marginProperties = paraTextElement as IMarginProperties;
        IColumnProperties columnProperties = paraTextElement as IColumnProperties;
        ITextElement textElement = paraTextElement as ITextElement;
        IElement element = paraTextElement as IElement;

        // Set the margin and column count
        marginProperties.Margin = 4;
        columnProperties.Count = 1;

        // Reusable color object
        IRgbColor rgbColor = new RgbColorClass();

        // Outline, black
        ISimpleLineSymbol outline = new SimpleLineSymbolClass();
        rgbColor.Red = 0;
        rgbColor.Green = 0;
        rgbColor.Blue = 0;
        rgbColor.Transparency = 255;
        outline.Color = rgbColor;
        outline.Width = 0.5;
        outline.Style = esriSimpleLineStyle.esriSLSSolid;

        // Fill, white
        ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
        rgbColor.Red = 255;
        rgbColor.Green = 255;
        rgbColor.Blue = 255;
        rgbColor.Transparency = 255;
        fillSymbol.Color = rgbColor;

        // Set outline to fill
        fillSymbol.Outline = outline;

        // Set fill to background
        ISymbolBackground background = new SymbolBackgroundClass();
        background.FillSymbol = fillSymbol;

        // Set background to frame
        frameProperties.Background = background;

        // Text symbol
        ISimpleTextSymbol textSymbol = new TextSymbolClass();
        rgbColor.Red = 0;
        rgbColor.Green = 0;
        rgbColor.Blue = 0;
        Font font = new Font("Arial Narrow", 14, FontStyle.Bold);
        textSymbol.Font = OLE.GetIFontDispFromFont(font) as stdole.IFontDisp;
        textSymbol.Color = rgbColor;
        textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
        textSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;

        // Set text symbol to element
        textElement.Symbol = textSymbol;

        // Set the actual text to display
        textElement.Text = paraText;

        // Set the size of the text box to 5 x 2 in display units (ie. inches)
        IEnvelope envelope = new EnvelopeClass();
        envelope.PutCoords(0, 0, 5, 2);
        element.Geometry = envelope;

        // Add the text box to the layout
        IGraphicsContainer graphicsContainer = ArcMap.Document.PageLayout as IGraphicsContainer;
        graphicsContainer.AddElement(element, 0);

        activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

       
    }

}
Reply
0 Kudos
Highlighted
New Contributor II
Wow sweet! Thanks Jeff. That's a real life saver. I like your commented tips too. I sincerely appreciate your help.

Here is code that will drop a ParagraphTextElement on the layout in the lower left corner. This was banged together quickly, but does work and shows how to get at the various options available for ParagraphTextElement.



using System.Drawing;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.ADF.COMSupport;
// Also add references to "stdole" and "ESRI.ArcGIS.ADF.Local" to the project.
//...
// Call the method in your add-in button click such as:
//   string txt = @"This is just a bunch of text to place...";
//   BuildParaText(txt);

private void BuildParaText(string paraText)
{
    IActiveView activeView = ArcMap.Document.ActiveView;
  
    if (activeView is IPageLayout)
    {

        ITextElement paraTextElement = new ParagraphTextElementClass();
        // notice casts here
        IFrameProperties frameProperties = paraTextElement as IFrameProperties;
        IMarginProperties marginProperties = paraTextElement as IMarginProperties;
        IColumnProperties columnProperties = paraTextElement as IColumnProperties;
        ITextElement textElement = paraTextElement as ITextElement;
        IElement element = paraTextElement as IElement;

        // Set the margin and column count
        marginProperties.Margin = 4;
        columnProperties.Count = 1;

        // Reusable color object
        IRgbColor rgbColor = new RgbColorClass();

        // Outline, black
        ISimpleLineSymbol outline = new SimpleLineSymbolClass();
        rgbColor.Red = 0;
        rgbColor.Green = 0;
        rgbColor.Blue = 0;
        rgbColor.Transparency = 255;
        outline.Color = rgbColor;
        outline.Width = 0.5;
        outline.Style = esriSimpleLineStyle.esriSLSSolid;

        // Fill, white
        ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
        rgbColor.Red = 255;
        rgbColor.Green = 255;
        rgbColor.Blue = 255;
        rgbColor.Transparency = 255;
        fillSymbol.Color = rgbColor;

        // Set outline to fill
        fillSymbol.Outline = outline;

        // Set fill to background
        ISymbolBackground background = new SymbolBackgroundClass();
        background.FillSymbol = fillSymbol;

        // Set background to frame
        frameProperties.Background = background;

        // Text symbol
        ISimpleTextSymbol textSymbol = new TextSymbolClass();
        rgbColor.Red = 0;
        rgbColor.Green = 0;
        rgbColor.Blue = 0;
        Font font = new Font("Arial Narrow", 14, FontStyle.Bold);
        textSymbol.Font = OLE.GetIFontDispFromFont(font) as stdole.IFontDisp;
        textSymbol.Color = rgbColor;
        textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
        textSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;

        // Set text symbol to element
        textElement.Symbol = textSymbol;

        // Set the actual text to display
        textElement.Text = paraText;

        // Set the size of the text box to 5 x 2 in display units (ie. inches)
        IEnvelope envelope = new EnvelopeClass();
        envelope.PutCoords(0, 0, 5, 2);
        element.Geometry = envelope;

        // Add the text box to the layout
        IGraphicsContainer graphicsContainer = ArcMap.Document.PageLayout as IGraphicsContainer;
        graphicsContainer.AddElement(element, 0);

        activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

       
    }

}
Reply
0 Kudos
Highlighted
New Contributor III
Ann, if you see this, I have a question for you (or anyone else that cares to reply):

I am also working with ParagraphTextElement, which of course corresponds to a Rectangle Text (or Polygon Text, or Circle Text) on the ArcMap Draw toolbar.

Are you able to use this element and set various font sizes within the text using formatting tags and have the lines spaced correctly? I can't get it to work, and have posted a thread in the ArcGIS Desktop form: Line spacing for different sized text in rectangle text elements not working?

I am about ready to give up and use additional separate ITextElements and group them -- which will be a big pain since they don't do word-wrapping, etc. And it makes manual editing in ArcMap after placement more difficult.

-Jeff
Reply
0 Kudos
Highlighted
New Contributor II
Sorry Jeff, I fear that I don't have a solution here. It may be the ESRI thing. The formatting tags in ArcMAP doesn't seem to have that scalability. I still wonder why ESRI rep. doesn't care to reply to your ArcMAP thread!!!!
Ann
Reply
0 Kudos
Highlighted
New Contributor II
Here is code that will drop a ParagraphTextElement on the layout in the lower left corner. This was banged together quickly, but does work and shows how to get at the various options available for ParagraphTextElement.



using System.Drawing;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.ADF.COMSupport;
// Also add references to "stdole" and "ESRI.ArcGIS.ADF.Local" to the project.
//...
// Call the method in your add-in button click such as:
//   string txt = @"This is just a bunch of text to place...";
//   BuildParaText(txt);

private void BuildParaText(string paraText)
{
    IActiveView activeView = ArcMap.Document.ActiveView;
  
    if (activeView is IPageLayout)
    {

        ITextElement paraTextElement = new ParagraphTextElementClass();
        // notice casts here
        IFrameProperties frameProperties = paraTextElement as IFrameProperties;
        IMarginProperties marginProperties = paraTextElement as IMarginProperties;
        IColumnProperties columnProperties = paraTextElement as IColumnProperties;
        ITextElement textElement = paraTextElement as ITextElement;
        IElement element = paraTextElement as IElement;

        // Set the margin and column count
        marginProperties.Margin = 4;
        columnProperties.Count = 1;

        // Reusable color object
        IRgbColor rgbColor = new RgbColorClass();

        // Outline, black
        ISimpleLineSymbol outline = new SimpleLineSymbolClass();
        rgbColor.Red = 0;
        rgbColor.Green = 0;
        rgbColor.Blue = 0;
        rgbColor.Transparency = 255;
        outline.Color = rgbColor;
        outline.Width = 0.5;
        outline.Style = esriSimpleLineStyle.esriSLSSolid;

        // Fill, white
        ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
        rgbColor.Red = 255;
        rgbColor.Green = 255;
        rgbColor.Blue = 255;
        rgbColor.Transparency = 255;
        fillSymbol.Color = rgbColor;

        // Set outline to fill
        fillSymbol.Outline = outline;

        // Set fill to background
        ISymbolBackground background = new SymbolBackgroundClass();
        background.FillSymbol = fillSymbol;

        // Set background to frame
        frameProperties.Background = background;

        // Text symbol
        ISimpleTextSymbol textSymbol = new TextSymbolClass();
        rgbColor.Red = 0;
        rgbColor.Green = 0;
        rgbColor.Blue = 0;
        Font font = new Font("Arial Narrow", 14, FontStyle.Bold);
        textSymbol.Font = OLE.GetIFontDispFromFont(font) as stdole.IFontDisp;
        textSymbol.Color = rgbColor;
        textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
        textSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;

        // Set text symbol to element
        textElement.Symbol = textSymbol;

        // Set the actual text to display
        textElement.Text = paraText;

        // Set the size of the text box to 5 x 2 in display units (ie. inches)
        IEnvelope envelope = new EnvelopeClass();
        envelope.PutCoords(0, 0, 5, 2);
        element.Geometry = envelope;

        // Add the text box to the layout
        IGraphicsContainer graphicsContainer = ArcMap.Document.PageLayout as IGraphicsContainer;
        graphicsContainer.AddElement(element, 0);

        activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

       
    }

}


How can I use this code in Tool instead of button? Somehow, Textelement works fine. Paragraph text doesn't work at all. Any suggestions?
Reply
0 Kudos