Hide Table of Contents

Get Annotation Object Example (C#)

This example shows how to obtain the annotation object for the selected annotation symbol.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Open a model document that contains an annotation symbol.
// 2. Select the annotation symbol.
//
// Postconditions: The annotation object for the selected symbol is obtained.
// ---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;

namespace GetAnnotationObject_CSharp.csproj
{
    
partial class SolidWorksMacro
    {

        
ModelDoc2 Part;
        
SelectionMgr SelMgr;
        
object AnnoObject;
        
WeldSymbol aWeldSymbol;
        
WeldBead aWeldBead;
        
TableAnnotation aTableAnno;
        
SFSymbol anSFSymbol;
        
RevisionCloud aRevisionCloud;
        
Note aNote;
        
MultiJogLeader aLeader;
        
Gtol aGtol;
        
DowelSymbol aDowelSym;
        
DisplayDimension aDispDim;
        
DatumTargetSym aDatTarSym;
        
DatumTag aDatumTag;
        
DatumOrigin aDatumOrigin;
        
CustomSymbol aCustomSymbol;
        
CenterMark aCenterMark;
        
CenterLine aCenterLine;
        
CThread aCThread;

        
Annotation Anno;

        
public void Main()
        {
            Part = (
ModelDoc2)swApp.ActiveDoc;
            SelMgr = (
SelectionMgr)Part.SelectionManager;
            AnnoObject = SelMgr.GetSelectedObject6(1, -1);

            
switch (SelMgr.GetSelectedObjectType3(1, -1))
            {
                
case (int)swSelectType_e.swSelWELDS:
                    
Debug.Print("Selected annotation is a WeldSymbol.");
                    aWeldSymbol = (
WeldSymbol)AnnoObject;
                    Anno = (
Annotation)aWeldSymbol.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelWELDBEADS:
                    
Debug.Print("Selected annotation is a WeldBead.");
                    aWeldBead = (
WeldBead)AnnoObject;
                    Anno = (
Annotation)aWeldBead.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelANNOTATIONTABLES:
                    
Debug.Print("Selected annotation is a TableAnnotation.");
                    aTableAnno = (
TableAnnotation)AnnoObject;
                    Anno = (
Annotation)aTableAnno.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelSFSYMBOLS:
                    
Debug.Print("Selected annotation is an SFSymbol.");
                    anSFSymbol = (
SFSymbol)AnnoObject;
                    Anno = (
Annotation)anSFSymbol.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelREVISIONCLOUDS:
                    
Debug.Print("Selected annotation is a RevisionCloud.");
                    aRevisionCloud = (
RevisionCloud)AnnoObject;
                    Anno = (
Annotation)aRevisionCloud.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelNOTES:
                    
Debug.Print("Selected annotation is a Note.");
                    aNote = (
Note)AnnoObject;
                    Anno = (
Annotation)aNote.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelLEADERS:
                    
Debug.Print("Selected annotation is a Leader.");
                    aLeader = (
MultiJogLeader)AnnoObject;
                    Anno = (
Annotation)aLeader.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelGTOLS:
                    
Debug.Print("Selected annotation is a Gtol.");
                    aGtol = (
Gtol)AnnoObject;
                    Anno = (
Annotation)aGtol.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelDOWELSYMS:
                    
Debug.Print("Selected annotation is a DowelSymbol.");
                    aDowelSym = (
DowelSymbol)AnnoObject;
                    Anno = (
Annotation)aDowelSym.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelDIMENSIONS:
                    
Debug.Print("Selected annotation is a DisplayDimension.");
                    aDispDim = (
DisplayDimension)AnnoObject;
                    Anno = (
Annotation)aDispDim.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelDTMTARGS:
                    
Debug.Print("Selected annotation is a DatumTargetSym.");
                    aDatTarSym = (
DatumTargetSym)AnnoObject;
                    Anno = (
Annotation)aDatTarSym.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelDATUMTAGS:
                    
Debug.Print("Selected annotation is a DatumTag.");
                    aDatumTag = (
DatumTag)AnnoObject;
                    Anno = (
Annotation)aDatumTag.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelDATUMPOINTS:
                    
Debug.Print("Selected annotation is a DatumOrigin.");
                    aDatumOrigin = (
DatumOrigin)AnnoObject;
                    Anno = (
Annotation)aDatumOrigin.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelCUSTOMSYMBOLS:
                    
Debug.Print("Selected annotation is a CustomSymbol.");
                    aCustomSymbol = (
CustomSymbol)AnnoObject;
                    Anno = (
Annotation)aCustomSymbol.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelCTHREADS:
                    
Debug.Print("Selected annotation is a CThread.");
                    aCThread = (
CThread)AnnoObject;
                    Anno = (
Annotation)aCThread.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelCENTERMARKSYMS:
                    
Debug.Print("Selected annotation is a CenterMark.");
                    aCenterMark = (
CenterMark)AnnoObject;
                    Anno = (
Annotation)aCenterMark.GetAnnotation();
                    
break;
                
case (int)swSelectType_e.swSelCENTERLINES:
                    
Debug.Print("Selected annotation is a CenterLine.");
                    aCenterLine = (
CenterLine)AnnoObject;
                    Anno = (
Annotation)aCenterLine.GetAnnotation();
                    
break;
            }

            
Debug.Print("Annotation: " + Anno.GetName());

        }



        
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 Annotation Object 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) 2018 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.