This example shows how to create a callout that is independent of a
selection.
//---------------------------------------------------------------------------
// Preconditions:
// 1. Document is open in SolidWorks.
// 2. Right-click the project in Project Explorer, select Add
Reference,
//
browse to <SolidWorks_install_dir>\api\redist\CLR2,
//
and select SolidWorks.interop.swpublished.dll.
// 3. Rename the namespace of this macro to match the name of your
C# project.
//
// Postconditions:
// 1. A callout is created with two leaders.
// 2. The callout label does not display a colon.
// 3. The callout value is empty.
//----------------------------------------------------------------
using
System;
using
System.Collections.Generic;
using
System.Text;
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using
SolidWorks.Interop.swpublished;
using
System.Diagnostics;
namespace
CreateCallout_CSharp.csproj
{
partial
class
SolidWorksMacro
{
ModelDoc2
swModel;
ModelDocExtension
swExt;
SelectionMgr
swSelMgr;
MathUtility
mathUtil;
public
void
Main()
{
swModel = (ModelDoc2)swApp.ActiveDoc;
swExt = swModel.Extension;
swSelMgr = (SelectionMgr)swModel.SelectionManager;
mathUtil = (MathUtility)swApp.GetMathUtility();
calloutHandler
handle = new
calloutHandler();
MathPoint
mp;
double[]
vPnt = new
double[3];
vPnt[0] = 0.0;
vPnt[1] = 0.0;
vPnt[2] = 0.0;
mp = (MathPoint)mathUtil.CreatePoint(vPnt);
Callout
myCallout;
myCallout = swExt.CreateCallout(2, handle);
myCallout.set_Value(1,
"");
myCallout.set_IgnoreValue(1,
true);
myCallout.set_Label2(1,
"SldWorks API");
myCallout.SkipColon =
true;
myCallout.SetLeader(true,
true);
myCallout.SetTargetPoint(1, 0.001, 0.001, 0);
myCallout.SetTargetPoint(2, -0.001, 0.001, 0);
myCallout.Position = mp;
myCallout.set_ValueInactive(0,
true);
myCallout.TextBox =
false;
myCallout.Display(true);
}
public
SldWorks
swApp;
}
[System.Runtime.InteropServices.ComVisible(true)]
public
class
calloutHandler
: SwCalloutHandler
{
#region
ISwCalloutHandler Members
bool
ISwCalloutHandler.OnStringValueChanged(object
pManipulator, int
RowID, string
Text)
{
Debug.Print("Text:
" + Text);
Debug.Print("Row:
" + RowID.ToString());
return
true;
}
#endregion
}
}