Hide Table of Contents

Get and Set Paragraph Properties Example (VB.NET)

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.
'----------------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
 
Partial Class SolidWorksMacro
 
 
    Sub main()
 
        Dim swModel As ModelDoc2
        Dim swSelMgr As SelectionMgr
        Dim swAnnObj As Note
        Dim swAnn As Annotation
        Dim paragraphs As Paragraphs
        Dim numSegs As Integer
        Dim paragraphIndex As Integer
        Dim iseg As Integer
        Dim textFormat As TextFormat
        Dim paraType As Integer
        Dim numberingtype As Integer
        Dim startas As Integer
        Dim format As Integer
        Dim numtype As Integer
        Dim numParagraphs As Integer
        Dim Text As String
 
 
        swModel = swApp.ActiveDoc
        swSelMgr = swModel.SelectionManager
 
        If swSelMgr.GetSelectedObjectCount > 0 Then
 
            swAnnObj = swSelMgr.GetSelectedObject6(1, -1)
            swAnn = swAnnObj.GetAnnotation()
            paragraphs = swAnn.GetParagraphs
 
            numParagraphs = paragraphs.count
            Debug.Print("Number of paragraphs = " & numParagraphs)
            Debug.Print("")
 
            For paragraphIndex = 0 To numParagraphs - 1
 
                paragraphs.CurrentParagraph = paragraphIndex
                Debug.Print("paragraph(" & paragraphIndex & "): ")
                Debug.Print(paragraphs.GetText(True))
 
                If paragraphIndex = 0 Then
                    paragraphs.SetFormatting(0.0011, 0.0012)
                Else
                    paragraphs.SetFormatting(0.0021, 0.0022)
                End If
 
                paragraphs.GetBulletsAndNumbering(paraType, numberingtype, startas, numtype, format)
                Debug.Print("Paragraph list type as defined in swParagraphType_e: " & paraType)
                If paraType = 1 Then
                    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)
                End If
 
                numSegs = paragraphs.GetTextSegmentCount
                Debug.Print("Text segment count: " & numSegs)
 
                For iseg = 0 To numSegs - 1
                    Text = paragraphs.GetTextSegmentText(iseg)
                    Debug.Print("segment(" & iseg & "): " & Text)
 
                    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)
 
                Next
 
                paragraphs.UpdateParagraph()
 
            Next
 
            swModel.GraphicsRedraw2()
 
        End If
 
    End Sub
 
 
 
    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    Public swApp As SldWorks
 
 
End Class
 

 

 



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 (VB.NET)
*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) 2019 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.