Hide Table of Contents

Get and Set Paragraph Properties Example (C#)

This example shows how to get and set the properties of paragraphs in note annotations.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Open a drawing with a note annotation that contains one or more
//    paragraphs.
// 2. Select the annotation in the graphics area.
// 3. Open an Immediate window.
//
// Postconditions:
// 1. For each paragraph in the selected note:
//    * Sets the paragraph and line spacing.
//    * Gets properties of numbered lists, if present.
//    * Gets text segment formatting.
//    * Bolds the text of each text segment.
// 2. Inspect the Immediate window.
//----------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
namespace GetParagraphs_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            SelectionMgr swSelMgr = default(SelectionMgr);
            Note noteObj = default(Note);
            Annotation swAnn = default(Annotation);
            Paragraphs paragraphs = default(Paragraphs);
            int numSegs = 0;
            int paragraphIndex = 0;
            int iseg = 0;
            TextFormat textFormat = default(TextFormat);
            int paraType = 0;
            int numberingtype = 0;
            int startas = 0;
            int format = 0;
            int numtype = 0;
            int numParagraphs = 0;
            string Text = null;
 
 
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
 
 
            if (swSelMgr.GetSelectedObjectCount() > 0)
            {
                noteObj = (Note)swSelMgr.GetSelectedObject6(1, -1);
                swAnn = (Annotation)noteObj.GetAnnotation();
                paragraphs = (Paragraphs)swAnn.GetParagraphs();
 
                numParagraphs = paragraphs.Count;
                Debug.Print("Number of paragraphs = " + numParagraphs);
                Debug.Print("");
 
 
                for (paragraphIndex = 0; paragraphIndex <= numParagraphs - 1; paragraphIndex++)
                {
                    paragraphs.CurrentParagraph = paragraphIndex;
                    Debug.Print("paragraph(" + paragraphIndex + "): ");
                    Debug.Print(paragraphs.GetText(true));
 
                    if (paragraphIndex == 0)
                    {
                        paragraphs.SetFormatting(0.0011, 0.0012);
                    }
                    else
                    {
                        paragraphs.SetFormatting(0.0021, 0.0022);
                    }
 
                    paragraphs.GetBulletsAndNumbering(out paraType, out numberingtype, out startas, out numtype, out format);
                    Debug.Print("Paragraph list type as defined in swParagraphType_e: " + paraType);
                    if (paraType == 1)
                    {
                        Debug.Print("Numbered list:");
                        Debug.Print("  Start numbering from location as defined in swNumberedListStartType_e: " + numberingtype);
                        Debug.Print("  Start numbering index: " + startas);
                        Debug.Print("  Type as defined in swNumberedListType_e: " + numtype);
                        Debug.Print("  Format as defined in swNumberingFormat_e: " + format);
                    }
 
                    numSegs = paragraphs.GetTextSegmentCount();
                    Debug.Print("Text segment count: " + numSegs);
 
                    for (iseg = 0; iseg <= numSegs - 1; iseg++)
                    {
                        Text = paragraphs.GetTextSegmentText(iseg);
                        Debug.Print("segment(" + iseg + "): " + Text);
 
                        textFormat = (TextFormat)paragraphs.GetTextSegmentFormat(iseg);
                        Debug.Print("  Typeface: " + textFormat.TypeFaceName);
                        Debug.Print("  Backwards? " + textFormat.BackWards);
                        Debug.Print("  Bold? " + textFormat.Bold);
                        Debug.Print("  Italic? " + textFormat.Italic);
                        Debug.Print("  Strikeout? " + textFormat.Strikeout);
 
                        textFormat.Bold = true;
                        paragraphs.SetTextSegmentFormat(iseg, textFormat);
 
                    }
 
                    paragraphs.UpdateParagraph();
 
                }
 
                swModel.GraphicsRedraw2();
 
            }
 
        }
 
 
 
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
 
        public SldWorks swApp;
 
    }
 
}
 

 



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get and Set Paragraph Properties Example (C#)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:




x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2016 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.