Set Text in Datum Tags and GTols Example (VBA)
This example shows how to set the text in datum tags and geometric
tolerances.
'----------------------------------------------------------------------------
' Preconditions:
' 1. Open a drawing that contains at least one view, a datum feature,
' and a geometric tolerance.
' 2. Open the Immediate window.
' 3. Run the macro.
'
' Postconditions:
' 1. The specified text is appended to each annotation.
' 2. Datum tag label is printed to the Immediate window.
' ---------------------------------------------------------------------------
Option Explicit
Dim swApp
As SldWorks.SldWorks
Dim swModel
As SldWorks.ModelDoc2
Dim swModelView
As SldWorks.ModelView
Dim swDraw
As SldWorks.DrawingDoc
Dim swView
As SldWorks.View
Dim swDispGtol
As SldWorks.Gtol
Dim swDatumTag
As SldWorks.DatumTag
Dim Rect
As Variant
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelView = swModel.ActiveView
Set swDraw = swModel
Set swView = swDraw.GetFirstView 'sheet
Set swView = swView.GetNextView
Set swDispGtol = swView.GetFirstGTOL
swDispGtol.SetText swGTolTextPrefix, "prefix"
swDispGtol.SetText swGTolTextSuffix, "suffix"
swDispGtol.SetText swGTolTextCalloutAbove, "above"
swDispGtol.SetText swGTolTextCalloutBelow, "below"
Set swDatumTag = swView.GetFirstDatumTag
swDatumTag.SetText swDatumTagTextPrefix, "prefix"
swDatumTag.SetText swDatumTagTextSuffix, "suffix"
swDatumTag.SetText swDatumTagTextCalloutAbove, "above"
swDatumTag.SetText swDatumTagTextCalloutBelow, "below"
Debug.Print ("Datum tag label: " & swDatumTag.GetLabel)
Set Rect = Nothing
swModelView.GraphicsRedraw (Rect)
End Sub