Get Solid-fill Hatch Information Example (C#)
This example shows how to get information about solid-fill hatches in
a detail view in the current drawing sheet.
//-------------------------------------------------------------------------
// Preconditions:
// (1) Open a SolidWorks drawing that has a
// solid-fill
hatch in a detail view.
// (2) Run the macro and examine the Immediate window
// and
drawing document to verify the results.
//
// Postconditions: None
//----------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
namespace SolidFillHatchesView_CSharp.csproj
{
partial
class SolidWorksMacro
{
public
void Main()
{
ModelDoc2
swModel = default(ModelDoc2);
DrawingDoc
swDrawing = default(DrawingDoc);
Sheet
swSheet = default(Sheet);
View
swView = default(View);
long
nbrSolidFillHatches = 0;
int
ArraySize = 0;
long
i = 0;
Double[]
boundaryData = new Double[4];
swModel
= (ModelDoc2)swApp.ActiveDoc;
swDrawing
= (DrawingDoc)swModel;
//
Get drawing sheet
swSheet
= (Sheet)swDrawing.GetCurrentSheet();
//
Get name of drawing sheet
Debug.Print("
Number of drawing views on drawing sheet: " + swDrawing.GetViewCount());
//
First view is the current drawing sheet
swView
= (View)swDrawing.GetFirstView();
Debug.Print("
First drawing view is the current drawing sheet, so...");
//
Get first drawing view on drawing sheet
swView
= (View)swView.GetNextView();
nbrSolidFillHatches
= 0;
ArraySize
= 0;
while
((swView != null))
{
Debug.Print("
Get next drawing view on drawing sheet...");
Debug.Print("
View name: " + swView.Name);
nbrSolidFillHatches
= swView.GetSolidHatchCount(out
ArraySize);
Debug.Print("
Number of solid-fill hatches in this view: " + nbrSolidFillHatches);
Debug.Print("
Size of array for the boundary data for the solid-fill hatch(es): "
+ ArraySize);
if
(ArraySize > 0)
{
boundaryData
= (Double[])swView.GetSolidHatchInfo();
Debug.Print("
Is the loop an outer loop (first)? " + boundaryData[0]);
Debug.Print("
Number of polylines in loop: " + boundaryData[1]);
Debug.Print("
Type ( 0 = polyline; 1 = arc or circle): " + boundaryData[2]);
Debug.Print("
Size of geometric data array (will be 0 if Type = 0): " + boundaryData[3]);
Debug.Print("
See IView::GetSolidHatchInfo's API Help topic for descriptions of these
array elements: ");
for
(i = 4; i <= ArraySize - 1; i++)
{
Debug.Print("
Boundary data, array element " + i + ": " + boundaryData[i]);
}
}
//
Get next drawing view
swView
= (View)swView.GetNextView();
}
}
public
SldWorks swApp;
}
}