Get Text Items in GTol Frame Example (VB.NET)
This example shows how to get each text item (for example, datum tag
text and tolerance value) in a GTol frame.
'-------------------------------------------------------------
' Preconditions:
' 1. Open a document with a GTol frame and select that
GTol frame.
' 2. Open an Immediate window.
' 3. Run the macro.
'
' Postconditions: Number of text items and values for
the selected GTol
' frame are printed to the Immediate window.
'-------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Diagnostics
Imports System
Partial Public Class SolidWorksMacro
Public
Sub Main()
Dim
swModel As ModelDoc2
Dim
swModelDocExt As ModelDocExtension
Dim
swSelMgr As SelectionMgr
Dim
swGtol As Gtol
swModel
= DirectCast(swApp.ActiveDoc,
ModelDoc2)
swModelDocExt
= DirectCast(swModel.Extension,
ModelDocExtension)
swSelMgr
= DirectCast(swModel.SelectionManager,
SelectionMgr)
swGtol
= DirectCast(swSelMgr.GetSelectedObject6(1,
-1), Gtol)
Debug.Print("GetTextCount
= " & swGtol.GetTextCount().ToString())
For
idx As Integer = 0 To swGtol.GetTextCount()
- 1
Debug.Print(("GetTextAtIndex("
& idx.ToString() & ") = ") + swGtol.GetTextAtIndex(idx))
Next
Debug.Print("GetFrameCount
= " & swGtol.GetFrameCount().ToString())
For
idx As Integer = 1 To swGtol.GetFrameCount()
Dim
myParams As [Object]
myParams
= swGtol.GetFrameValues(CShort(idx))
If
myParams IsNot Nothing Then
Dim
myParamArray As Array = DirectCast(myParams, Array)
Debug.Print(((((("GetFrameValues("
& idx.ToString() & ") = ") + myParamArray.GetValue(0)
& ",") + myParamArray.GetValue(1) & ",") +
myParamArray.GetValue(2) & ",") + myParamArray.GetValue(3)
& ",") + myParamArray.GetValue(4))
End
If
Next
End
Sub
'''
<summary>
'''
The SldWorks swApp variable is pre-assigned for you.
'''
</summary>
Public
swApp As SldWorks
End Class