Return Box Extents Example (C++ Dispatch)
This example shows how to return the box extents
of assembly components.
NOTE:
There is no checking to see if the components are suppressed.
void GetComponentExtents()
{
LPDISPATCH pDispatch;
IModelDoc ModelDoc;
IConfiguration Configuration;
IComponent RootComponent;
VARIANT varChildren;
SafeArray* psaChildren;
VARIANT varBox;
SafeArray* psaBox;
IComponent Child;
long i, nChildren;
double extent[6];
double value;
long j;
pDispatch = GetSOLIDWORKS()->GetActiveDoc();
ModelDoc.AttachDispatch(pDispatch);
if ( ModelDoc.GetType()
== swDocASSEMBLY )
{
if ( (pDispatch = ModelDoc.GetActiveConfiguration())
!= NULL )
{
Configuration.AttachDispatch(pDispatch);
if ( (pDispatch = Configuration.GetRootComponent()) != NULL )
{
RootComponent.AttachDispatch(pDispatch);
varChildren = RootComponent.GetChildren();
psaChildren = V_ARRAY(&varChildren);
SafeArrayGetUBound(psaChildren,
1, &nChildren);
for ( i=0; i<=nChildren; i++
) // Note Ubound 0 is 1 child
{
SafeArrayGetElement(psaChildren,
&i, &pDispatch);
Child.AttachDispatch(pDispatch);
varBox = Child.GetBox(FALSE,
FALSE);
psaBox = V_ARRAY(&varBox);
SafeArrayLock(psaBox);
for ( j=0; j<6; j++ )
{
SafeArrayGetElement(psaBox,
&j, (VOID *)(&(value)));
extent[j] = value;
}
SafeArrayUnlock(psaBox);
SafeArrayDestroy(psaBox);
Child.ReleaseDispatch();
}
SafeArrayDestroy(psaChildren);
}
}
}
return;
}