Hide Table of Contents

Get, Set, And Remove Tracking IDs On Body (VBA)

This example shows how to get, set, and remove tracking IDs on a body. Tracking IDs reliably associate application-specific data across modeling operations.

'------------------------------------------

' Preconditions: Part document with a single part is open.

'                The selected body has not been assigned any

'                tracking IDs.

'

' Directions:     Run the macro once, and the

'                 the selected body is assigned

'                 a tracking ID of 12. Run

'                 the macro again, and the selected body

'                 is assigned tracking ID of 16. The

'                 the tracking ID is then deleted from the

'                 body.

'

' Postconditions: None

'------------------------------------------

Option Explicit

 

Sub main()

 

    Dim swApp               As SldWorks.SldWorks

    Dim swModel             As SldWorks.ModelDoc2

    Dim swModelExtn         As ModelDocExtension

    Dim swSelMgr            As SldWorks.SelectionMgr

    Dim swBody              As SldWorks.Body2

    Dim Cookies             As Long

    Dim vTrackingIDs        As Variant

    Dim TrackingID          As Long

    Dim bRebuild            As Boolean

 

    Set swApp = CreateObject("SldWorks.Application")

    

    Cookies = swApp.RegisterTrackingDefinition("Tracking_API")

    If (Cookies = -1) Then

        End  ' No valid cookies found

    End If

    

    Stop

    

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager

    

    Stop ' Select body in Bodies folder

        

    Set swBody = swSelMgr.GetSelectedObject6(1, -1)

 

    Debug.Print "---------------------------------"

    Dim NbrTrackingIds As Long

    NbrTrackingIds = swBody.GetTrackingIDsCount(Cookies)

    Debug.Print "Body Tracking IDs:"

    If (NbrTrackingIds = 0) Then

    

        Debug.Print "  No tracking IDs"

        Debug.Print "    Setting tracking ID..."

        Debug.Print "      SetTrackingID Result (if 0, then call successful): " & swBody.SetTrackingID(Cookies, 12)

        Debug.Print "      GetTrackingIDs Result (if 0, then call successful): " & swBody.GetTrackingIDs(Cookies, vTrackingIDs)

        Debug.Print "      Tracking ID after SetTrackingID call : " & vTrackingIDs(0)

        End

     

    Else

    

        Debug.Print "  Tracking IDs exist..."

        Debug.Print "    Getting tracking ID..."

        Debug.Print "      GetTrackingIDs Result (if 0, then call successful): " & swBody.GetTrackingIDs(Cookies, vTrackingIDs)

        Debug.Print "      Tracking ID before SetTracingID call : " & vTrackingIDs(0)

        

        Debug.Print " "

        Debug.Print "      SetTrackingID Result (if 0, then call successful): " & swBody.SetTrackingID(Cookies, 16)

        Debug.Print "      GetTrackingIDs Result (if 0, then call successful): " & swBody.GetTrackingIDs(Cookies, vTrackingIDs)

        Debug.Print "      Tracking ID after SetTrackingID call: " & vTrackingIDs(0)

        Debug.Print " "

        Debug.Print "      Remove Tracking ID..."

        Debug.Print "        RemoveTrackingID Result (if 0, then call successful): " & swBody.RemoveTrackingID(Cookies)

        Debug.Print "        Number of tracking IDs on this body: " & swBody.GetTrackingIDsCount(Cookies)

        

        Debug.Print "---------------------------------"

        

   End If

   

End Sub



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, Set, And Remove Tracking IDs On Body (VBA)
*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.