Get Areas of MidSurface Faces (C#)
This example shows how to get the areas of mid-surface faces.
//--------------------------------------------------------------------------
// Preconditions: Part document open, and
// part
contains a mid-surface feature,
// which
is selected.
//
// Postconditions: None.
//--------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace FaceArea.csproj
{
public
partial class SolidWorksMacro
{
ModelDoc2
swModel;
SelectionMgr
swSelMgr;
MidSurface3
swMidSurf;
Feature
swFeat;
Face2
myFace;
object[]
faces;
int
count;
int
index;
double
area;
public
void Main()
{
swModel
= swApp.ActiveDoc as ModelDoc2;
swSelMgr
= swModel.SelectionManager as
SelectionMgr;
swFeat
= (Feature)swSelMgr.GetSelectedObject6(1,
-1);
swMidSurf
= (MidSurface3)swFeat.GetSpecificFeature2();
count
= swMidSurf.GetFaceCount();
Debug.Print
("Number of faces for midsurface feature: " + count);
faces
= (object[])swMidSurf.GetFaces();
for
(index = 0; index < count; index++)
{
myFace
= faces[index] as Face2;
area
= myFace.GetArea();
Debug.Print
("Area of face of midsurface feature: " + area);
}
}
///
<summary>
///
The SldWorks
swApp variable is pre-assigned for you.
///
</summary>
public
SldWorks swApp;
}
}