Welcome
Getting Started
Overview
Types of SolidWorks API Applications
SolidWorks API Object Model and Class Hierarchy
Programming with the SolidWorks API
Add-ins
API Dependent on SolidWorks Being Visible
Arrays
Attributes Imported from ACIS SAT Files
Bitmasks
Block Definitions and Block Instances
Bodies in Body Folders
BOOL and VARIANT_BOOL
Bounding Box and Note Text
COM vs. Dispatch
CommandManager and CommandGroups
Components, Configurations, and Suppression States
Compound Note
ComVisibleAttribute in VSTA macros
Controls, Visual Basic 6.0, and Windows XP
Double Arrays and Integer Pairs
Drawing Views and Model Entities
Early and Late Binding
Events
Features of Components
Helper Functions
Hole Wizard Features and Objects
IDispatch Object Arrays as Input in .NET
Implementation Guidelines
Import and Export File Options
In-process Methods
Instantiate ActiveX Controls as Tabs
Interface Pointers
Keystrokes and Accelerator Keys
Library Features and Objects
Lightweight Components
Line Attributes for View::GetPolyLinesAndCurves
Line Weights
Long vs. Integer
Macro Features
Manipulators
Mass Properties
Multibody Parts
Option Explicit Statement
Partition Rollback and API Handles
Persistent Reference IDs
Presentation Transforms
PropertyManager Pages
.NET Interop Assemblies
Quick Tips and Bubble ToolTips
Return Values
SafeArrays
Selection Criteria
Selection Lists
Selections that Define Features
Setup Project to Distribute SolidWorks Add-in
Smart Pointers
SolidWorks Objects
Sorting Tables
SQLite
STL Container Classes and Smart Pointers
Suspend Automatic Rebuilds
swdisp.cpp and swdisp.h Files
System Options and Document Properties
Tessellation and Edges
Tracking IDs
Type Libraries
VBA and SolidWorks x64
Units
Unmanaged C+ and C++/CLI Code Differences
Examples and Projects
SolidWorks API Help
FeatureWorks API Help
SolidWorks Document Manager API Help
eDrawings API Help
SolidWorks Routing API Help
SolidWorks Simulation API Help
SolidWorks Utilities API Help
SolidWorks Workgroup PDM API Help
Hide Table of Contents Show Table of Contents

In-process Methods

The SolidWorks API provides two types of methods for interfaces that get or set arrays:

  • in-process

  • global

For example, IView contains these methods:

Both types of methods perform the same work, but each is more or less appropriate for a given language and application.

In-process methods typically begin with the letter I and get or set pointers to arrays that only unmanaged C++ applications can handle. The in-process companion methods (i.e., similarly named methods that do not begin with the letter I) are more globally useful both inside a process and across processes and return predictable results for all of the SolidWorks supported languages.

In VBA, VB.NET, C#, and C++/CLI (also called managed C++), global methods typically get or set a VARIANT or object that the programmer can iterate as an array. In unmanaged C++, these methods get or set a pointer to a Dispatch object that should be cast as a SafeDISPATCHArray, which is a VARIANT helper class that was defined in a template class.

For more information about using smart pointers with container classes, see STL Container Classes and Smart Pointers.

The following unmanaged C++ code example uses the flag, useInProcessMethod, to switch between usages of the in-process method, IView::IGetCThreads, and the more global method, IView::GetCThreads:

 

STDMETHODIMP CCTDemo::ToolbarCallback0(void)

