Code:
public void Main()
{
// Description: Inserts SketchTexts with incrementing numbers in a linear component order on a preselected surface
// Pre-Condition: A face must be selected // Configuration Parameters:
// Hint: Depending on coordinate system the values might have to be negative!
// Offset referenced to sketch origin in mm
Double Offset_x = 0.01;
Double Offset_y = 0.01;
Double Offset_z = 0.0;
// Increment between labels in mm
Double Inc_x = 0.01;
Double Inc_y = 0.0;
Double Inc_z = 0.0;
// Sets the direction of the text in mm
Double Length_x = 0.005;
Double Length_y = 0.005;
Double Length_z = 0.000;
// Number to start with and amount of numbers
Int32 first_num = 1;
Int32 count_num = 6;
// Text Font Type
double TextHeight = 0.005;
bool TextBold = true;
string TextFont = "Arial"; // Calibri or Consolas
Int32 i;
ModelDoc2 swDoc = null;
ModelDocExtension swExt = null;
SelectionMgr swSelMgr = null;
SketchManager swSketchMgr = null;
SketchSegment swSketchSeg;
SketchText swSketchText;
TextFormat swTextFormat;
swDoc = ((ModelDoc2)(swApp.ActiveDoc));
swExt = swDoc.Extension;
swSelMgr = swDoc.SelectionManager as SelectionMgr;
swSketchMgr = swDoc.SketchManager;
swSketchMgr.InsertSketch(true);
swDoc.ClearSelection2(true);
for (i = first_num; i <= first_num+count_num-1; i++)
{
// Create construction line, to align the text
swDoc.CreateCenterLineVB(Inc_x * (i - first_num) + Offset_x, Inc_y * (i - first_num) + Offset_y, Inc_z * (i - first_num) + Offset_z,
Inc_x * (i - first_num) + Offset_x + Length_x, Inc_y * (i - first_num) + Offset_y + Length_y,
Inc_z * (i - first_num) + Offset_z + Length_z);
// Select the created line
swSketchSeg = (SketchSegment)swSelMgr.GetSelectedObject6(1, -1);
SelectData swSelData = swSelMgr.CreateSelectData();
swSelData.Mark = 1;
swSketchSeg.Select4(false, swSelData);
// Insert text counting up
swSketchText = (SketchText)swDoc.InsertSketchText(0, 0, 0, i.ToString(), 1, 0, 0, 100, 100);
// Change look of text
swTextFormat = (TextFormat)swSketchText.GetTextFormat();
swTextFormat.CharHeight = TextHeight;
swTextFormat.Bold = TextBold;
swTextFormat.TypeFaceName = TextFont;
swSketchText.SetTextFormat(false, swTextFormat);
swDoc.ClearSelection2(true);
}
}