Get Text Items in GTol Frame Example (C#)
This example shows how to get each text item (for example, datum tag
text and tolerance
value) in a GTol frame.
//-------------------------------------------------------------
// Preconditions:
// 1.
Open document with a GTol frame and select that GTol frame.
// 2.
Open the Immediate window.
// 3.
Run the macro.
//
// Postconditions: Number of text items and values for
the selected GTol
// frame are printed to the Immediate window.
//-------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Diagnostics;
using System;
namespace GetTextCountGtolCSharp.csproj
{
public
partial class SolidWorksMacro
{
public
void Main()
{
ModelDoc2
swModel;
ModelDocExtension
swModelDocExt;
SelectionMgr
swSelMgr;
Gtol
swGtol;
swModel
= (ModelDoc2)swApp.ActiveDoc;
swModelDocExt
= (ModelDocExtension)swModel.Extension;
swSelMgr
= (SelectionMgr)swModel.SelectionManager;
swGtol
= (Gtol)swSelMgr.GetSelectedObject6(1,
-1);
Debug.Print("GetTextCount
= " + swGtol.GetTextCount().ToString());
for(int
idx=0;idx < swGtol.GetTextCount();idx++)
{
Debug.Print("GetTextAtIndex("
+ idx.ToString() + ") = " + swGtol.GetTextAtIndex(idx));
}
Debug.Print("GetFrameCount
= " + swGtol.GetFrameCount().ToString());
for(int
idx=1;idx <= swGtol.GetFrameCount();idx++)
{
Object
myParams;
myParams
= swGtol.GetFrameValues((short)idx);
if
(myParams != null)
{
Array
myParamArray = (Array)myParams;
Debug.Print("GetFrameValues("
+ idx.ToString() + ") = " + myParamArray.GetValue(0) + ","
+ myParamArray.GetValue(1) + "," + myParamArray.GetValue(2)
+ "," + myParamArray.GetValue(3) + "," + myParamArray.GetValue(4));
}
}
}
///
<summary>
///
The SldWorks
swApp variable is pre-assigned for you.
///
</summary>
public
SldWorks swApp;
}
}