Create Circular Pattern Example (C#)
This example shows how to create a circular-pattern feature using a preselected axis, a preselected feature, and equal spacing between
instances.
//-------------------------------------------------------------
// Preconditions:
// 1. Make sure that the specified file exists.
// 2. Rename the namespace of this macro to match the name
// of your C# project.
//
// Postconditions: A circular-pattern feature is created.
//
// NOTE: Because the model is used elsewhere, do not
// save any changes when closing it.
//--------------------------------------------------------------
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using
System;
namespace
FeatureCircularPatternCSharp.csproj
{
partial
class
SolidWorksMacro
{
public
void Main()
{
ModelDoc2 swModel = default(ModelDoc2);
ModelDocExtension swModelDocExt =
default(ModelDocExtension);
FeatureManager swFeatureMgr =
default(FeatureManager);
Feature swFeature = default(Feature);
bool
status = false;
int
warnings = 0;
int
errors = 0;
swModel = (ModelDoc2)swApp.OpenDoc6("C:\\Program
Files\\SolidWorks Corp\\SolidWorks\\samples\\tutorial\\api\\FeatureCircularPattern.SLDPRT",
(int)swDocumentTypes_e.swDocPART,
(int)swOpenDocOptions_e.swOpenDocOptions_Silent,
"",
ref errors,
ref
warnings);
swModelDocExt = (ModelDocExtension)swModel.Extension;
swFeatureMgr = (FeatureManager)swModel.FeatureManager;
// Select boss feature to use
for circular pattern; selection mark is 4
status = swModelDocExt.SelectByID2("Boss-Extrude2",
"BODYFEATURE",
0, 0, 0, false,
4, null,
0);
// Select axis around which to
create circular pattern; selection mark is 1
status = swModelDocExt.SelectByID2("Axis1",
"AXIS",
0, 0, 0, true,
1, null,
0);
// Create circular-pattern
feature
swFeature =
(Feature)swFeatureMgr.FeatureCircularPattern3(6, 6.2831853071,
false,
"NULL",
false,
true);
}
///
<summary>
///
The SldWorks swApp variable is pre-assigned for you.
///
</summary>
public
SldWorks swApp;
}
}