Set Text in Datum Tags and GTols Example (C#)
This example shows how to set the text in datum tags and geometric
tolerances.
//----------------------------------------------------------------------------
// Preconditions:
// 1. Open a drawing that contains one view, a datum feature,
// and a geometric tolerance.
// 2. Ensure that the namespace matches the name of your C# project.
//
// Postconditions: Each annotation is appended with the specified text.
//
---------------------------------------------------------------------------
using
Microsoft.VisualBasic;
using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Data;
using
System.Diagnostics;
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
namespace
SetText_CSharp.csproj
{
partial
class
SolidWorksMacro
{
ModelDoc2
swModel;
ModelView
swModelView;
DrawingDoc
swDraw;
View
swView;
Gtol
swDispGtol;
Double[]
rect = null;
DatumTag
swDatumTag;
public
void
Main()
{
swModel = (ModelDoc2)swApp.ActiveDoc;
swModelView = (ModelView)swModel.ActiveView;
swDraw = (DrawingDoc)swModel;
swView = (View)swDraw.GetFirstView();
//sheet
swView = (View)swView.GetNextView();
swDispGtol = (Gtol)swView.GetFirstGTOL();
swDispGtol.SetText((int)swGTolTextParts_e.swGTolTextPrefix,
"prefix");
swDispGtol.SetText((int)swGTolTextParts_e.swGTolTextSuffix,
"suffix");
swDispGtol.SetText((int)swGTolTextParts_e.swGTolTextCalloutAbove,
"above");
swDispGtol.SetText((int)swGTolTextParts_e.swGTolTextCalloutBelow,
"below");
swDatumTag = (DatumTag)swView.GetFirstDatumTag();
swDatumTag.SetText((int)swDatumTagTextParts_e.swDatumTagTextPrefix,
"prefix");
swDatumTag.SetText((int)swDatumTagTextParts_e.swDatumTagTextSuffix,
"suffix");
swDatumTag.SetText((int)swDatumTagTextParts_e.swDatumTagTextCalloutAbove,
"above");
swDatumTag.SetText((int)swDatumTagTextParts_e.swDatumTagTextCalloutBelow,
"below");
swModelView.GraphicsRedraw(rect);
}
public
SldWorks
swApp;
}
}