{

            CComPtr<IModelDoc2> swModel;

            iSwApp->get_IActiveDoc2(&swModel);

            CComQIPtr<IDrawingDoc> swDraw = swModel;

            if (swDraw)

            {

            

                  CComPtr<IView> viewSheet;

                  swDraw->IGetFirstView(&viewSheet);

                  CComPtr<IView> viewFirst;

                  viewSheet->IGetNextView(&viewFirst);

            

                  if (viewFirst)

                  {

                        bool useInProcessMethod = false;

                        

                        ///Using IGetCThreads

                        if (useInProcessMethod)

                        {

                              long count;

                              viewFirst->GetCThreadCount(&count);

                              if (count > 0)

                              {

                                    CString msg;

                                    msg.Format(_T("Number of threads:  %d"), count);

                                    long res0;

                                    iSwApp->SendMsgToUser2(CComBSTR(msg),0,0,&res0);

                                    ICThread** rawThreadArray = new ICThread*[count];

            

                                    viewFirst->IGetCThreads(count, rawThreadArray);

                                    CComPtr<INote> threadCalloutNote;

                                    rawThreadArray[0]->get_ThreadCallout(&threadCalloutNote);

                                    if (threadCalloutNote)

                                    {

                                          CComBSTR noteText;

                                          threadCalloutNote->GetText(&noteText);

                                          CComBSTR msg(_T("Cosmetic thread callout text: "));

                                          if (noteText != NULL)

                                                msg.Append(noteText);

                                          long res1;

                                          iSwApp->SendMsgToUser2(CComBSTR(msg),0,0,&res1);

                                    }

                                    //Be sure to release your resources when you are finished.

                                    for (int arrayIndex = 0; arrayIndex != count; ++arrayIndex)

                                          rawThreadArray[arrayIndex]->Release();

                                    delete[] rawThreadArray;

                              }

                              else

                              {

                                    long res2;

                                    iSwApp->SendMsgToUser2(CComBSTR(_T("No threads in drawing view.")),0,0,&res2);

                              }

                        }

                        

                        ///Using GetCThreads

                        ///Note the use of SafeDISPATCHArray. This is a VARIANT helper class

                        ///that was defined in a template class.

                        else

                        {

                              long count;

                              viewFirst->GetCThreadCount(&count);

                              if (count > 0)

                              {

                                    VARIANT vThreads;

                                    VariantInit(&vThreads);

                                    viewFirst->GetCThreads(&vThreads);

                                    SafeDISPATCHArray variantThreadArray(&vThreads);

                              

                                    CComQIPtr<ICThread> swThread = variantThreadArray[0];

                                    CComPtr<INote> threadCalloutNote;

                                    swThread->get_ThreadCallout(&threadCalloutNote);

                                    if (threadCalloutNote)

                                    {

                                          CComBSTR noteText;

                                          threadCalloutNote->GetText(&noteText);

                                          CComBSTR msg(_T("Cosmetic thread callout text: "));

                                          if (noteText != NULL)

                                                msg.Append(noteText);

                                          long res1;

                                          iSwApp->SendMsgToUser2(CComBSTR(msg),0,0,&res1);

                                    }

                                    //Be sure to release your resources when you are finished.

                                    for (int arrayIndex = 0; arrayIndex != count; ++arrayIndex)

                                          variantThreadArray[arrayIndex]->Release();

                              }

                              else

                              {

                                    long res2;

                                    iSwApp->SendMsgToUser2(CComBSTR(_T("No threads in drawing view.")),0,0,&res2);

                              }

                        }

                  }

                  else

                  {

                        long res3;

                        iSwApp->SendMsgToUser2(CComBSTR(_T("No drawing view.")),0,0,&res3);

                  }

            

            

            

            }

            else

            {

                  long res4;

                  iSwApp->SendMsgToUser2(CComBSTR(_T("No drawing.")),0,0,&res4);

            }

            

      

      return S_OK;

}

 

A VBA programmer might hope that IView::IGetCThreads returns an array. But this in-process method returns an array only in unmanaged C++. In VBA, this method returns only one strongly typed object, CThread, as follows:

 

Dim instance As IView

Dim numCThread As Integer

Dim value As CThread

 

value = instance.IGetCThreads(numCThread)

 

To reliably obtain the complete array of CThreads, a VBA programmer (and C# or C++/CLI programmer) should always call the more global method (e.g., IView::GetCThreads), which returns a VARIANT in VBA that can be iterated as an array of CThreads.  For example:

 

Option Explicit

Dim instance As IView

Dim vObj As Variant

Dim CurrCT As SldWorks.Annotation

Dim value As Variant

 

Sub main()

 

Set swApp = Application.SldWorks

Set swModel = swApp.GetFirstDocument

Set instance = swModel.ActiveView

 

value = instance.GetCThreads

If Not value Is Nothing Then

        For i = 0 to UBound(value)

            Set CurrCT = value(i)

            Debug.Print CurrCT.GetName

        Next i

End If

End Sub



Related SolidWorks Forum Content

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:   In-process Methods
*Comment:  
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) 2012 SP05

The search functionality within the web help is in a beta test phase and you may experience periodic delays or interruptions in its performance. These are the normal and ordinary features of a beta test and shall not under any circumstances give rise to any liability on the part of DS SolidWorks or its licensors. The topics within the Web-based help are not beta topics; they document API Help (English only) 2012 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.