Hide Table of Contents

Get Annotations Arrays Example (VB.NET)

Methods added to the IView interface in SOLIDWORKS API 2009 SP1 can return arrays of each annotation type in a drawing view. This example shows how to call these methods.

'-----------------------------------------------------------------------------
' Preconditions: Verify that the specified path and template file exist.
'
' Postconditions:
' 1. Creates a part with annotations.
' 2. Click Save.
' 3. Creates a drawing with third-angle views of the part
'    and annotations.
' 4. Iterates through each annotation array and pops up message boxes
'    containing information about each annotation in the drawing views.
' 5. Click OK to close each message box.
'---------------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
 
Partial Class SolidWorksMacro
 
    Const filedir As String = "C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2016\templates\"
    Const TemplateName As String = "C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2016\templates\drawing.drwdot"
    Const TemplateSize As Long = swDwgTemplates_e.swDwgTemplateBsize
    Const PaperSize As Long = swDwgPaperSizes_e.swDwgPaperBsize
    Const ScaleNum As Double = 1.0#
    Const ScaleDenom As Double = 2.0#
    Dim swModel As ModelDoc2
    Dim swFeatMgr As FeatureManager
    Dim Response As Integer
    Dim ThirdAngle As Boolean
    Dim swDraw As DrawingDoc
    Dim swSheet As Sheet
    Dim i As Long
    Dim j As Long
    Dim retval As Boolean
    Dim swView As View
    Dim count As Long
    Dim Annotations As Object
    Dim msg As String
 
    Public Sub main()
        'Create a part
        Build_Part()

        'Create a drawing of the part
        swModel = swApp.ActiveDoc
        swDraw = swApp.NewDocument(TemplateName, PaperSize, _
                0.0#, 0.0#)
        ThirdAngle = False
        swDraw.ActivateSheet("Sheet1")
        swSheet = swDraw.GetCurrentSheet
        swSheet.SetSize(PaperSize, 0.0#, 0.0#)
        swSheet.SetScale(ScaleNum, ScaleDenom, TrueTrue)

        ' Create 3rd-angle drawing views
        ' Pop up Save As dialog
        ' Click Save in the dialog
        retval = swDraw.Create3rdAngleViews2(swModel.GetPathName)
        Dim LocX As Double
        Dim LocY As Double
        LocX = 0.2635088599471
        LocY = 0.1934578136726

        ' Create isometric drawing view
        swDraw.CreateDrawViewFromModelView3(swModel.GetPathName"*Isometric", LocX, LocY, 0)
        swDraw.ViewDisplayShaded()
        ' Insert display dimension annotations from the current model
        swDraw.InsertModelAnnotations3(0, swInsertAnnotation_e.swInsertDimensionsMarkedForDrawing, TrueTrueFalseTrue)
        ' Insert datum target symbol annotations from the current model
        swDraw.InsertModelAnnotations3(0, swInsertAnnotation_e.swInsertDatumTargets, TrueTrueFalseTrue)
        ' Insert geometric tolerance annotations from the current model
        swDraw.InsertModelAnnotations3(0, swInsertAnnotation_e.swInsertGTols, TrueTrueFalseTrue)
        ' Insert surface finish symbol annotations from the current model
        swDraw.InsertModelAnnotations3(0, swInsertAnnotation_e.swInsertSFSymbols, TrueTrueFalseTrue)
        ' Insert datum tag annotations from the current model
        swDraw.InsertModelAnnotations3(0, swInsertAnnotation_e.swInsertDatums, TrueTrueFalseTrue)
        ' Insert dowel symbol on a selected arc or circle - not applicable to this model
        'swDraw.InsertDowelSymbol
        ' Insert center line on a selected entity
        'swDraw.InsertCenterLine2
        ' Insert cosmetic thread
        'swDraw.InsertThreadCallout
        ' Insert weld symbol on the last edge selection
        'swDraw.InsertWeldSymbol
        ' Insert weld bead
        ' Insert table
        'swDraw.InsertTableAnnotation2

        swDraw.ForceRebuild3(True)

        ' Iterate through all the views on the drawing to find display dimensions
        swView = swDraw.GetFirstView
        Do While Not swView Is Nothing
            count = swView.GetDisplayDimensionCount
            Dim DisplayDimension As DisplayDimension
            Dim swDim As Dimension
            ' Iterate through all the display dimension annotations in each drawing view that has them
            If count > 0 Then
                Annotations = swView.GetDisplayDimensions
                For j = 0 To UBound(Annotations)
                    DisplayDimension = Annotations(j)
                    swDim = DisplayDimension.GetDimension
                    ' For each annotation in each drawing view, pop up a message box with the
                    ' annotation name and corresponding dimension
                    msg = "Display dimension found: " & swView.GetName2 & ":" & DisplayDimension.GetAnnotation.GetName & " = " & swDim.GetSystemValue2("") & " meters"
                    swApp.SendMsgToUser2(msg, swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk)
                Next j
            End If
            swView = swView.GetNextView
        Loop
        ' Iterate through all the views on the drawing to find datum target symbols
        swView = swDraw.GetFirstView
        Do While Not swView Is Nothing
            count = swView.GetDatumTargetSymCount
            Dim dtsymbol As DatumTargetSym
            ' Iterate through all the datum target symbol annotations in each drawing view that has them
            If count > 0 Then
                Annotations = swView.GetDatumTargetSyms
                For j = 0 To UBound(Annotations)
                    dtsymbol = Annotations(j)
                    ' For each annotation in each drawing view, pop up a message box with the
                    ' annotation name and name of each datum target symbol found
                    msg = "Datum target symbol found: " & swView.GetName2 & ":" & dtsymbol.GetAnnotation.GetName
                    swApp.SendMsgToUser2(msg, swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk)
                Next j
            End If
            swView = swView.GetNextView
        Loop
        ' Iterate through all the views on the drawing to find surface finish symbols
        swView = swDraw.GetFirstView
        Do While Not swView Is Nothing
            count = swView.GetSFSymbolCount
            Dim sfsymbol As SFSymbol
            ' Iterate through all the surface finish symbol annotations in each drawing view that has them
            If count > 0 Then
                Annotations = swView.GetSFSymbols
                For j = 0 To UBound(Annotations)
                    SFSymbol = Annotations(j)
                    ' For each annotation in each drawing view, pop up a message box with the
                    ' annotation name and name of each surface finish symbol found
                    msg = "Surface finish symbol found: " & swView.GetName2 & ":" & SFSymbol.GetAnnotation.GetName
                    swApp.SendMsgToUser2(msg, swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk)
                Next j
            End If
            swView = swView.GetNextView
        Loop
        ' Iterate through all the views on the drawing to find datum tags
        swView = swDraw.GetFirstView
        Do While Not swView Is Nothing
            count = swView.GetDatumTagCount
            Dim dTag As DatumTag
            ' Iterate through all the datum tags in each drawing view that has them
            If count > 0 Then
                Annotations = swView.GetDatumTags
                For j = 0 To UBound(Annotations)
                    dTag = Annotations(j)
                    ' For each annotation in each drawing view, pop up a message box with the
                    ' annotation name and name of each datum tag found
                    msg = "Datum tag found: " & swView.GetName2 & ":" & dTag.GetAnnotation.GetName
                    swApp.SendMsgToUser2(msg, swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk)
                Next j
            End If
            swView = swView.GetNextView
        Loop
        ' Iterate through all the views on the drawing to find geometric tolerances
        swView = swDraw.GetFirstView
        Do While Not swView Is Nothing
            count = swView.GetGTolCount
            Dim gtol As Gtol
            ' Iterate through all the geometric tolerance symbols in each drawing view that has them
            If count > 0 Then
                Annotations = swView.GetGTols
                For j = 0 To UBound(Annotations)
                    Gtol = Annotations(j)
                    ' For each annotation in each drawing view, pop up a message box with the
                    ' annotation name and name of each geometric tolerance found
                    msg = "Geometric tolerance symbol found: " & swView.GetName2 & ":" & Gtol.GetAnnotation.GetName
                    swApp.SendMsgToUser2(msg, swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk)
                Next j
            End If
            swView = swView.GetNextView
        Loop
        ' In a similar fashion:
        ' Get other annotations on the drawing, if they exist
        ' Iterate through all the views on the drawing
        ' Get the annotation count, and if greater than zero, get the annotation array
        ' Iterate on each array, and set an annotation object to each array member:
        ' Annotations = swView.GetDowelSymbols
        ' Annotations = swView.GetMultiJogLeaders
        ' Annotations = swView.GetDatumOrigins
        ' Annotations = swView.GetCenterLines
        ' Annotations = swView.GetCThreads
        ' Annotations = swView.GetWeldSymbols
        ' Annotations = swView.GetWeldBeads
        ' Annotations = swView.GetTableAnnotations
        swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swInputDimValOnCreate, True)
        swModel.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayAnnotations, False)

    End Sub

    Private Sub Build_Part()
        ' Builds a part with these annotations:
        ' display dimensions, geometric tolerance symbol, surface finish symbol, 
        ' datum tag symbol, and datum target symbol
        swModel = swApp.NewDocument(filedir + "part.prtdot", 0, 0.0#, 0.0#)
        swModel.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swUnitsLinear, swLengthUnit_e.swMETER)
        swModel.SetUserPreferenceDoubleValue(swUserPreferenceDoubleValue_e.swMaterialPropertyDensity, 7800)
        swModel.SetUserPreferenceStringValue(swUserPreferenceStringValue_e.swMaterialPropertyCrosshatchPattern, "ISO (Steel)")
        swModel.SketchManager.InsertSketch(False)
        Dim Height As Double
        Dim Width As Double
        Height = 0.05
        Width = 0.05
        swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swInputDimValOnCreate, False)
        swModel.SketchManager.CreateLine(0.01, 0.01, 0, 0.01, 0.01 + Height, 0)
        swModel.ViewZoomtofit2()
        ' Add display dimension to line
        swModel.AddDimension2(0, 0.01 + Height / 2, 0)
        ' Add geometric tolerance to line
        swModel.InsertGtol()
        swModel.SketchManager.CreateLine(0.01, 0.01, 0, 0.01 + Width, 0.01, 0)
        swModel.ViewZoomtofit2()
        ' Add display dimension
        swModel.AddDimension2(0.01 + Width / 2, 0, 0)
        ' Add surface finish symbol to line
        swModel.Extension.InsertSurfaceFinishSymbol3(swSFSymType_e.swSFBasic, swLeaderStyle_e.swSTRAIGHT, 0.01, 0.01, 0.01, swSFLaySym_e.swSFCircular, swArrowStyle_e.swDOT_ARROWHEAD, """""""""""""")
        swModel.SketchManager.CreateLine(0, 0, 0, 0, 0.01, 0).ConstructionGeometry = True
        swModel.ClearSelection2(True)
        swModel.ViewZoomtofit2()
        Dim Thick As Double
        Thick = 0.05
        Dim Depth As Double
        Depth = 0.05
        swFeatMgr = swModel.FeatureManager
        swFeatMgr.FeatureExtrusionThin2(TrueFalseTrue, 0, 0, Depth, 0, FalseFalseFalseFalse, 0, 0, FalseFalseFalseFalseFalse, Thick, 0, 0, 0, 0, FalseFalseFalseFalse, swStartConditions_e.swStartSketchPlane, 0.0#, False)
        swModel.ViewZoomtofit2()
        swModel.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayAnnotations, True)
        swModel.ShowNamedView2("Isometric", 7)
        swModel.ViewZoomtofit2()
        ' Add datum tag to line
        retval = swModel.Extension.SelectByID2("""EDGE", 0.06001738353251, -0.01284975502705, -0.05001738353241, False, 0, Nothing, 0)
        Dim dTag As DatumTag
        dTag = swModel.InsertDatumTag2
        ' Add datum target symbol to line
        retval = swModel.Extension.SelectByID2("""EDGE", 0.06001738353251, -0.01284975502705, -0.05001738353241, False, 0, Nothing, 0)
        Dim myDatumTarget As Object
        myDatumTarget = swModel.Extension.InsertDatumTargetSymbol2("""""", 0, False, 0.03, 0.03, """"True, 12, 0, FalseTrueTrue)

    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 Annotations Arrays 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) 2017 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.