IFeatureManager Interface

Solidworks学习笔记-链接Solidworks

属性

NameDescription备注
DocumentGets the specified document.  获取指定的文档。
EnableFeatureTreeGets or sets whether or not to update the FeatureManager design tree.  获取或设置是否更新 FeatureManager 设计树。
EnableFeatureTreeWindowGets or sets whether the FeatureManager design tree is enabled or not.  获取或设置是否启用 FeatureManager 设计树。
FeatureNameGets the feature name for the specified feature ID.  获取指定功能 ID 的功能名称。
FeatureStatisticsGets statistics about the features in a part document.  获取有关零件文档中特征的统计信息。
GroupComponentInstancesGets or sets whether to group the same components in the same configuration in an assembly into a folder in the FeatureManager design tree.  获取或设置是否将装配体中相同配置中的相同零部件分组到 FeatureManager 设计树中的文件夹中。
MoveSizeFeaturesShows or hides the feature Instant3D.  显示或隐藏特征 Instant3D。
ShowComponentConfigurationDescriptionsGets or sets whether to show the active configuration's component configuration descriptions in the FeatureManager design tree.  获取或设置是否在 FeatureManager 设计树中显示活动配置的零部件配置描述。
ShowComponentConfigurationNamesGets or sets whether to show the active configuration's component configuration names in the FeatureManager design tree.  获取或设置是否在 FeatureManager 设计树中显示活动配置的零部件配置名称。
ShowComponentDescriptionsGets or sets whether to show the component configuration descriptions in the FeatureManager design tree.  获取或设置是否在 FeatureManager 设计树中显示零部件配置描述。
ShowComponentNamesGets or sets whether to show the component configuration names in the FeatureManager design tree.  获取或设置是否在 FeatureManager 设计树中显示零部件配置名称。
ShowDisplayStateNamesGets or sets whether to show the display state names in the FeatureManager design tree.  获取或设置是否在 FeatureManager 设计树中显示显示状态名称。
ShowFeatureDescriptionGets or sets whether to show the description of the feature in the FeatureManager design tree.  获取或设置是否在 FeatureManager 设计树中显示特征描述。
ShowFeatureDetailsGets or sets whether to show the feature details in the FeatureManager design tree.  获取或设置是否在 FeatureManager 设计树中显示特征细节。
ShowFeatureNameGets or sets whether to show the name of the feature in the FeatureManager design tree.  获取或设置是否在 FeatureManager 设计树中显示特征的名称。
ShowHierarchyOnlyGets or sets whether to show only the hierarchy in the FeatureManager design tree.  获取或设置是否仅显示 FeatureManager 设计树中的层次结构。
SolidForTrimGets or sets whether a surface trim feature is a solid body or a surface body.  获取或设置曲面修剪特征是实体还是曲面体。
ViewDependenciesGets or sets whether to view the FeatureManager design tree by its dependencies.  获取或设置是否按依赖项查看 FeatureManager 设计树。
ViewFeaturesGets or sets whether to view the FeatureManager design tree by its features.  获取或设置是否按特征查看 FeatureManager 设计树。
This example shows how to get the statistics of all of the features in a part document.

//-------------------------------------------
// Preconditions:
// 1. Open a part that has multiple features.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Gets the statistics for the features in
//    the part.
// 2. Examine the Immediate window.
//-------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
namespace GetFeatureStatisticsForPart_CSharp.csproj
{
    partial 
 class SolidWorksMacro
    {
        public 
 void Main()
        {
            FeatureStatistics swFeatStat = default(FeatureStatistics);
            FeatureManager swFeatMgr = default(FeatureManager);
            ModelDoc2 swModel = default(ModelDoc2);
            String[] featnames = null;
            Int32[] feattypes = null;
            Object[] 
 features = null;
            Double[] featureUpdateTimes = null;
            Double[] featureUpdatePercentTimes = null;
            int iter = 0;

            swModel = (ModelDoc2)swApp.ActiveDoc;
            swFeatMgr = swModel.FeatureManager;
            swFeatStat = swFeatMgr.FeatureStatistics;

            swFeatStat.Refresh();

            Debug.Print("Model name: " + swFeatStat.PartName);
            Debug.Print(" 
 Number of features: " + swFeatStat.FeatureCount);
            Debug.Print(" 
 Number of solid bodies: " + swFeatStat.SolidBodiesCount);
            Debug.Print(" 
 Number of surface bodies: " + swFeatStat.SurfaceBodiesCount);
            Debug.Print(" 
 Total rebuild time: " + swFeatStat.TotalRebuildTime);
            Debug.Print("");
            features 
 = (Object[])swFeatStat.Features;
            featnames = (String[])swFeatStat.FeatureNames;
            feattypes = (Int32[])swFeatStat.FeatureTypes;
            featureUpdateTimes = (Double[])swFeatStat.FeatureUpdateTimes;
            featureUpdatePercentTimes = (Double[])swFeatStat.FeatureUpdatePercentageTimes;
            if 
 ((featnames != null))
            {
                for 
 (iter = 0; iter <= featnames.GetUpperBound(0); iter++)
                {
                    Debug.Print(" 
 Feature name: " + featnames[iter]);
                    Debug.Print(" 
 Feature created: " + ((Feature)features[iter]).DateCreated);
                    Debug.Print(" 
 Feature type as defined in sw_SelectType_e: " + feattypes[iter]);
                    Debug.Print(" 
 Update time: " + featureUpdateTimes[iter]);
                    Debug.Print(" 
 Update % time: " + featureUpdatePercentTimes[iter]);
                    Debug.Print("");
                }
            }
        }
        public SldWorks swApp;
    }
}
This example shows how to get and set properties related to displaying the FeatureManager design tree.

//----------------------------------------------------
// Preconditions:
// 1. Verify that the specified document exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens the assembly and gets the FeatureManager design tree's display-related property
//    design tree's display-related property values.
// 2. Examine both the Immediate window and the FeatureManager
//    design tree, then press F5.
// 3. Re-examine both the Immediate window and the FeatureManager 
//    design tree to verify the changes.
//
// NOTE: Because this assembly document is used
// elsewhere, do not save changes.
//----------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;

namespace ViewFeatureManagerDesignTreeCSharp.csproj
{
    partial class SolidWorksMacro
    {

        public void Main()
        {
            ModelDoc2 swModelDoc = default(ModelDoc2);
            FeatureManager swFeatMgr = default(FeatureManager);
            string document = null;
            int errors = 0;
            int warnings = 0;


            document = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\advdrawings\\bladed shaft.sldasm";

            swModelDoc = (ModelDoc2)swApp.OpenDoc6(document, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swFeatMgr = (FeatureManager)swModelDoc.FeatureManager;

            Debug.Print("----------------- Before changing FeatureManager design tree properties -----------------");
            Debug.Print("View dependencies     = " + swFeatMgr.ViewDependencies);
            Debug.Print("View features         = " + swFeatMgr.ViewFeatures);
            Debug.Print("Show feature details  = " + swFeatMgr.ShowFeatureDetails);
            Debug.Print("Show hierarchy only   = " + swFeatMgr.ShowHierarchyOnly);

            System.Diagnostics.Debugger.Break();
            // Examine the Immediate window and
            // FeatureManager design tree before
            // resuming the macro

            // Change details, dependencies, hierarchy, and
            // features-related properties
            if ((swFeatMgr.ViewDependencies))
            {
                swFeatMgr.ViewFeatures = true;
            }
            else
            {
                swFeatMgr.ViewDependencies = true;
            }

            if ((swFeatMgr.ShowFeatureDetails))
            {
                swFeatMgr.ShowHierarchyOnly = true;
            }
            else
            {
                swFeatMgr.ShowFeatureDetails = true;
            }

            Debug.Print("----------------- After changing FeatureManager design tree properties -----------------");
            Debug.Print("View dependencies     = " + swFeatMgr.ViewDependencies);
            Debug.Print("View features         = " + swFeatMgr.ViewFeatures);
            Debug.Print("Show feature details  = " + swFeatMgr.ShowFeatureDetails);
            Debug.Print("Show hierarchy only   = " + swFeatMgr.ShowHierarchyOnly);
        }

        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>

        public SldWorks swApp;

    }
}
This example shows how to create a solid body surface trim feature.

//---------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified part to open exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens the specified part.
// 2. Creates Surface-Trim1.
// 3. Expand and examine Solid Bodies(1) in the FeatureManager 
//    design tree and examine the Immediate window.
//
// NOTE: Because the model is used elsewhere, do not save changes.
//----------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            FeatureManager swFeatureManager = default(FeatureManager);
            Feature swFeature = default(Feature);
            bool status = false;
            string fileName = null;
            int errors = 0;
            int warnings = 0;
 
            fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\SurfaceTrimFeature.sldprt";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            swFeatureManager = (FeatureManager)swModel.FeatureManager;
 
            // Select surface features
            status = swModelDocExt.SelectByID2("", "SURFACEBODY", -0.0446486526100784, 0.0218350174377093, 0.0123754341749418, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("", "SURFACEBODY", -0.00815686270678384, 0.0415839719953865, 0.0242402652081068, true, 0, null, 0);
 
            // Select trimming surfaces to create solid body surface trim feature
            status = swFeatureManager.PreTrimSurface(true, true, false, true);
            status = swModelDocExt.SelectByID2("", "SURFACEBODY", 0.0059504253577245, 0.0413800871671199, 0.0248740287174201, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("", "SURFACEBODY", -0.037205042299604, 0.0343527327176432, 0.0123446167727934, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("", "SURFACEBODY", -0.0104497983190015, -0.0472172176775487, 0.0233436625590571, true, 0, null, 0);
            Debug.Print("Solid body surface trim feature? " + swFeatureManager.SolidForTrim);
            swFeatureManager.SolidForTrim = true;
            Debug.Print("Solid body surface trim feature? " + swFeatureManager.SolidForTrim);
            swFeature = (Feature)swFeatureManager.PostTrimSurface(true);
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}

方法

NameDescription备注
AddCornerReliefCornerAdds the bend corner of two selected faces of a sheet metal body to the set of corners to which to apply a corner relief.  将钣金实体的两个选定面的折弯角添加到要应用角释放槽的角组。
AddCornerReliefTypeSpecifies the type of corner relief to apply to the specified corner of the selected sheet metal body.  指定要应用于选定钣金实体的指定角的角释放槽类型。
AddVariablePitchHelixFirstPitchAndDiameterAdds the first segment to a variable-pitch helix.  将第一段添加到可变螺距螺旋。
AddVariablePitchHelixSegmentAdds a segment to a variable-pitch helix.  向可变螺距螺旋线添加线段。
AdvancedHoleCreates an Advanced Hole feature.  创建高级孔特征。
CreateCoordinateSystemCreates a coordinate system feature.  创建坐标系特征。
CreateCustomBendAllowanceCreates a custom bend allowance to use when creating a sheet metal feature.  创建自定义折弯余量以在创建钣金特征时使用。
CreateDefinitionCreates a feature data object of the specified type.  创建指定类型的特征数据对象。
CreateFeatureCreates the specified feature.  创建指定的特征。
CreateFormTool2Creates a forming tool feature with the specified point of insertion in a sheet metal part.  在钣金零件中创建具有指定插入点的成形工具特征。
CreateSaveBodyFeatureCreates a Save Bodies feature and creates part and assembly documents of the save bodies.  创建保存实体特征并创建保存实体的零件和装配体文档。
CreateStructuralMemberGroupCreates a weldment structural-member group.  创建焊件结构成员组。
DraftXpertChangeChanges the parameters on the selected drafted faces, regardless of whether the drafted faces were created manually or with DraftXpert, provided that DraftXpert can process them.  更改所选拔模面的参数,无论拔模面是手动创建还是使用 DraftXpert 创建,前提是 DraftXpert 可以处理它们。
DraftXpertRemoveDeletes the draft on the selected faces. If all the faces of a draft are selected, then this method deletes the draft feature; if not, then this method edits the draft feature and removes the selected face references from it.  删除选定面上的草图。如果选择了草稿的所有面,则此方法将删除草稿特征;如果没有,则此方法将编辑草图特征并从中删除选定的面参考。
EditDeleteFaceEdits a DeleteFace feature.  编辑 DeleteFace 功能。
EditFreeze2Moves the freeze bar to the specified location in the FeatureManager design tree.  将冻结栏移动到 FeatureManager 设计树中的指定位置。
EditReferencePointEdits the selected reference points.  编辑选定的参考点。
EditRollbackRolls back or forward the rollback bar to a specific location in the FeatureManager design tree.  将回滚条向后或向前回滚到 FeatureManager 设计树中的特定位置。
EndVariablePitchHelixEnds and inserts a variable-pitch helix.  结束并插入可变螺距螺旋。
ExpandFeatureExpands the specified component in the specified FeatureManager design tree pane.在指定的 FeatureManager 设计树窗格中展开指定的零部件。
FeatureBossThickenThickens the selected reference surface, and then generates a boss.  加厚选定的参考曲面,然后生成凸台。
FeatureCut4Creates a cut extrude feature.  创建切割拉伸特征。
FeatureCutThickenThickens the selected reference surface feature, and then generates a cut.  加厚选定的参考曲面特征,然后生成切口。
FeatureCutThin2Inserts a thin cut extrude feature.  插入细切拉伸特征。
FeatureDimensionPatternNot implemented.  未实现。
FeatureExtruRefSurface3Inserts an extruded surface.  插入拉伸曲面。
FeatureExtrusion3Creates an extruded feature.  创建拉伸特征。
FeatureExtrusionThin2Creates an extruded thin feature.  创建拉伸的薄特征。
FeatureFillet3Creates the specified fillet feature for selected edges or faces.  为选定的边或面创建指定的圆角特征。
FeatureFolderLocationGets the folder feature for the specified feature.  获取指定要素的文件夹要素。
FeatureRevolve2Creates a base-, boss-, or cut-revolve feature.  创建基本旋转、凸台旋转或切割旋转特征。
FilletXpertChangeChanges the parameters on the selected filleted faces, regardless of whether the filleted faces were created manually or with FilletXpert, provided that FilletXpert can process them.  更改选定圆角面上的参数,无论圆角面是手动创建还是使用 FilletXpert 创建,前提是 FilletXpert 可以处理它们。
FilletXpertMakeCornerCreates or changes a fillet corner feature.  创建或更改圆角特征。
FilletXpertRemoveDeletes the fillets on the selected faces.  删除选定面上的圆角。
FinishCornerReliefCreates a sheet metal corner relief feature.  创建钣金边角释放槽特征。
GetFeatureCountGets the number of features in this document.  获取此文档中的特征数量。
GetFeaturesGets the features in this document.  获取此文档中的特征。
GetFeatureTreeRootItem2Gets the root item of the FeatureManager design tree in the specified pane.  获取指定窗格中 FeatureManager 设计树的根项目。
GetFlatPatternFolderGets the interface to the flat-pattern folder feature in the FeatureManager design tree.  获取 FeatureManager 设计树中平面模式文件夹特征的接口。
GetFreezeLocationGets the location of the freeze bar in the FeatureManager design tree.  获取冻结栏在 FeatureManager 设计树中的位置。
GetPreTrimmedBodiesGets the temporary trimmed bodies using the specified target sheet (surface) body according to the trim tools previously defined by IFeatureManager::PreTrimSurface.  根据之前由 IFeatureManager::PreTrimSurface 定义的修剪工具,使用指定的目标板(曲面)实体获取临时修剪的实体。
GetSelectionSetFolderGets the Selection Sets folder.  获取选择集文件夹。
GetSheetMetalFolderGets the interface to the sheet metal folder feature in the FeatureManager design tree.  获取 FeatureManager 设计树中钣金文件夹特征的接口。
HideBodiesHides both solid and surface bodies in the model.  在模型中隐藏实体和曲面实体。
HoleWizard5Creates customized holes of various kinds.  创建各种自定义孔。
IGetFeaturesGets the features in this document.  获取此文档中的特征。
IInsertCombineFeatureCombines the specified bodies in the multibody part to create a combine feature.  组合多实体零件中的指定实体以创建组合特征。
IInsertMacroFeature3Inserts a macro feature in this model.  在此模型中插入宏特征。
IInsertReferencePointCreates the geometry for the reference points based on any of these selected entities: edges, faces, planes, vertices, or sketch geometry.  基于以下任何选定实体为参考点创建几何:边、面、平面、顶点或草图几何。
IInsertSheetMetalEdgeFlange2Inserts an edge flange in this sheet metal part.  在此钣金零件中插入边线法兰。
InsertCenterOfMassInserts a Center of Mass feature.  插入重心特征。
InsertCenterOfMassReferencePointInserts a Center of Mass Reference Point feature.  插入质心参考点特征。
InsertCombineFeatureCombines the specified bodies in the multibody part to create a combine feature.  组合多实体零件中的指定实体以创建组合特征。
InsertConnectionPointAdds a connection point based on the selected entities.  添加基于选定实体的连接点。
InsertConvertToSheetMetal2Converts a solid or surface body into a sheet metal part.  将实体或曲面实体转换为钣金零件。
InsertCoordinateSystemInserts a coordinate system feature.  插入坐标系特征。
InsertCosmeticThread3Inserts a cosmetic thread.  插入装饰线。
InsertCosmeticWeldBead2Inserts a cosmetic weld bead using either weld geometry or a weld path.  使用焊接几何图形或焊接路径插入装饰焊缝。
InsertCrossBreakInserts a cross break feature on the selected face in a sheet metal part.  在钣金零件的选定面上插入交叉折断特征。
InsertCutBlendInserts a lofted cut based on the selected profiles, centerline, and guide curves.  根据选定的轮廓、中心线和引导曲线插入放样切割。
InsertCutSurfaceInserts a surface-cut feature using the preselected surface or plane.  使用预选曲面或平面插入曲面切割特征。
InsertDeleteBody2Inserts a Body-Delete/Keep feature.  插入正文删除/保留功能。
InsertDeleteHoleForSurfaceInserts a Delete Hole feature for one or more selected hole edges on a surface.  为曲面上的一个或多个选定孔边缘插入删除孔特征。
InsertDwgOrDxfFile2Inserts a DXF/DWG image feature.  插入 DXF/DWG 图像特征。
InsertEdgeMergeMerges multiple edges into a single edge using the selected faces when importing data.  导入数据时,使用选定面将多条边合并为一条边。
InsertEndCapFeature2Inserts an end cap feature using the specified end faces of a structural member.  使用结构构件的指定端面插入端盖特征。
InsertEndCapFeature3Inserts an end cap feature for one or more pre-selected open ends of a structural member.  为结构构件的一个或多个预选开口端插入端盖特征。
InsertFeatureChamferInserts a chamfer.  插入倒角。
InsertFeatureLockNot implemented.  未实现。
InsertFeatureTreeFolder2Inserts a folder in the FeatureManager design tree.  在 FeatureManager 设计树中插入一个文件夹。
InsertFilletBeadFeature2Inserts a fillet weld bead feature and also fills the gap between the pre-selected part bodies, if any.  插入角焊缝特征并填充预选零件实体之间的间隙(如果有)。
InsertFilletBeadFeature3Inserts fillet weld bead features for the specified face sets.  为指定的面组插入角焊缝特征。
InsertFillSurface2Inserts a fill-surface feature in the model.  在模型中插入填充曲面特征。
InsertFlattenSurface2Inserts a surface-flatten feature in the model.  在模型中插入表面平整特征。
InsertFlexFeatureInserts a Flex feature using the selected solid or surface body.  使用选定的实体或曲面实体插入 Flex 特征。
InsertFormToolFeatureInserts a forming tool from the Design Library into a sheet metal part.  将设计库中的成形工具插入钣金零件。
InsertFreeform2Inserts a Freeform feature.  插入自由形式特征。
InsertGridFeatureInserts a Grid System feature.  插入网格系统特征。
InsertGussetFeature2Inserts a gusset feature for the specified faces.  为指定的面插入角撑板特征。
InsertGussetFeature3Inserts a gusset feature for pre-selected faces of a weldment.  为焊件的预选面插入角撑板特征。
InsertIndentInserts an indent feature using a selected target body and tool body regions.  使用选定的目标主体和工具主体区域插入缩进特征。
InsertLiveSectionPlaneInserts a Live Section Plane using the selected plane or planar face.  使用选定的平面或平面插入活动剖面。
InsertMacroFeature3Inserts a macro feature in this model.  在此模型中插入宏特征。
InsertMateReference2Inserts a mate reference for a part or assembly document.  为零件或装配体文档插入配合参考。
InsertMidSurfaceInserts a midsurface feature.  插入中间曲面特征。
InsertMirrorFeature2Mirrors selected features, faces, and bodies about a selected plane or planar face.  围绕选定的平面或平面镜像选定的特征、面和实体。
InsertMoldCoreCavitySolidsCreates a core/cavity solid feature.  创建型芯/型腔实体特征。
InsertMoldPartingLineInserts a mold parting line feature.  插入模具分型线特征。
InsertMoldPartingSurfaceInserts a mold parting surface feature.  插入模具分型面特征。
InsertMoldShutOffSurfaceInserts the mold shut-off surface feature.  插入模具关闭曲面特征。
InsertMoveCopyBody2Moves, rotates, and makes copies of the selected solid bodies or surfaces.  移动、旋转和制作选定实体或曲面的副本。
InsertMoveFace3Moves the selected faces on a solid or surface model.  在实体或曲面模型上移动选定的面。
InsertMultiFaceDraftInserts a multiface draft feature.  插入多面拔模特征。
InsertNetBlend2This method inserts a boundary feature or a boundary surface feature.此方法插入边界特征或边界表面特征。
InsertProtrusionBlend2Creates a lofted body or boss from the selected profiles, centerline, and guide curves.  从选定的轮廓、中心线和引导曲线创建放样实体或凸台。
InsertReferencePointCreates the geometry for the reference points based on any of these selected entities: edges, faces, planes, vertices, or sketch geometry.  基于以下任何选定实体为参考点创建几何:边、面、平面、顶点或草图几何。
InsertRefPlaneInserts a constraint-based reference plane using the selected reference entities.  使用选定的参考实体插入基于约束的参考平面。
InsertRevolvedRefSurfaceCreates a revolved reference surface by revolving a profile around a centerline.  通过围绕中心线旋转轮廓来创建旋转参考曲面。
InsertRibInserts a rib.  插入肋骨。
InsertRuledSurfaceFromEdge2Inserts a ruled surface from the selected edge on this feature.  从该特征上的选定边插入直纹曲面。
InsertSaveOutBodiesSaves the selected surface bodies or solid bodies or sub-weldments to a file.  将选定的曲面实体或实体或子焊件保存到文件。
InsertScaleApplies the specified scaling to either the current model or a selected graphic body.  将指定的缩放比例应用于当前模型或选定的图形主体。
InsertSecurityNoteInserts a note for the specified macro feature.  为指定的宏功能插入注释。
InsertSewRefSurfaceCreates a surface by knitting the selected surfaces together.  通过将选定曲面编织在一起来创建曲面。
InsertSheetMetal3dBendInserts a 3D bend in sheet metal part.  在钣金零件中插入 3D 折弯。
InsertSheetMetalBaseFlange2Inserts a sheet metal base flange feature.  插入钣金基体法兰特征。
InsertSheetMetalCornerTrimInserts a break corner trim in the sheet metal part.  在钣金零件中插入断角修剪。
InsertSheetMetalEdgeFlange2Inserts an edge flange in this sheet metal part.  在此钣金零件中插入边线法兰。
InsertSheetMetalGussetFeature3Inserts a gusset feature using pre-selected entities of a sheet metal part.  使用钣金零件的预选实体插入角撑板特征。
InsertSheetMetalHem2Inserts a hem of the specified relief type at the selected edges of the current sheet metal part.  在当前钣金零件的选定边上插入指定浮雕类型的折边。
InsertSheetMetalLoftedBend2Inserts a lofted bend in a sheet metal part.  在钣金零件中插入放样折弯。
InsertSheetMetalMiterFlangeInserts a meter flange in a sheet metal part.  在钣金零件中插入仪表法兰。
InsertSplitLineIntersectCreates split lines using the selected intersecting tool and target entities.  使用选定的相交工具和目标实体创建分割线。
InsertStructuralWeldment5Inserts a structural weldment feature.  插入结构焊件特征。
InsertSubFolderCreates a subfolder in the Solid Bodies folder in the FeatureManager design tree and moves the selected solid bodies or subfolders in the Solid Bodies folder to the new subfolder.  在 FeatureManager 设计树的实体文件夹中创建一个子文件夹,并将实体文件夹中的选定实体或子文件夹移动到新的子文件夹。
InsertSubWeldFolderCreates a sub weld folder feature containing solid bodies that are pre-selected in the user interface.  创建包含在用户界面中预选的实体的子焊缝文件夹特征。
InsertSubWeldFolder2Creates a sub weld folder feature containing the specified weldment bodies.  创建包含指定焊件实体的子焊缝文件夹特征。
InsertUntrimSurfaceInserts an untrimmed surface to patch surface holes and external edges by extending an existing surface along its natural boundaries.  插入未修剪的曲面,通过沿其自然边界延伸现有曲面来修补曲面孔洞和外部边缘。
InsertVariablePitchHelixStarts a variable-pitch helix using the selected sketch containing an arc.  使用包含圆弧的选定草图开始可变螺距螺旋。
InsertVaryInstanceIncrementApplies the specified increment to the specified pattern instance dimension or spacing.  将指定的增量应用于指定的阵列实例尺寸或间距。
InsertVaryInstanceOverrideApplies the specified override to the specified dimension or spacing of the specified pattern instance.  将指定的替代应用于指定阵列实例的指定尺寸或间距。
InsertWeldmentCutListInserts a cut-list-item folder feature containing pre-selected weldment bodies.  插入包含预选焊件实体的切割清单项目文件夹特征。
InsertWeldmentCutList2Inserts a cut-list-item folder feature containing the specified weldment bodies.  插入包含指定焊件主体的切割清单项目文件夹功能。
InsertWeldmentFeatureInserts a weldment feature.  插入焊件特征。
InsertWeldmentTrimFeatureInserts a weldment trim feature.  插入焊件修剪特征。
InsertWeldmentTrimFeature2Inserts a weldment trim feature for the specified weldment bodies or faces.  为指定的焊件实体或面插入焊件修剪特征。
InsertWrapFeature2Inserts a wrap feature.  插入包裹特征。
IsNameUsedChecks to see whether the specified name is unique in the FeatureManager design tree and valid to use.  检查指定的名称在 FeatureManager 设计树中是否唯一并且可以使用。
MakeStyledCurves2Fits a spline to the preselected sketch segments to make a smooth edge on the model.  将样条线拟合到预选的草图段以在模型上形成平滑的边缘。
MoldUndercutDetect2Detects trapped, also called undercut, areas in a model that cannot be ejected from the mold.  检测模型中无法从模具中弹出的被困区域,也称为底切区域。
MoveRotateLiveSectionPlaneMoves or rotates the selected Live Section Plane using the selected Live Section Plane and its manipulator.  使用选定的实时剖面及其操纵器移动或旋转选定的实时剖面。
MoveToFolderMoves the selected feature or folder in the Solid Bodies Feature Manager design tree structure to the specified folder in the Solid Bodies Feature Manager design tree structure.  将实体特征管理器设计树结构中的选定特征或文件夹移动到实体特征管理器设计树结构中的指定文件夹。
PostIntersectCreates an intersect feature.  创建相交特征。
PostSplitBody2Creates a Split feature.  创建拆分功能。
PostTrimSurfaceSets whether to sew the resulting trimmed surfaces.  设置是否缝合生成的修剪曲面。
PreIntersect2Prepares an intersect feature.  准备一个相交特征。
PreSplitBody2Gets all of the bodies created by splitting a part.  获取通过拆分零件创建的所有实体。
PreTrimSurfaceSets the trimming options before trimming a surface.  在修剪曲面之前设置修剪选项。
SetFreeformBoundaryContinuitySets the boundary continuity for this Freeform feature.  设置此自由形式特征的边界连续性。
SetFreeformCurveDataAdds a curve to the pre-selected face for a Freeform feature.  将曲线添加到自由形状特征的预选面。
SetFreeformPointDataAdds a point to a curve for a Freeform feature.  为自由形式特征向曲线添加点。
SetNetBlendCurveDataSets the data for a curve for this boundary feature or boundary surface feature.  设置此边界特征或边界表面特征的曲线数据。
SetNetBlendDirectionDataSets the curve set data (one for each of the two directions) for this boundary feature or boundary surface feature.  设置此边界特征或边界表面特征的曲线集数据(两个方向各一个)。
ShowBodiesShows both hidden solid and surface bodies.  显示隐藏的实体和曲面实体。
SimpleHole2Inserts a simple hole feature.  插入一个简单的孔特征。
UpdateFeatureTreeUpdates the FeatureManager design tree. 更新 FeatureManager 设计树。
This example shows how to create a corner relief feature.

//----------------------------------------------------------------------------
// Preconditions: 
// Open public_documents\samples\tutorial\sheetmetal\formtools\cover.sldprt.
//
// Postconditions:
// 1. The model is rotated to the back view.
// 2. An edge flange is created.
// 3. The model is rotated slightly about the x-axis.
// 4. A corner relief feature is created:
//    * A rectangular corner relief is added to one corner of the edge flange.
//    * An obround corner relief is added to another corner of the edge flange.
//----------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
namespace TwoCorners_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            bool bValue = false;
            Edge swEdge = default(Edge);
            double dAngle = 0;
            double dLength = 0;
            Feature swFeature = default(Feature);
            Entity swEntity = default(Entity);
            Sketch swSketch = default(Sketch);
            object[] vSketchSegments = null;
            SketchLine swSketchLine = default(SketchLine);
            SketchPoint swStartPoint = default(SketchPoint);
            SketchPoint swEndPoint = default(SketchPoint);
            int nOptions = 0;
            double dSize = 0;
            double dFactor1 = 0;
            double dFactor2 = 0;
            Edge[] aFlangeEdges = new Edge[1];
            object vFlangeEdges = null;
            Sketch[] aSketchFeats = new Sketch[1];
            object vSketchFeats = null;

            // Get active document
            swModel = (ModelDoc2)swApp.ActiveDoc;

            // Flange parameters

            // Set the angle
            dAngle = (90.0 / 180.0) * 3.1415926535897;

            dLength = 0.01;

            // Rotate model so that IModelDocExtension::SelectByID2 coordinates can be found
            swModel.ShowNamedView2("*Back", -1);
            swModel.ViewZoomtofit2();

            // Select edge for flange
            bValue = swModel.Extension.SelectByID2("", "EDGE", 0.0372105002552985, 0.052846642716446, -9.93711211094706E-06, false, 0, null, 0);

            // Get edge
            swEdge = (Edge)((SelectionMgr)(swModel.SelectionManager)).GetSelectedObject6(1, -1);

            // Insert a sketch for an edge flange
            swFeature = (Feature)swModel.InsertSketchForEdgeFlange(swEdge, dAngle, false);

            // Select
            bValue = swFeature.Select2(false, 0);

            // Start sketch editing
            swModel.EditSketch();

            // Get the active sketch
            swSketch = (Sketch)swModel.SketchManager.ActiveSketch;

            // Add the edge to the sketch

            // Cast edge to entity
            swEntity = (Entity)swEdge;

            // Select edge
            bValue = swEntity.Select4(false, null);

            // Use the edge in the sketch
            bValue = swModel.SketchManager.SketchUseEdge(false);

            // Get the created sketch line
            vSketchSegments = (object[])swSketch.GetSketchSegments();

            swSketchLine = (SketchLine)vSketchSegments[0];

            // Get start and end point
            swStartPoint = (SketchPoint)swSketchLine.GetStartPoint2();
            swEndPoint = (SketchPoint)swSketchLine.GetEndPoint2();

            // Create additional lines to define sketch
            // Set parameters defining the sketch geometry
            dSize = swEndPoint.X - swStartPoint.X;
            dFactor1 = 0.1;
            dFactor2 = 1.25;

            swModel.SetAddToDB(true);
            swModel.SetDisplayWhenAdded(false);

            swModel.SketchManager.CreateLine(swStartPoint.X, swStartPoint.Y, 0.0, swStartPoint.X, swStartPoint.Y + dLength, 0.0);
            swModel.SketchManager.CreateLine(swStartPoint.X, swStartPoint.Y + dLength, 0.0, swStartPoint.X + dFactor1 * dSize, swStartPoint.Y + dFactor2 * dLength, 0.0);
            swModel.SketchManager.CreateLine(swStartPoint.X + dFactor1 * dSize, swStartPoint.Y + dFactor2 * dLength, 0.0, swEndPoint.X - dFactor1 * dSize, swStartPoint.Y + dFactor2 * dLength, 0.0);
            swModel.SketchManager.CreateLine(swEndPoint.X - dFactor1 * dSize, swStartPoint.Y + dFactor2 * dLength, 0.0, swEndPoint.X, swEndPoint.Y + dLength, 0.0);
            swModel.SketchManager.CreateLine(swEndPoint.X, swEndPoint.Y, 0.0, swEndPoint.X, swEndPoint.Y + dLength, 0.0);

            // Reset
            swModel.SetDisplayWhenAdded(true);
            swModel.SetAddToDB(false);

            // Commit changes made to the sketch
            swModel.SketchManager.InsertSketch(true);

            // Set options
            nOptions = (int)swInsertEdgeFlangeOptions_e.swInsertEdgeFlangeUseDefaultRadius + (int)swInsertEdgeFlangeOptions_e.swInsertEdgeFlangeUseDefaultRelief;

            aFlangeEdges[0] = swEdge;
            aSketchFeats[0] = swSketch;

            vFlangeEdges = aFlangeEdges;
            vSketchFeats = aSketchFeats;

            swFeature = swModel.FeatureManager.InsertSheetMetalEdgeFlange2((vFlangeEdges), (vSketchFeats), nOptions, dAngle, 0.0, (int)swFlangePositionTypes_e.swFlangePositionTypeBendOutside, dLength, (int)swSheetMetalReliefTypes_e.swSheetMetalReliefNone, 0.0, 0.0,
            0.0, (int)swFlangeDimTypes_e.swFlangeDimTypeInnerVirtualSharp, null);

            // Rotate view so that IModelDocExtension::SelectByID2 coordinates can be found
            ModelView myModelView = default(ModelView);
            myModelView = (ModelView)swModel.ActiveView;
            myModelView.RotateAboutCenter(45, 0.00911235438195936);

            // Select the sheet metal body to which to apply a corner relief
            bValue = swModel.Extension.SelectByID2("Edge-Flange1", "SOLIDBODY", 0, 0, 0, true, 0, null, 0);
            swModel.ClearSelection2(true);

            // Specify two corners of the edge flange for which to create a corner relief

            // Select faces that define the first corner
            bValue = swModel.Extension.SelectByID2("", "FACE", 0.0549242492243928, 0.053073918098565, 0.0242634000000049, true, 4, null, 0);
            bValue = swModel.Extension.SelectByID2("", "FACE", 0.0276778697571744, 0.0530739180985651, -0.00104170971004399, true, 4, null, 0);
            long myCorner = 0;
            myCorner = swModel.FeatureManager.AddCornerReliefCorner();

            // Specify the type of corner relief to apply to the first corner
            bool myReliefType = false;
            myReliefType = swModel.FeatureManager.AddCornerReliefType(-1, (int)swCornerReliefType_e.swCornerSquareRelief, 0.0001, 0.0007366, 0.00018415, false, false, false, true, false);
            swModel.ClearSelection2(true);

            // Select faces that define the second corner
            bValue = swModel.Extension.SelectByID2("", "FACE", 0.0276778697571744, 0.0530739180985651, -0.00104170971004399, true, 4, null, 0);
            bValue = swModel.Extension.SelectByID2("", "FACE", 0.000431490289955978, 0.053073918098565, 0.0242634000000049, true, 4, null, 0);
            myCorner = swModel.FeatureManager.AddCornerReliefCorner();

            // Specify the type of corner relief to apply to the second corner
            myReliefType = swModel.FeatureManager.AddCornerReliefType(-1, (int)swCornerReliefType_e.swCornerObroundRelief, 0.0001, 0.0029464, 0.0007366, false, false, false, false, false);

            // Create the corner relief feature
            Feature myFeature = default(Feature);
            myFeature = swModel.FeatureManager.FinishCornerRelief();

        }



        public SldWorks swApp;

    }


} 
This example shows how to create a variable-pitch helix.

//---------------------------------------------------------
// Preconditions: Verify that the specified part document 
// template exists.
//
// Postconditions:
// 1. Creates a variable-pitch helix.
// 2. Examine the graphics area and FeatureManager design
//    tree.
//---------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;

namespace AddVariablePitchHelixCSharp.csproj
{
    partial class SolidWorksMacro
    {


        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            SketchManager swSketchManager = default(SketchManager);
            SketchSegment swSketchSegment = default(SketchSegment);
            FeatureManager swFeatureManager = default(FeatureManager);
            Feature swFeature = default(Feature);
            int errors = 0;
            bool status = false;

            // Create part document
            swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2016\\templates\\Part.prtdot", 0, 0, 0);
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swSketchManager = (SketchManager)swModel.SketchManager;
            swFeatureManager = (FeatureManager)swModel.FeatureManager;

            // Sketch a circle
            swSketchSegment = (SketchSegment)swSketchManager.CreateCircle(0.0, 0.0, 0.0, 0.045549, 0.013926, 0.0);

            // Create a variable-pitch helix using the sketched circle
            status = swFeatureManager.InsertVariablePitchHelix(false, true, 1, 4.712388980385);
            status = swFeatureManager.AddVariablePitchHelixFirstPitchAndDiameter(0.053, 0.05382625271268);
            status = swFeatureManager.AddVariablePitchHelixSegment(0.0265, 0.05382625271268, 0.5);
            status = swFeatureManager.AddVariablePitchHelixSegment(0.03975, 0.05382625271268, 0.75);
            status = swFeatureManager.AddVariablePitchHelixSegment(0.046375, 0.05382625271268, 0.875);
            status = swFeatureManager.AddVariablePitchHelixSegment(0.053, 0.05382625271268, 1);
            swFeature = (Feature)swFeatureManager.EndVariablePitchHelix();

        }


        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>

        public SldWorks swApp;

    }
}
This example shows how to create and modify a variable-pitch helix.

//--------------------------------------------
// Preconditions:
// 1. Specified part template exits.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens a new part document.
// 2. Selects Front Plane, creates a circle, and
//    and uses the circle to create a variable-pitch
//    helix feature named Helix/Spiral1.
// 3. Gets whether the Helix/Spiral1 feature is a
//    variable-pitch helix. If so:
//    a. Prints to the Immediate window the number
//       of regions.
//    b. Prints to the Immediate window
//       each region's diameter, pitch, height,
//       and revolution.
//    c. If second region of variable-pitch helix
//       is defined by height and revolution:
//       1. Modifies region's diameter, height, and
//          revolution values.
//       2. Prints to the Immediate window the status
//          of modifications made in previous step.
//    d. Deletes the last region in the Helix/Spiral1 feature and
//       prints the status of the deletion to the Immediate window.
//    e. Adds a new last region to the Helix/Spiral1 feature and
//       prints the status of the addition to the Immediate window.
//    - or -
//    Prints to the Immediate window that the Helix/Spiral1
//    feature is not a variable-pitch helix.
// 4. Examine the Immediate window.
//--------------------------------------------
 
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace HelixCSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
 
        public void Main()
        {
            PartDoc swPart = default(PartDoc);
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            SketchManager swSketchMgr = default(SketchManager);
            FeatureManager swFeatureMgr = default(FeatureManager);
            Feature swFeat = default(Feature);
            HelixFeatureData swHelixFeatData = default(HelixFeatureData);
            bool status = false;
            int i = 0;
            int helixType = 0;
            int helixStatus = 0;
            int[] helixRegionArray = new int[1];
 
 
            swPart = (PartDoc)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SolidWorks 2015\\templates\\Part.prtdot", 0, 0, 0);
            swModel = (ModelDoc2)swPart;
            swModelDocExt = (ModelDocExtension)swModel.Extension;
 
            //Select plane on which to create circle
            //for variable-pitch helix
            status = swModelDocExt.SelectByID2("Front Plane", "PLANE", -0.0571253507530972, 0.0536428819342089, 0.00349118658744337, false, 0, null, 0);
            swSketchMgr = (SketchManager)swModel.SketchManager;
            swSketchMgr.InsertSketch(true);
            //Create circle for variable-pitch helix
            swSketchMgr.CreateCircle(0.007581, 0.053509, 0.0, 0.013533, 0.016475, 0.0);
            // Create a variable-pitch helix using the just-sketched circle
            swFeatureMgr = (FeatureManager)swModel.FeatureManager;
            status = swFeatureMgr.InsertVariablePitchHelix(false, true, (int)swHelixDefinedBy_e.swHelixDefinedByHeightAndRevolution, 4.712388980385);
            status = swFeatureMgr.AddVariablePitchHelixFirstPitchAndDiameter(0.053, 0.05382625271268);
            status = swFeatureMgr.AddVariablePitchHelixSegment(0.0265, 0.05382625271268, 0.5);
            status = swFeatureMgr.AddVariablePitchHelixSegment(0.03975, 0.05382625271268, 0.75);
            status = swFeatureMgr.AddVariablePitchHelixSegment(0.046375, 0.05382625271268, 0.875);
            status = swFeatureMgr.AddVariablePitchHelixSegment(0.053, 0.05382625271268, 1);
            swFeat = swFeatureMgr.EndVariablePitchHelix();
            //Get variable-pitch helix
            swHelixFeatData = (HelixFeatureData)swFeat.GetDefinition();
            if (swHelixFeatData.VariablePitch)
            {
                Debug.Print("  Number of regions: " + swHelixFeatData.PitchCount);
                for (i = 1; i <= swHelixFeatData.PitchCount; i++)
                {
                    Debug.Print("   Region " + i + ":");
                    Debug.Print("      Diameter: " + swHelixFeatData.GetRegionParameterAtIndex(i, (int)swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Diameter));
                    Debug.Print("      Pitch: " + swHelixFeatData.GetRegionParameterAtIndex(i, (int)swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Pitch));
                    Debug.Print("      Height: " + swHelixFeatData.GetRegionParameterAtIndex(i, (int)swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Height));
                    Debug.Print("      Revolutions: " + swHelixFeatData.GetRegionParameterAtIndex(i, (int)swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Revolution));
                }
                //Modify region 2 of variable-pitch helix
                //defined by height and revolution
                helixType = swHelixFeatData.DefinedBy;
 
                switch (helixType)
                {
                    case (int)swHelixDefinedBy_e.swHelixDefinedByHeightAndRevolution:
                        if (i >= 2)
                        {
                            //Cannot change pitch
                            //Can change diameter, height, and revolution
                            //Revolution must be smaller than previous region's
                            //revolution and less than next region's revolution
                            Debug.Print("");
                            Debug.Print("Helix defined by height and revolution:");
                            Debug.Print("   Region modified: 2");
                            helixStatus = swHelixFeatData.SetRegionParameterAtIndex(2, (int)swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Diameter, 0.052);
                            Debug.Print("      Diameter modified (0 = success): " + helixStatus);
                            helixStatus = swHelixFeatData.SetRegionParameterAtIndex(2, (int)swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Height, 0.025);
                            Debug.Print("      Height modified (0 = success): " + helixStatus);
                            helixStatus = swHelixFeatData.SetRegionParameterAtIndex(2, (int)swVariablePitchHelixRegionParameter_e.swVariablePitchHelixRegionParameter_Revolution, 0.45);
                            Debug.Print("      Revolution modified (0 = success): " + helixStatus);
                        }
                        else
                        {
                            Debug.Print("Less than three regions in Helix/Spiral1 feature.)");
                        }
                        break;
 
                    case (int)swHelixDefinedBy_e.swHelixDefinedByHeightAndPitch:
                        //Cannot change revolution
                        //TODO: Add code for variable-pitch helix defined by height and pitch
                        break;
 
                    case (int)swHelixDefinedBy_e.swHelixDefinedByPitchAndRevolution:
                        //Cannot change height
                        //TODO: Add code for variable-pitch helix defined by pitch and revolution            
                        break;
                }
 
                //Delete last region in the Helix/Spiral1 feature
                i = i - 1;
                helixRegionArray[0] = (int)i;
                Debug.Print("");
                status = swHelixFeatData.DeleteRecord(helixRegionArray);
                Debug.Print("Last region in Helix/Spiral1 deleted; i.e., region " + i + " was deleted: " + status);
 
                //Add new region to end of Region parameters table
                double[] record = new double[4];
                //Height
                record[0] = 0.055;
                //Number of revolutions
                record[1] = 1;
                //0 indicates that this value cannot be specified
                //for this type of variable-pitch helix (Height and Revolution)
                //Instead, SOLIDWORKS calculates it
                record[2] = 0;
                //Diameter
                record[3] = 0.05382625271268;
                status = swHelixFeatData.AddLastRecord(record);
                Debug.Print("New region 5 added as last record to Helix/Spiral1: " + status);
 
                status = swFeat.ModifyDefinition(swHelixFeatData, swModel, null);
            }
            else
            {
                Debug.Print("Helix is not variable pitch.");
            }
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to insert a hem into a sheet metal part.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Open a sheet metal part.
// 2. Select the edge to which to you can add a hem.
// 3. Open the Immediate window.
//
// Postconditions:
// 1. Adds an open hem with a custom relief of type Obround and
//    a relief ratio of 1.0.
// 2. Gets the hem type.
// 3. Examine the Immediate window.
// ---------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
namespace SheetMetalHem_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        ModelDoc2 Part;
        CustomBendAllowance CBAObject;
        Feature myFeature;
        HemFeatureData myHem;

        public void Main()
        {
            Part = (ModelDoc2)swApp.ActiveDoc;

            CBAObject = Part.FeatureManager.CreateCustomBendAllowance();
            CBAObject.Type = 2;
            CBAObject.KFactor = 0.5;

            // Insert an open hem of custom relief type Obround and relief ratio 1.0
            myFeature = Part.FeatureManager.InsertSheetMetalHem2((int)swHemTypes_e.swHemTypeOpen, (int)swHemPositionTypes_e.swHemPositionTypeOutside, false, 0.01, 0.01, 0, 0.005, 0.0011, CBAObject, false,
            (int)swSheetMetalReliefTypes_e.swSheetMetalReliefObround, 0, true, 1.0, 0, 0);
            Part.ClearSelection2(true);

            myHem = (HemFeatureData)myFeature.GetDefinition();
            Debug.Print("Hem type as defined in swHemTypes_e: " + myHem.Type);
        }



        public SldWorks swApp;

    }

}
This example shows how to create and edit a thread feature.

//---------------------------------------------------------------------------- 
// Preconditions: 
// 1. Open:
//    public_documents\samples\tutorial\api\holecube.sldprt
// 2. Open an Immediate window.
// 
// Postconditions: 
// 1. Creates Thread1.
// 2. Modifies the start angle and overrides the pitch of Thread1.
// 3. Inspect the Immediate window.
//
// NOTE: Because the model is used elsewhere, do not save changes.
//----------------------------------------------------------------------------
 
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Diagnostics;
 
 
namespace ThreadFeature_CSharp
{
    public partial class SolidWorksMacro
    {
        public void Main()
        {
 
            ModelDoc2 swModel = default(ModelDoc2);
            Feature swFeat = default(Feature);
            FeatureManager FeatMgr = default(FeatureManager);
            ThreadFeatureData swThreadFeatData = default(ThreadFeatureData);
            Edge pEdge = default(Edge);
 
            bool boolstatus = false;
 
 
            swModel = (ModelDoc2)swApp.ActiveDoc;
            FeatMgr = swModel.FeatureManager;

            //Create and initialize a thread feature data object
            swThreadFeatData = (ThreadFeatureData)FeatMgr.CreateDefinition((int)swFeatureNameID_e.swFmSweepThread);
            swThreadFeatData.InitializeThreadData();

            //Specify the thread method type as extrude
            swThreadFeatData.ThreadMethod = 1;

            //Specify the up-to-selection end conditon
            swThreadFeatData.EndCondition = (int)swThreadEndCondition_e.swThreadEndCondition_UpToSelection;
 
            //Select the thread's starting edge
            boolstatus = swModel.Extension.SelectByRay(0.011047195612548, -0.0190800402080527, -0.000365739009737354, 0.164466301431523, -0.479983539625146, -0.861723063044243, 0.00160036844432164, 1, false, 1,
            0);
            pEdge = (Edge)((SelectionMgr)(swModel.SelectionManager)).GetSelectedObject6(1, -1);
            swThreadFeatData.Edge = pEdge;
            swModel.ClearSelection2(true);
 
            //Select the thread's up-to reference
            boolstatus = swModel.Extension.SelectByRay(0.00850469161018452, -0.0212858011305457, -0.0254798703094821, 0.164466301431523, -0.479983539625146, -0.861723063044243, 0.00160036844432164, 1, true, 1,
            0);
            pEdge = (Edge)((SelectionMgr)(swModel.SelectionManager)).GetSelectedObject6(1, -1);
            swThreadFeatData.SetEndConditionReference(pEdge);
            swModel.ClearSelection2(true);
 
            //Create the thread feature
            swFeat = FeatMgr.CreateFeature(swThreadFeatData);
            Debug.Print("File = " + swModel.GetPathName());

            //Access the thread feature data and print its properties
            swThreadFeatData = (ThreadFeatureData)swFeat.GetDefinition();
 
            swThreadFeatData.AccessSelections((ModelDoc)swModel, null);
            Debug.Print("Offset the starting location of the helix? " + swThreadFeatData.Offset);
            Debug.Print("Reverse direction of offset? " + swThreadFeatData.ReverseOffset);
            Debug.Print("Offset distance: " + swThreadFeatData.OffsetDistance);
            Debug.Print("Thread starting angle: " + swThreadFeatData.ThreadStartAngle);
            Debug.Print("End condition as defined in swThreadEndCondition_e: " + swThreadFeatData.EndCondition);
            Debug.Print("End condition offset: " + swThreadFeatData.EndConditionOffset);
            Debug.Print("Reverse end condition offset? " + swThreadFeatData.EndConditionOffsetReverse);
            Debug.Print("End condition offset distance: " + swThreadFeatData.EndConditionOffsetDistance);
            Debug.Print("Keep thread length constant? " + swThreadFeatData.MaintainThreadLength);
            Debug.Print("Thread profile type: " + swThreadFeatData.Type);
            Debug.Print("Size: " + swThreadFeatData.Size);
            Debug.Print("Diameter overridden? " + swThreadFeatData.DiameterOverride);
            Debug.Print("Diameter: " + swThreadFeatData.Diameter);
            Debug.Print("Pitch overridden? " + swThreadFeatData.PitchOverride);
            Debug.Print("Pitch: " + swThreadFeatData.Pitch);
            Debug.Print("Thread method as defined in swThreadMethod_e: " + swThreadFeatData.ThreadMethod);
            Debug.Print("Flip the profile of the helix about an axis? " + swThreadFeatData.MirrorProfile);
            Debug.Print("How to flip the profile of the helix as defined in swThreadMirrorType_e: " + swThreadFeatData.MirrorType);
            Debug.Print("Helix rotation angle: " + swThreadFeatData.RotationAngle);
            Debug.Print("Thread wind direction (true = clockwise, false = counterclockwise): " + swThreadFeatData.RightHanded);
            Debug.Print("Multiple thread starts? " + swThreadFeatData.MultipleStart);
            if (swThreadFeatData.MultipleStart == true)
            {
                Debug.Print("  Number of starts? " + swThreadFeatData.NumberOfStarts);
            }
            Debug.Print("Trim with the end face? " + swThreadFeatData.TrimEndFace);
            Debug.Print("Trim with the start face? " + swThreadFeatData.TrimStartFace);
 
            //Change the thread start angle and pitch
            swThreadFeatData.ThreadStartAngle = 0.04;
            swThreadFeatData.PitchOverride = true;
            swThreadFeatData.Pitch = 0.01

            //Modify the feature definition
            swFeat.ModifyDefinition(swThreadFeatData, swModel, null);
        }
 
        // The SldWorks swApp variable is pre-assigned for you.
        public SldWorks swApp;
 
    }
}

This example shows how to create a forming tool for a sheet metal part.

//----------------------------------------------------------------------------
// Preconditions: Open public_documents\samples\tutorial\api\formingTool.sldprt
//
// Postconditions: 
// 1. Creates FormTool1 with the specified stopping face, face to remove,
//    and insertion point.
// 2. Examine the FeatureManager design tree and graphics area.
//
// NOTE: Because the model is used elsewhere, do not save changes.
// ---------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
namespace CreateFormTool_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        ModelDoc2 Part;
        Feature myFeature;

        bool boolstatus;
        public void Main()
        {
            Part = (ModelDoc2)swApp.ActiveDoc;
            //Select the stopping face: Mark = 1
            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.0283459459495816, 0.0187563215566229, 0, true, 1, null, 0);
            //Select the face to remove: Mark = 2
            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.0358143533097106, 0.0308169322714775, 0.0066335048657038, true, 2, null, 0);
            //Create a forming tool with insertion point x=0, y=0
            myFeature = Part.FeatureManager.CreateFormTool2(0, 0);
        }

        public SldWorks swApp;

    }
}
This example shows how to create structural weldment features using structural member groups.

//---------------------------------------------------------------------------
// Preconditions:
// 1. Verify the existence of the weldment profile pathname
//    as specified in both calls to IFeatureManager::InsertStructuralWeldment4.
// 2. Open an Immediate window.
//
// Postconditions:
// 1. Creates a new part document containing a weldment and structural members.
// 2. Rotates c channel 3 x 5(1).
// 3. Inspect the FeatureManager design tree, graphics area, and
//    Immediate window.
//---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
 
namespace Macro1CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 Part;
        bool boolstatus;
        FeatureManager FeatMgr;
        SelectionMgr SelMgr;
        Feature swWeldFeat;
        StructuralMemberFeatureData swWeldFeatData;
 
        public void Main()
        {
 
            string MacroFolder = null;
            MacroFolder = swApp.GetCurrentMacroPathFolder();
            swApp.SetCurrentWorkingDirectory(MacroFolder);
 
            string Template = null;
            Template = swApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            Part = (ModelDoc2)swApp.NewDocument(Template, 0, 0, 0);
 
            FeatMgr = Part.FeatureManager;
            SelMgr = (SelectionMgr)Part.SelectionManager;
 
            Part.ClearSelection2(true);
 
            object vSkLines = null;
            vSkLines = Part.SketchManager.CreateCornerRectangle(-0.1872393706766, 0.1133237194389, 0, -0.07003610048208, 0.009188409684237, 0);
 
            Part.ClearSelection2(true);
 
            vSkLines = Part.SketchManager.CreateCornerRectangle(0.06513561531715, 0.03369083550887, 0, 0.1807053904567, -0.08106219210316, 0);
            Part.SketchManager.InsertSketch(true);
 
            Part.ViewZoomtofit2();
 
            object myFeature = null;
            myFeature = Part.FeatureManager.InsertWeldmentFeature();
 
            StructuralMemberGroup Group1 = default(StructuralMemberGroup);
            Group1 = FeatMgr.CreateStructuralMemberGroup();
            SketchSegment[] segments1 = new SketchSegment[2];
            object[] GroupArray1 = new object[1];
 
            boolstatus = Part.Extension.SelectByID2("Line1@Sketch1", "EXTSKETCHSEGMENT", -0.1495427140733, 0.1133237194389, 0, false, 0, null, 0);
            boolstatus = Part.Extension.SelectByID2("Line2@Sketch1", "EXTSKETCHSEGMENT", -0.1872393706766, 0.08238014634844, 0, true, 0, null, 0);
 
            segments1[0] = (SketchSegment)SelMgr.GetSelectedObject6(1, 0);
            segments1[1] = (SketchSegment)SelMgr.GetSelectedObject6(2, 0);
 
            Group1.Segments = segments1;
            Group1.Angle = 0.785714285714286;             //radians 
            Group1.ApplyCornerTreatment = true;
            Group1.CornerTreatmentType = (int)swSolidworksWeldmentEndCondOptions_e.swEndConditionMiter;
            Group1.MirrorProfile = true;
            Group1.MirrorProfileAxis = (int)swMirrorProfileOrAlignmentAxis_e.swMirrorProfileOrAlignmentAxis_Vertical;
            Group1.GapWithinGroup = 0.0127;            //meters 
 
            GroupArray1[0] = (object)Group1;
            DispatchWrapper[] groups1 = new DispatchWrapper[1];
            groups1[0] = new DispatchWrapper(GroupArray1[0]);
 
            myFeature = Part.FeatureManager.InsertStructuralWeldment4("C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\lang\\english\\weldment profiles\\ansi inch\\c channel\\3 x 5.sldlfp", 1, false, groups1);
 
            Part.ClearSelection2(true);
 
            StructuralMemberGroup Group2 = default(StructuralMemberGroup);
            Group2 = FeatMgr.CreateStructuralMemberGroup();
            SketchSegment[] segments2 = new SketchSegment[2];
            object[] GroupArray2 = new object[1];
 
            boolstatus = Part.Extension.SelectByID2("Line5@Sketch1", "EXTSKETCHSEGMENT", 0.1185825251083, 0.03369083550887, 0, false, 0, null, 0);
            boolstatus = Part.Extension.SelectByID2("Line6@Sketch1", "EXTSKETCHSEGMENT", 0.06513561531715, -0.02774616865332, 0, true, 0, null, 0);
 
            segments2[0] = (SketchSegment)SelMgr.GetSelectedObject6(1, 0);
            segments2[1] = (SketchSegment)SelMgr.GetSelectedObject6(2, 0);
 
            Group2.Segments = segments2;
            Group2.AlignAxis = (int)swMirrorProfileOrAlignmentAxis_e.swMirrorProfileOrAlignmentAxis_Vertical;
 
            GroupArray2[0] = (object)Group2;
            DispatchWrapper[] groups2 = new DispatchWrapper[1];
            groups2[0] = new DispatchWrapper(GroupArray2[0]);
 
            myFeature = Part.FeatureManager.InsertStructuralWeldment4("C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\lang\\english\\weldment profiles\\ansi inch\\c channel\\3 x 5.sldlfp", 1, false, groups2);
 
            Part.ClearSelection2(true);
 
            // Get Group Information 
 
            StructuralMemberGroup Group = default(StructuralMemberGroup);
            object[] vGroups = null;
            object[] vSegments = null;
 
            boolstatus = Part.Extension.SelectByID2("c channel 3 x 5(1)", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swWeldFeat = (Feature)SelMgr.GetSelectedObject6(1, 0);
 
            swWeldFeatData = (StructuralMemberFeatureData)swWeldFeat.GetDefinition();
            swWeldFeatData.AccessSelections(Part, null);
 
            Debug.Print("");
            Debug.Print("Groups Count : " + swWeldFeatData.GetGroupsCount());
            Debug.Print(" Feature Name : " + swWeldFeat.Name);
 
            vGroups = (object[])swWeldFeatData.Groups;
 
            int i = 0;
            int j = 0;
            for (i = vGroups.GetLowerBound(0); i <= vGroups.GetUpperBound(0); i++)
            {
                Group = (StructuralMemberGroup)vGroups[i];
                Debug.Print(" Segment Count in Group " + i + 1 + " : " + Group.GetSegmentsCount());
                Debug.Print(" Rotational angle of group: " + Group.Angle);
                Debug.Print(" ApplyCornerTreatment: " + Group.ApplyCornerTreatment);
                Debug.Print(" CornerTreatmentType: " + Group.CornerTreatmentType);
                Debug.Print(" MirrorProfile: " + Group.MirrorProfile);
                Debug.Print(" MirrorProfileAxis: " + Group.MirrorProfileAxis);
                Debug.Print(" GapWithinGroup: " + Group.GapWithinGroup);
                vSegments = (object[])Group.Segments;
                for (j = vSegments.GetLowerBound(0); j <= vSegments.GetUpperBound(0); j++)
                {
                    ((SketchSegment)vSegments[j]).Select(false);
                }
            }
 
            swWeldFeatData.ReleaseSelectionAccess();
 
            boolstatus = Part.Extension.SelectByID2("c channel 3 x 5(2)", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swWeldFeat = (Feature)SelMgr.GetSelectedObject6(1, 0);
            swWeldFeatData = (StructuralMemberFeatureData)swWeldFeat.GetDefinition();
            swWeldFeatData.AccessSelections(Part, null);
 
            Debug.Print("");
            Debug.Print("Groups Count : " + swWeldFeatData.GetGroupsCount());
            Debug.Print(" Feature Name : " + swWeldFeat.Name);
 
            vGroups = (object[])swWeldFeatData.Groups;
            for (i = vGroups.GetLowerBound(0); i <= vGroups.GetUpperBound(0); i++)
            {
                Group = (StructuralMemberGroup)vGroups[i];
                Debug.Print(" Segment Count in Group " + i + 1 + " : " + Group.GetSegmentsCount());
                Debug.Print(" Rotational angle of group: " + Group.Angle);
                Debug.Print(" ApplyCornerTreatment: " + Group.ApplyCornerTreatment);
                Debug.Print(" CornerTreatmentType: " + Group.CornerTreatmentType);
                Debug.Print(" MirrorProfile: " + Group.MirrorProfile);
                Debug.Print(" MirrorProfileAxis: " + Group.MirrorProfileAxis);
                Debug.Print(" GapWithinGroup: " + Group.GapWithinGroup);
                vSegments = (object[])Group.Segments;
                for (j = vSegments.GetLowerBound(0); j <= vSegments.GetUpperBound(0); j++)
                {
                    ((SketchSegment)vSegments[j]).Select(false);
                }
            }
 
            swWeldFeatData.ReleaseSelectionAccess();
 
            Part.ClearSelection2(true);
        }
 
        public SldWorks swApp;
 
    }
} 
This example shows how to create structural-member groups for weldment features.

// --------------------------------------------------------------------------
// Preconditions: 
// 1. Ensure that the specified weldment profile and path exist. 
// 2. If necessary, modify the path in both calls to InsertStructuralWeldment3.
// 
// Postconditions: 
// 1. Two structural-member features are created. 
// 2. Each feature consists of one structural-member group of two 
//    sketch segments. 
// 3. Inspect the Immediate Window for information. 
//---------------------------------------------------------------------------

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System;

using System.Diagnostics;

namespace CreateStructureMemberGroup_CSharp.csproj

{

    partial class SolidWorksMacro

    {

        ModelDoc2 Part;

        bool boolstatus;

        FeatureManager FeatMgr;

        SelectionMgr SelMgr;

        Feature swWeldFeat;

        StructuralMemberFeatureData swWeldFeatData;

 

        public void Main()

        {

            string MacroFolder = null;

            MacroFolder = swApp.GetCurrentMacroPathFolder();

            swApp.SetCurrentWorkingDirectory(MacroFolder);

            string Template = null;

            Template = swApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);

            Part = (ModelDoc2)swApp.NewDocument(Template, 0, 0, 0);

            FeatMgr = Part.FeatureManager;

            SelMgr = (SelectionMgr)Part.SelectionManager;

            Part.ClearSelection2(true);

            object vSkLines = null;

            vSkLines = Part.SketchManager.CreateCornerRectangle(-0.1872393706766, 0.1133237194389, 0, -0.07003610048208, 0.009188409684237, 0);

            Part.ClearSelection2(true);

            vSkLines = Part.SketchManager.CreateCornerRectangle(0.06513561531715, 0.03369083550887, 0, 0.1807053904567, -0.08106219210316, 0);

            Part.ClearSelection2(true);

            Part.SketchManager.InsertSketch(true);

            Part.ViewZoomtofit2();

            Feature myFeature = default(Feature);

            myFeature = Part.FeatureManager.InsertWeldmentFeature();

            StructuralMemberGroup Group1 = default(StructuralMemberGroup);

            Group1 = FeatMgr.CreateStructuralMemberGroup();

            SketchSegment[] segments1 = new SketchSegment[2];

            StructuralMemberGroup[] GroupArray1 = new StructuralMemberGroup[1];

            boolstatus = Part.Extension.SelectByID2("Line1@Sketch1", "EXTSKETCHSEGMENT", -0.1495427140733, 0.1133237194389, 0, false, 0, null, 0);

            boolstatus = Part.Extension.SelectByID2("Line2@Sketch1", "EXTSKETCHSEGMENT", -0.1872393706766, 0.08238014634844, 0, true, 0, null, 0);

            segments1[0] = (SketchSegment)SelMgr.GetSelectedObject6(1, 0);

            segments1[1] = (SketchSegment)SelMgr.GetSelectedObject6(2, 0);

            Group1.Segments = segments1;

            GroupArray1[0] = Group1;

            myFeature = Part.FeatureManager.InsertStructuralWeldment3("C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\lang\\english\\weldment profiles\\ansi inch\\c channel\\3 x 5.sldlfp", 1, 0, false, GroupArray1);

            Part.ClearSelection2(true);

            StructuralMemberGroup Group2 = default(StructuralMemberGroup);

            Group2 = FeatMgr.CreateStructuralMemberGroup();

            SketchSegment[] segments2 = new SketchSegment[2];

            StructuralMemberGroup[] GroupArray2 = new StructuralMemberGroup[1];

            boolstatus = Part.Extension.SelectByID2("Line5@Sketch1", "EXTSKETCHSEGMENT", 0.1185825251083, 0.03369083550887, 0, false, 0, null, 0);

            boolstatus = Part.Extension.SelectByID2("Line6@Sketch1", "EXTSKETCHSEGMENT", 0.06513561531715, -0.02774616865332, 0, true, 0, null, 0);

            segments2[0] = (SketchSegment)SelMgr.GetSelectedObject6(1, 0);

            segments2[1] = (SketchSegment)SelMgr.GetSelectedObject6(2, 0);

            Group2.Segments = segments2;

            GroupArray2[0] = Group2;

            myFeature = Part.FeatureManager.InsertStructuralWeldment3("C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\lang\\english\\weldment profiles\\ansi inch\\c channel\\3 x 5.sldlfp", 1, 0, false, GroupArray2);

            Part.ClearSelection2(true);

            // Get Group Information 

            StructuralMemberGroup Group = default(StructuralMemberGroup);

            Object[] vGroups = null;

            Object[] vSegments = null;

            SketchSegment skSegment = default(SketchSegment);

            boolstatus = Part.Extension.SelectByID2("Structural Member1", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);

            swWeldFeat = (Feature)SelMgr.GetSelectedObject6(1, 0);

            swWeldFeatData = (StructuralMemberFeatureData)swWeldFeat.GetDefinition();

            swWeldFeatData.AccessSelections(Part, null);

            Debug.Print("");

            Debug.Print("Groups Count : " + swWeldFeatData.GetGroupsCount());

            Debug.Print(" Feature Name : " + swWeldFeat.Name);

            vGroups = (Object[])swWeldFeatData.Groups;

            long i = 0;

            long j = 0;

            for (i = vGroups.GetLowerBound(0); i <= vGroups.GetUpperBound(0); i++)

            {

                Group = (StructuralMemberGroup)vGroups[i];

                Debug.Print(" Segment Count in Group " + i + 1 + " : " + Group.GetSegmentsCount());

                Debug.Print(" Rotational angle of group: " + Group.Angle.ToString());

                vSegments = (Object[])Group.Segments;

                for (j = vSegments.GetLowerBound(0); j <= vSegments.GetUpperBound(0); j++)

                {

                    skSegment = (SketchSegment)vSegments[j];

                    skSegment.Select(false);

                }

            }

            swWeldFeatData.ReleaseSelectionAccess();

            boolstatus = Part.Extension.SelectByID2("Structural Member2", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);

            swWeldFeat = (Feature)SelMgr.GetSelectedObject6(1, 0);

            swWeldFeatData = (StructuralMemberFeatureData)swWeldFeat.GetDefinition();

            swWeldFeatData.AccessSelections(Part, null);

            Debug.Print("");

            Debug.Print("Groups Count : " + swWeldFeatData.GetGroupsCount());

            Debug.Print(" Feature Name : " + swWeldFeat.Name);

            vGroups = (Object[])swWeldFeatData.Groups;

            for (i = vGroups.GetLowerBound(0); i <= vGroups.GetUpperBound(0); i++)

            {

                Group = (StructuralMemberGroup)vGroups[i];

                Debug.Print(" Segment Count in Group " + i + 1 + " : " + Group.GetSegmentsCount());

                Debug.Print(" Rotational angle of group: " + Group.Angle.ToString());

                vSegments = (Object[])Group.Segments;

                for (j = vSegments.GetLowerBound(0); j <= vSegments.GetUpperBound(0); j++)

                {

                    skSegment = (SketchSegment)vSegments[j];

                    skSegment.Select(false);

                }

            }

            swWeldFeatData.ReleaseSelectionAccess();

        }

        public SldWorks swApp;

    }

}
This example shows how to expand a component in the specified FeatureManager design tree pane.

//-------------------------------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\pdmworks\speaker.sldasm.
// 2. Select speaker_frame<1> in the FeatureManager design
//    tree.
//
// Postconditions:
// 1. Expands the selected component in the top pane of the 
//    FeatureManager design tree.
// 2. Examine the top pane of the FeatureManager design tree
//    and the Immediate window.
//
// NOTE: Because this assembly is used elsewhere, do not
// save changes.
//--------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            AssemblyDoc swAssy = default(AssemblyDoc);
            SelectionMgr swSelMgr = default(SelectionMgr);
            Feature swFeat = default(Feature);
            Component2 swComp = default(Component2);
            FeatureManager swFeatMgr = default(FeatureManager);
            string featName = null;
            bool status = false;
 
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swAssy = (AssemblyDoc)swModel;
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            swComp = (Component2)swSelMgr.GetSelectedObjectsComponent4(1, -1);
            swFeat = (Feature)swAssy.FeatureByName("speaker_frame-1");
            swFeat = (Feature)swComp.FeatureByName("Cut-Extrude1");
            featName = swFeat.Name;
            swFeatMgr = (FeatureManager)swModel.FeatureManager;
            status = swFeatMgr.ExpandFeature(swComp, featName, (int)swFeatMgrPane_e.swFeatMgrPaneTop);
            Debug.Print("Selected component expanded in top pane of FeatureManager design tree? " + status);
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
In CAM drilling operations, it might be useful to deduce the appearance of an item before machining begins. This is slightly different than calculating the minimum amount of raw material required, i.e., the stock size. This example shows how to use some of the geometry- and topology-related methods and properties to fill all holes in a part.

//--------------------------------------------------------------------------
// Preconditions:  Open public_documents\samples\tutorial\api\cover_datum.sldrpt.
//
// Postconditions:
// 1. Creates a new part.
// 2. Fills the holes in the new part.
// 3. Click the surface-imported and thicken features, which were created
//    by filling the holes, in the FeatureManager design tree and examine
//    the part after each click.
//
// NOTE: Because the part is used elsewhere, do not save changes.
//--------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            PartDoc swPart = default(PartDoc);
            Body2 swBody = default(Body2);
            Face2 swFace = default(Face2);
            Loop2 swLoop = default(Loop2);
            object[] vEdgeArr = null;
            Curve[] swCurve = new Curve[1];
            object[] vCurveArr = null;
            Edge swEdge = default(Edge);
            Body2 swTempBody = default(Body2);
            Surface swSurf = default(Surface);
            Surface swSurfCopy = default(Surface);
            string sPartTemplateName = null;
            ModelDoc2 swNewModel = default(ModelDoc2);
            PartDoc swNewPart = default(PartDoc);
            Feature[] swFeats = new Feature[1];
            Feature swFeat = default(Feature);
            Feature swKnitFeat = default(Feature);
            Feature swThickFeat = default(Feature);
            FeatureManager swNewFeatMgr = default(FeatureManager);
            int i = 0;
            bool bRet = false;
            object[] vBodies = null;
 
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swPart = (PartDoc)swModel;
 
            vBodies = (object[])swPart.GetBodies2((int)swBodyType_e.swSolidBody, false);
            swBody = (Body2)vBodies[0];
 
            // Create new part
            sPartTemplateName = swApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            swNewModel = (ModelDoc2)swApp.NewDocument(sPartTemplateName, (int)swDwgPaperSizes_e.swDwgPaperAsize, 0.0, 0.0);
            swNewFeatMgr = (FeatureManager)swNewModel.FeatureManager;
            swNewPart = (PartDoc)swNewModel;
 
            swFace = (Face2)swBody.GetFirstFace();
            while ((swFace != null))
            {
                swLoop = (Loop2)swFace.GetFirstLoop();
                while ((swLoop != null))
                {
                    if (swLoop.IsOuter())
                    {
                        vEdgeArr = (object[])swLoop.GetEdges();
                        if ((vEdgeArr.GetUpperBound(0)) >= 0)
                        {
                            Array.Resize(ref swCurve, (vEdgeArr.GetUpperBound(0) + 1));
 
                            for (i = 0; i <= (vEdgeArr.GetUpperBound(0)); i++)
                            {
                                swEdge = (Edge)vEdgeArr[i];
                                swCurve[i] = (Curve)swEdge.GetCurve();
                            }
                            vCurveArr = (Curve[])swCurve;
                            swSurf = (Surface)swFace.GetSurface();
                            swSurfCopy = (Surface)swSurf.Copy();
                            swTempBody = (Body2)swSurfCopy.CreateTrimmedSheet4((vCurveArr), false);
 
                            // Typically nothing is returned if the loop is
                            // perpendicular to the surface, as in the
                            // end loops of a cylinder
 
                            if ((swTempBody != null))
                            {
                                // Sheet body only has one face
                                swFeat = (Feature)swNewPart.CreateFeatureFromBody3(swTempBody, false, (int)swCreateFeatureBodyOpts_e.swCreateFeatureBodyCheck);
                                swFeats[swFeats.GetUpperBound(0)] = swFeat;
                                Debug.Assert((swFeats[swFeats.GetUpperBound(0)] != null));
                                Array.Resize(ref swFeats, (swFeats.GetUpperBound(0)) + 2);
                            }
                        }
                    }
                    swLoop = (Loop2)swLoop.GetNext();
                }
                swFace = (Face2)swFace.GetNextFace();
            }
 
            Array.Resize(ref swFeats, (swFeats.GetUpperBound(0)));
 
            swNewModel.ClearSelection2(true);
            for (i = 0; i <= (swFeats.GetUpperBound(0)); i++)
            {
                bRet = swFeats[i].Select2(true, 1);
            }
 
            swNewFeatMgr.InsertSewRefSurface(true, false, false, 3.001639406912E-05, 0.0001);
 
            // Make sure surfaces are successfully sewn together
            swKnitFeat = (Feature)swNewModel.FeatureByPositionReverse(0);
            bRet = swKnitFeat.Select2(false, 1);
            swThickFeat = (Feature)swNewFeatMgr.FeatureBossThicken(0.00254, 0, 7471215, false, true, true, true);
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to create an optimized, normal, cut extrude in a sheet metal part.

//-------------------------------------------------------------
// Preconditions: 
// 1. Verify that the sheet metal part to open exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens the sheet metal part.
// 2. Selects a face.
// 3. Sketches a circle on the selected face.
// 4. Creates Cut-Extrude2, which is an optimized, normal, cut 
//    extrude.
// 5. Examine the FeatureManager design tree, graphics area, and
//    Immediate window.
//
// NOTE: Because the part document is used elsewhere, do not save
// changes.
//--------------------------------------------------------------
 
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            SketchManager swSketchManager = default(SketchManager);
            SketchSegment swSketchSegment = default(SketchSegment);
            FeatureManager swFeatureManager = default(FeatureManager);
            Feature swFeature = default(Feature);
            ExtrudeFeatureData2 swExtrudeFeatureData = default(ExtrudeFeatureData2);
            bool status = false;
            int errors = 0;
            int warnings = 0;
 
            swModel = (ModelDoc2)swApp.OpenDoc6("C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\2012-sm.sldprt", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);

            //Select a face
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            status = swModelDocExt.SelectByRay(-0.0287275955400048, 0.0301558252805876, 0.00509460972091347, 0.369531106281609, -0.495005022745071, -0.786394804756136, 0.00115698538052806, 2, false, 0,
            0);

            //Sketch a circle
            swSketchManager = (SketchManager)swModel.SketchManager;
            swSketchSegment = (SketchSegment)swSketchManager.CreateCircle(0.0, 0.0, 0.0, 0.004122, -0.003029, 0.0);

            //Create an optimized, normal, cut extrude
            swFeatureManager = (FeatureManager)swModel.FeatureManager;
            swFeature = (Feature)swFeatureManager.FeatureCut4(true, false, false, 1, 0, 0.01, 0.01, false, false, false,
            false, 0.0174532925199433, 0.0174532925199433, false, false, false, false, true, true, true,
            true, true, false, 0, 0, false, true);

            swModel.ClearSelection2(true);
 	    swExtrudeFeatureData = (ExtrudeFeatureData2)swFeature.GetDefinition();
	    Debug.Print("Normal cut? " + swExtrudeFeatureData.NormalCut);
	    Debug.Print("Geometry optimized? " + swExtrudeFeatureData.OptimizeGeometry);
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to insert a thin cut extrude feature. 

//------------------------------------------------------
// Preconditions: Verify that the specified part exists.
//
// Postconditions:
// 1. Opens the part.
// 2. Inserts a thin cut extrude feature in the part.
// 3. Examine the FeatureManager design tree and
//    graphics area.
//
// NOTE: Because this part document is used elsewhere,
// do not save changes.
//-----------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;

namespace FeatureCutThin2FeatureManagerCSharp.csproj
{
    partial 
 class SolidWorksMacro
    {
        public 
 void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            SketchManager swSketchManager = default(SketchManager);
            SketchSegment swSketchSegment = default(SketchSegment);
            FeatureManager swFeatureManager = default(FeatureManager);
            Feature swFeature = default(Feature);
            bool boolstatus = false;
            int errorstatus = 0;
            int warnings = 0;

            // Open part 
            swApp.OpenDoc6("C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\water.sldprt", 1, 0, "",
ref errorstatus, ref warnings);
            swModel = (ModelDoc2)swApp.ActiveDoc;


            // Select face on which to sketch a circle 
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            boolstatus = swModelDocExt.SelectByID2("", "FACE", 0.0001655362220845, -0.0477671348753, 0.072, false, 0, null, 0)

            swModel.ShowNamedView2("*Normal To", (int)swStandardViews_e.swBackView);
            swModel.ClearSelection2(true);


            // Sketch a circle 
            swSketchManager = (SketchManager)swModel.SketchManager;
            swSketchSegment = (SketchSegment)swSketchManager.CreateCircle(0.0, 0.0, 0.0, 0.030255, -0.042492, 0.0);
            swModel.ClearSelection2(true);


            // Create the thin cut extrude 
            boolstatus = swModelDocExt.SelectByID2("Arc1", "SKETCHSEGMENT", 0, 0, 0, false, 0, null, 0);
            swFeatureManager = (FeatureManager)swModel.FeatureManager;
            swFeature = (Feature)swFeatureManager.FeatureCutThin2(true, false, false, (int)swEndConditions_e.swEndCondBlind,
                (int)swEndConditions_e.swEndCondBlind, 0.01, 0.01, false, false, false,
                false, 0.01745329251994, 0.01745329251994, false, false, false, false, 0.01, 0.01, 0.01,
                0, 0, false, 0.005, true, true, (int)swStartConditions_e.swStartSketchPlane, 0, false);
            swModel.ShowNamedView2("*Isometric", (int)swStandardViews_e.swIsometricView);


        }


        /// <summary> 
        /// The SldWorks swApp variable is pre-assigned for you. 
        /// </summary> 
        public SldWorks swApp;


    }
}
This example shows how to insert an extruded surface in a model.

//--------------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified part template exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Creates a new part and inserts Surface-Extrude1.
// 2. Expand the Surface Bodies folder to verify that it contains:
//    * Surface-Extrude[1]
//    * Surface-Extrude[2]
//    * Surface-Extrude[3]
// 3. Examine the Immediate window and graphics area.
//---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            SketchManager swSketchManager = default(SketchManager);
            object[] sketchLines = null;
            SketchSegment swSketchSegment = default(SketchSegment);
            SelectionMgr swSelMgr = default(SelectionMgr);
            FeatureManager swFeatureManager = default(FeatureManager);
            Feature swFeature = default(Feature);
            SurfExtrudeFeatureData swSurfExtrudeFeature = default(SurfExtrudeFeatureData);
            bool status = false;
 
            swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SOLIDWORKS\\SOLIDWORKS 2017\\templates\\Part.prtdot", 0, 0, 0);
 
            //Create sketches for extruded surface feature
            swSketchManager = (SketchManager)swModel.SketchManager;
            swSketchManager.InsertSketch(true);
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            status = swModelDocExt.SelectByID2("Front Plane", "PLANE", -0.03891024234798, 0.02968528649877, 0.0003646590412283, false, 0, null, 0);
            swModel.ClearSelection2(true);
            sketchLines = (object[])swSketchManager.CreateCornerRectangle(-0.05517876768764, 0.008130204900836, 0, -0.02399076855985, -0.0155939995639, 0);
            swModel.ClearSelection2(true);
            sketchLines = (object[])swSketchManager.CreateCornerRectangle(-0.003731897331531, 0.008130204900836, 0, 0.0285223581767, -0.02998846069981, 0);
            swModel.ClearSelection2(true);
            swSketchSegment = (SketchSegment)swSketchManager.CreateCircle(0.053579, 0.013995, 0.0, 0.06819, 0.018462, 0.0);
            swModel.ClearSelection2(true);
            swSketchManager.InsertSketch(true);
            swModel.ShowNamedView2("*Trimetric", 8);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 0, null, 0);
 
            // Create a blind surface extrude 
            // in two directions from the selected sketch
            // in a direction normal to the selected sketch plane
            swFeatureManager = (FeatureManager)swModel.FeatureManager;
            swFeatureManager.FeatureExtruRefSurface3(false, false, (int)swStartConditions_e.swStartSketchPlane, 0, (int)swEndConditions_e.swEndCondBlind, (int)swEndConditions_e.swEndCondBlind, 0.01, 0.01, true, false,
            false, false, 0.4, 0, false, false, false, false, false, false,
            false, false);
            swModel.ClearSelection2(true);
 
            // Get Surface-Extrude1 feature
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            status = swModelDocExt.SelectByID2("Surface-Extrude1", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            swFeature = (Feature)swSelMgr.GetSelectedObject6(1, -1);
            swSurfExtrudeFeature = (SurfExtrudeFeatureData)swFeature.GetDefinition();
 
            //Access Surface-Extrude1 feature data
            swSurfExtrudeFeature.AccessSelections(swModel, null);
 
            Debug.Print(swFeature.Name);
            Debug.Print("  Depth:");
            Debug.Print("    Forward direction: " + swSurfExtrudeFeature.GetDepth(true));
            Debug.Print("    Reverse direction: " + swSurfExtrudeFeature.GetDepth(false));
            Debug.Print("  End condition as defined in swSurfaceExtendEndCond_e:");
            Debug.Print("    Forward direction: " + swSurfExtrudeFeature.GetEndCondition(true));
            Debug.Print("    Reverse direction: " + swSurfExtrudeFeature.GetEndCondition(false));
            Debug.Print("  Reverse offset enabled:");
            Debug.Print("    Forward direction? " + swSurfExtrudeFeature.GetReverseOffset(true));
            Debug.Print("    Reverse direction? " + swSurfExtrudeFeature.GetReverseOffset(false));
            Debug.Print("  Translate surface setting enabled:");
            Debug.Print("    Forward direction? " + swSurfExtrudeFeature.GetTranslateSurface(true));
            Debug.Print("    Reverse direction? " + swSurfExtrudeFeature.GetTranslateSurface(false));
            Debug.Print("  Surface extruded in both directions? " + swSurfExtrudeFeature.BothDirections);
            Debug.Print("  Extrusion reversed? " + swSurfExtrudeFeature.ReverseDirection);
            Debug.Print("  Direction 1 end:");
            Debug.Print("    Capped? " + swSurfExtrudeFeature.D1CapEnd);
            Debug.Print("    Drafted? " + swSurfExtrudeFeature.D1DraftOn);
            if (swSurfExtrudeFeature.D1DraftOn)
            {
                Debug.Print("      Angle: " + swSurfExtrudeFeature.D1DraftAngle);
                Debug.Print("      Inward (false) or outward (true)? " + swSurfExtrudeFeature.D1DraftOutward);
            }
            Debug.Print("  Direction 2 end:");
            Debug.Print("    Capped? " + swSurfExtrudeFeature.D2CapEnd);
            Debug.Print("    Drafted? " + swSurfExtrudeFeature.D2DraftOn);
            if (swSurfExtrudeFeature.D2DraftOn)
            {
                Debug.Print("      Angle: " + swSurfExtrudeFeature.D2DraftAngle);
                Debug.Print("      Inward (false) or outward (true)? " + swSurfExtrudeFeature.D2DraftOutward);
            }
            Debug.Print("  Delete original face? " + swSurfExtrudeFeature.DeleteOriginalFace);
            Debug.Print("  Knit extrusion result? " + swSurfExtrudeFeature.KnitResult);
 
            //Release Surface-Extrude1 feature data
            swSurfExtrudeFeature.ReleaseSelectionAccess();
 
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to create an extrusion feature.

//----------------------------------------------------------------------------
// Preconditions: Verify that the specified part template exists.
//
// Postconditions: 
// 1. Creates a Boss-Extrude1 feature.
// 2. Examine the FeatureManager design tree and graphics area.
// ---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
namespace CreateExtrusionFeature_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        Feature myFeature;
        ModelDoc2 Part;
        RefPlane myRefPlane;

        bool boolstatus;

        public void Main()
        {
            Part = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SOLIDWORKS\\SOLIDWORKS 2016\\templates\\Part.prtdot", 0, 0, 0);
            Part = (ModelDoc2)swApp.ActiveDoc;

            boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0);
            myRefPlane = (RefPlane)Part.FeatureManager.InsertRefPlane(8, 0.01, 0, 0, 0, 0);
            boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0);
            myRefPlane = (RefPlane)Part.FeatureManager.InsertRefPlane(8, 0.02, 0, 0, 0, 0);

            boolstatus = Part.Extension.SelectByID2("Plane2", "PLANE", 0, 0, 0, false, 0, null, 0);
            object vSkLines = null;
            vSkLines = Part.SketchManager.CreateCornerRectangle(-0.0250462141853123, 0.0157487558892494, 0, 0.0275128867944718, -0.015559011842391, 0);

            Part.SketchManager.InsertSketch(true);

            // Sketch to extrude
            boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 0, null, 0);
            // Start condition reference
            boolstatus = Part.Extension.SelectByID2("Plane2", "PLANE", 0.00105020593408751, -0.00195369982668282, 0.0248175428318827, true, 32, null, 0);
            // End condition reference
            boolstatus = Part.Extension.SelectByID2("Plane1", "PLANE", 0.0068370744701368, -0.004419862088339, 0.018892268568016, true, 1, null, 0);

            // Boss extrusion start condition reference is Plane2, and the extrusion end is offset 3 mm from the end condition reference, Plane1
            myFeature = (Feature)Part.FeatureManager.FeatureExtrusion3(true, false, true, (int)swEndConditions_e.swEndCondOffsetFromSurface, 0, 0.003, 0.003, false, false, false,
            false, 0.0174532925199433, 0.0174532925199433, false, false, false, false, true, true, true,
            (int)swStartConditions_e.swStartSurface, 0, false);

        }

        public SldWorks swApp;

    }
}
This example shows how to create a variable radius asymmetric elliptical fillet and get its data.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\api\block.sldprt.
// 2. Open an Immediate window.
//
// Postconditions:
// 1. Creates a variable radius asymmetric elliptical fillet, VarFillet1, 
//    in the FeatureManager design tree.
// 2. Inspect the Immediate window.
//
// NOTE: Because the model is used elsewhere, do not save changes.
// ---------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
namespace FeatureFillet3_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        ModelDoc2 swModel;
        SelectionMgr swSelMgr;
        Feature myFeature;
        Edge swedge;
        Vertex ver1;
        Vertex ver2;
        VariableFilletFeatureData2 swFeatData;
        int Fillet_ProfileTyp;
        double[] dists26 = new double[2];
        double AsyRadius1;
        double AsyRadius2;
        double AsyRadius3;
        double AsyRadius4;
        bool boolstatus;
        double[] radiis = new double[2];
        object radiiArray0;
        object conicRhosArray0;
        object setBackArray0;
        object pointArray0;
        object pointRhoArray0;
        object dist2Array0;
        object pointDist2Array0;

        public void Main()
        {

            swModel = (ModelDoc2)swApp.ActiveDoc;
            swSelMgr = (SelectionMgr)swModel.SelectionManager;

            radiis[0] = 0.008;
            radiis[1] = 0.009;
            radiiArray0 = radiis;
            dists26[0] = 0.006;
            dists26[1] = 0.007;
            dist2Array0 = dists26;

            conicRhosArray0 = 0;
            setBackArray0 = 0;
            pointArray0 = 0;
            pointRhoArray0 = 0;
            pointDist2Array0 = 0;
 

            boolstatus = swModel.Extension.SelectByID2("", "EDGE", 1.66068305868521E-02, -4.40742070395572E-06, -1.49970056632469E-02, true, 1, null, 0); 


            if (boolstatus == false)
                ErrorMsg(swApp, "Failed to select edge");

            myFeature = (Feature)swModel.FeatureManager.FeatureFillet3((int)swFeatureFilletOptions_e.swFeatureFilletAsymmetric + (int)swFeatureFilletOptions_e.swFeatureFilletKeepFeatures + (int)swFeatureFilletOptions_e.swFeatureFilletAttachEdges + (int)swFeatureFilletOptions_e.swFeatureFilletUniformRadius + (int)swFeatureFilletOptions_e.swFeatureFilletPropagate, 0, 0, 0, (int)swFeatureFilletType_e.swFeatureFilletType_VariableRadius, (int)swFilletOverFlowType_e.swFilletOverFlowType_Default, (int)swFeatureFilletProfileType_e.swFeatureFilletCircular, (radiiArray0), (dist2Array0), (conicRhosArray0),
            (setBackArray0), (pointArray0), (pointDist2Array0), (pointRhoArray0));
            if (myFeature == null)
                ErrorMsg(swApp, "Failed to create fillet");

            swFeatData = (VariableFilletFeatureData2)myFeature.GetDefinition();
            if (swFeatData == null)
                ErrorMsg(swApp, "Failed to get definition for fillet feature");

            boolstatus = swFeatData.AccessSelections(swModel, null);
            if (boolstatus == false)
                ErrorMsg(swApp, "Failed to access selections for fillet feature");

            boolstatus = swFeatData.AsymmetricFillet;
            if (boolstatus == false)
                ErrorMsg(swApp, "Fillet is not asymmetric");
            Debug.Print("Variable size fillet is asymmetric? " + boolstatus);

            swedge = (Edge)swFeatData.GetFilletEdgeAtIndex(0);
            if (swedge == null)
                ErrorMsg(swApp, "Failed to get edge");

            ver1 = (Vertex)swedge.GetStartVertex();
            if (ver1 == null)
                ErrorMsg(swApp, "Failed to get start vertex of edge");

            ver2 = (Vertex)swedge.GetEndVertex();
            if (ver2 == null)
                ErrorMsg(swApp, "Failed to get end vertex of edge");

            AsyRadius1 = swFeatData.GetRadius2(ver1, out boolstatus);
            if (AsyRadius1 != 0.008)
                ErrorMsg(swApp, "Radius R1 at vertex V1 is wrong");
            Debug.Print("Radius R1 at vertex V1: " + AsyRadius1);

            AsyRadius2 = swFeatData.GetDistance(ver1);
            if (AsyRadius2 != 0.006)
                ErrorMsg(swApp, "Radius R2 at vertex V1 is wrong");
            Debug.Print("Radius R2 at vertex V1: " + AsyRadius2);

            AsyRadius3 = swFeatData.GetRadius2(ver2, out boolstatus);
            if (AsyRadius3 != 0.009)
                ErrorMsg(swApp, "Radius R1 for vertex V2 is wrong");
            Debug.Print("Radius R1 at vertex V2: " + AsyRadius3);

            AsyRadius4 = swFeatData.GetDistance(ver2);
            if (AsyRadius4 != 0.007)
                ErrorMsg(swApp, "Radius R2 for vertex V2 is wrong");
            Debug.Print("Radius R2 at vertex V2: " + AsyRadius4);


            Fillet_ProfileTyp = swFeatData.ConicTypeForCrossSectionProfile;
            if (Fillet_ProfileTyp != 0)
                ErrorMsg(swApp, "Profile type is not elliptical");
            Debug.Print("Fillet profile type as defined in swFeatureFilletProfileType_e (0 = Elliptical): " + Fillet_ProfileTyp);

            swFeatData.ReleaseSelectionAccess();

        }


        public void ErrorMsg(SldWorks SwApp, string Message)
        {
            SwApp.SendMsgToUser2(Message, 0, 0);
            SwApp.RecordLine("'*** WARNING - General");
            SwApp.RecordLine("'*** " + Message);
            SwApp.RecordLine("");
        }

        public SldWorks swApp;

    }
} 
This example shows how to create revolve features.

//----------------------------------------------------------------------------
// Preconditions: 
// 1. Open a new part document.
// 2. Rename the namespace to match your C# project.
//
// Postconditions: Two revolve features and one cut-revolve feature are created.
//----------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
namespace FeatureRevolves_CSharp.csproj
{
    partial class SolidWorksMacro
    {
        ModelDoc2 swModel;
        ModelDocExtension swModelDocExt;
        FeatureManager swFeatMgr;
        SelectionMgr swSelMgr;

        bool boolstatus;

        public void Main()
        {
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModelDocExt = swModel.Extension;
            swSelMgr = (SelectionMgr)swModel.SelectionManager;

            // Create an axis
            boolstatus = swModelDocExt.SelectByID2("Right Plane", "PLANE", 0, 0, 0, true, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            boolstatus = swModelDocExt.SelectByID2("Top Plane", "PLANE", 0, 0, 0, true, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            swModel.InsertAxis2(true);

            // Create a rectangle
            boolstatus = swModelDocExt.SelectByID2("Top Plane", "PLANE", -0.08954836342753, 0.0004336873289503, 0.006720765739942, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            swModel.InsertSketch2(true);
            swModel.ClearSelection2(true);
            swModel.SketchRectangle(-0.05668466821757, -0.02198379306525, 0, -0.01330857427717, 0.03972855876814, 0, true);

            // Create the first revolve feature
            swModel.InsertSketch2(true);
            swModel.ShowNamedView2("*Trimetric", 8);
           
            boolstatus = swModelDocExt.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            boolstatus = swModelDocExt.SelectByID2("Axis1", "AXIS", 0, 0, 0, true, 16, null, (int)swSelectOption_e.swSelectOptionDefault);
            swFeatMgr = swModel.FeatureManager;
          
            swFeatMgr.FeatureRevolve2(true, true, false, false, false, false, 0, 0, 6.28318530718, 0, false,
            false, 0.01, 0.01, 0, 0, 0, true, true, true);

            // Create a cut-revolve feature using a face on the revolve feature
            swSelMgr.EnableContourSelection = false;
            boolstatus = swModelDocExt.SelectByID2("", "FACE", -0.03095803920934, 0.01509536510872, 0.02198379306526, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            swModel.InsertSketch2(true);
            swModel.ClearSelection2(true);
            swModel.SketchRectangle(-0.04194874421597, 0.01774859621099, 0, -0.01883036471929, -0.01265654504095, 0, true);
            swModel.InsertSketch2(true);
           
            boolstatus = swModelDocExt.SelectByID2("Sketch2", "SKETCH", 0, 0, 0, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            boolstatus = swModelDocExt.SelectByID2("Line4@Sketch2", "EXTSKETCHSEGMENT", -0.01883036471929, 0.003802500010693, 0, true, 4, null, (int)swSelectOption_e.swSelectOptionDefault);
            swFeatMgr.FeatureRevolveCut(6.26573201466, false, 0, 0, 0, true, true);

            // Create the second revolve feature using a face on the first revolve feature
            swSelMgr.EnableContourSelection = false;
            boolstatus = swModelDocExt.SelectByID2("", "FACE", -0.02333512246603, 0.03472018719853, 0.0219837930652, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            swModel.InsertSketch2(true);
            swModel.ClearSelection2(true);
            swModel.CreateCircle2(-0.02232361399104, 0.03354683337932, 0, -0.01445073476016, 0.02795861773112, 0);
            swModel.InsertSketch2(true);
           
            boolstatus = swModelDocExt.SelectByID2("Sketch3", "SKETCH", 0, 0, 0, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            boolstatus = swModelDocExt.SelectByRay(-1.81956067901865E-02, 1.80455411334037E-02, 2.17820530671702E-02, -0.400036026779312, -0.515038074910024, -0.758094294050284, 9.91972972972973E-04, 1, False, 4, 0);
            swFeatMgr.FeatureRevolve2(true, true, false, false, false, false, 0, 0, 6.28318530718, 0, false,
            false, 0.01, 0.01, 0, 0, 0, true, true, true);
            swSelMgr.EnableContourSelection = false;

        }

        public SldWorks swApp;

    }
} 
This example shows how to create a thin feature revolve in two directions.

//----------------------------------------------------------------------------
// Preconditions: Open public_documents\samples\tutorial\api\Multiple Planar_Faces2.sldprt.
//
// Postconditions:
// 1. Creates a thin feature revolve in two directions.
// 2. Examine the graphics area and FeatureManager design tree.
//
// NOTE: Because the model is used elsewhere, do not save changes
//---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
namespace ThinFeatureRevolve_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        public void main()
        {
            ModelDoc2 Part = default(ModelDoc2);
            bool boolstatus = false;

            Part = (ModelDoc2)swApp.ActiveDoc;

            boolstatus = Part.Extension.SelectByID2("Sketch2", "SKETCH", 0, 0, 0, true, 0, null, 0);
            boolstatus = Part.Extension.SelectByID2("Axis1", "AXIS", -0.03249248386774, -0.008890295497245, -0.005457395402805, true, 16, null, 0);
            boolstatus = Part.Extension.SelectByID2("", "FACE", -0.03948753408952, 0.1016773485926, -0.08343298757264, true, 32, null, 0);

            Feature myFeature = default(Feature);
            myFeature = Part.FeatureManager.FeatureRevolve2(false, true, true, false, false, true, 4, 5, 6.28318530718, 0,
            false, true, 0.01, 0.01, 0, 0.002, 0.01, true, true, true);

        }

        public SldWorks swApp;
    }
} 
This example shows how to create a 360° revolve feature.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Open a part document that contains Axis1
//    and Sketch1 features; Sketch1 must be a rectangle and Axis1
//    must have been created using an edge on the rectangle.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Creates a 360° revolve feature.
// 2. Examine the Immediate window, graphics area, and FeatureManager
//    design tree.
//---------------------------------------------------------------------------
	using Microsoft.VisualBasic;
	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.Data;
	using System.Diagnostics;
	using SolidWorks.Interop.sldworks;
	using SolidWorks.Interop.swconst;
	using System.Runtime.InteropServices;
	namespace RevolveFeatDataType_CSharp.csproj
	{
	    partial class SolidWorksMacro
	    {
	        ModelDoc2 swModel;
	        ModelDocExtension swModelDocExt;
	        FeatureManager swFeatMgr;
	        Feature swFeat;
	        RevolveFeatureData2 swRevolveFeat;
	        bool boolstatus;
	        public void Main()
	        {
	            swModel = (ModelDoc2)swApp.ActiveDoc;
	            swModelDocExt = swModel.Extension;
	            boolstatus = swModelDocExt.SelectByID2("Axis1", "AXIS", 0, 0, 0, false, 
	16, null, 
	0);
	            boolstatus = swModelDocExt.SelectByID2("Sketch1", "SKETCH", 
	0, 0, 0, true, 
	0, null, 
	0);
	            swFeatMgr = swModel.FeatureManager;
	            swFeat = swFeatMgr.FeatureRevolve2(true, true, false, false, false, false, 0, 
	0, 6.2831853071796, 0,
	            false, false, 
	0.01, 0.01, 0, 0, 0, true, true, true);
	            swModel.ViewZoomtofit2();
	            swRevolveFeat = (RevolveFeatureData2)swFeat.GetDefinition();
	            // Set the type of revolve as 
	defined in swRevolveType_e
	            Debug.Print("Revolve feature type before setting to 5: " + swRevolveFeat.Type.ToString());
	            swRevolveFeat.Type = 5;
	            boolstatus = swFeat.ModifyDefinition(swRevolveFeat, swModel, null);
	            Debug.Print("Revolve feature type after setting to 5: " + swRevolveFeat.Type.ToString());
	        }
	        public SldWorks swApp;
	    }
	} 
This example shows how to create a temporary loft body using IModeler::CreateLoftBody2.

//-----------------------------------------------------
// Preconditions:
// 1. Verify that the specified part document template
//    exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens a new part document.
// 2. Creates and selects sketches of two profiles and
//    a guide curve.
// 3. Creates a temporary loft body.
// 4. Examine the Immediate window and graphics area.
//-----------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace CreateLoftCSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            SketchManager swSketchMgr = default(SketchManager);
            SketchSegment sketchSegment = default(SketchSegment);
            SelectionMgr swSelMgr = default(SelectionMgr);
            SketchPoint sketchPoint = default(SketchPoint);
            FeatureManager swFeatureMgr = default(FeatureManager);
            RefPlane refPlane = default(RefPlane);
            Feature swFeat = default(Feature);
            bool status = false;
            object profiles = null;
            object guides = null;
            Feature[] profile = new Feature[2];
            Feature[] guideCurve = new Feature[1];
            Modeler swModeler = default(Modeler);
            Body2 swBody = default(Body2);
            int count = 0;
            object[] featArr = null;
            int i = 0;
 
            //Open new part document
            swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SolidWorks 2014\\templates\\Part.prtdot", 0, 0, 0);
            swModelDocExt = (ModelDocExtension)swModel.Extension;
 
            //Create closed profile
            status = swModelDocExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            swSketchMgr = (SketchManager)swModel.SketchManager;
            sketchSegment = (SketchSegment)swSketchMgr.CreateCircle(0.0, 0.0, 0.0, 0.021796, -0.030937, 0.0);
            sketchPoint = (SketchPoint)swSketchMgr.CreatePoint(0.023454, 0.029699, 0.0);
            swModel.ClearSelection2(true);
            swSketchMgr.InsertSketch(true);
 
            //Create another closed profile
            status = swModelDocExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0);
            swFeatureMgr = (FeatureManager)swModel.FeatureManager;
            refPlane = (RefPlane)swFeatureMgr.InsertRefPlane(8, 0.254, 0, 0, 0, 0);
            status = swModelDocExt.SelectByID2("Plane1", "PLANE", 0, 0, 0, false, 0, null, 0);
            sketchSegment = (SketchSegment)swSketchMgr.CreateCircle(-0.035118, -0.014102, 0.0, -0.025452, -0.02953, 0.0);
            sketchPoint = (SketchPoint)swSketchMgr.CreatePoint(-0.018033, -0.020392, 0.0);
            swModel.ClearSelection2(true);
            swSketchMgr.InsertSketch(true);
 
            //Create guide curve
            status = swModelDocExt.SelectByID2("Point4@Sketch1", "EXTSKETCHPOINT", 0.0234541440502721, 0.0296993303358475, 0, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("Point5@Sketch2", "EXTSKETCHPOINT", -0.0180330744027628, -0.0203923494843098, 0, true, 0, null, 0);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("Point4@Sketch1", "EXTSKETCHPOINT", 0.0234541440502721, 0.0296993303358475, 0, false, 1, null, 0);
            status = swModelDocExt.SelectByID2("Point5@Sketch2", "EXTSKETCHPOINT", -0.0180330744027628, -0.0203923494843098, 0, true, 1, null, 0);
            swModel.Insert3DSplineCurve(false);
            swModel.ClearSelection2(true);
 
            //Select guide curve and profiles for loft feature
            status = swModelDocExt.SelectByID2("Curve1", "REFERENCECURVES", 0, 0, 0, false, 2, null, 0);
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            swFeat = (Feature)swSelMgr.GetSelectedObject6(1, -1);
            Debug.Print("Guide curve name: " + swFeat.Name);
            guideCurve[0] = (Feature)swFeat;
            guides = guideCurve;
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("Sketch1", "SKETCH", 0.00984860021145358, 0.0365397341178567, 0, true, 1, null, 0);
            swFeat = (Feature)swSelMgr.GetSelectedObject6(1, -1);
            Debug.Print("Profile name: " + swFeat.Name);
            profile[0] = (Feature)swFeat;
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("Sketch2", "SKETCH", -0.0401969362026636, 0.00338231877308527, 0, true, 1, null, 0);
            swFeat = (Feature)swSelMgr.GetSelectedObject6(1, -1);
            Debug.Print("Profile name: " + swFeat.Name);
            profile[1] = (Feature)swFeat;
            profiles = profile;
            swModel.ClearSelection2(true);
 
            //Create temporary loft body
            swModeler = (Modeler)swApp.GetModeler();
            swBody = (Body2)swModeler.CreateLoftBody2(swModel, profiles, guides, null, false, 0, 0, 0, true, false,
            true, false, true, 1, 1, 1, true, true, 1, 1,
            false);
 
            // Test whether the loft body is a temporary body
            status = swBody.IsTemporaryBody();
            Debug.Print("Is the loft body a temporary body?  " + status);
            if (status)
            {
                // Display the temporary loft body
                swBody.Display3(swModel, 256, (int)swTempBodySelectOptions_e.swTempBodySelectOptionNone);
                Debug.Print("Temporary loft body displayed; examine the graphics area.");
            }
            else
            {
                Debug.Print("Temporary loft body was not created.");
            }
 
            Debug.Print("");
 
            //Verify that the temporary loft body is not a loft feature
            //by examining the list of features printed to the
            //Immediate window
            count = swFeatureMgr.GetFeatureCount(false);
            featArr = (object[])swFeatureMgr.GetFeatures(false);
            for (i = 0; i < count - 1; i++)
            {
                swFeat = (Feature)featArr[i];
                Debug.Print(swFeat.Name);
            }
 
            swModel.ViewZoomtofit2();
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to get the flat-pattern folder and its contents.

//----------------------------------------------------------------------------
// Preconditions: Open a multibody sheet metal part that has a folder
// of flat-patterns.
//
// Postconditions: Inspect the Immediate window.
// ---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
namespace GetFlatPatternFolderFeature_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        ModelDoc2 myModel;
        FeatureManager featureMgr;
        Feature feat;
        object[] featArray;

        int i;

        public void Main()
        {
            myModel = (ModelDoc2)swApp.ActiveDoc;
            featureMgr = myModel.FeatureManager;
            FlatPatternFolder flatPatternFolder = default(FlatPatternFolder);
            flatPatternFolder = (FlatPatternFolder)featureMgr.GetFlatPatternFolder();
            feat = flatPatternFolder.GetFeature();
            Debug.Print("Flat-pattern folder name: " + feat.Name);
            Debug.Print("  Number of flat-pattern features in the folder: " + flatPatternFolder.GetFlatPatternCount());
            featArray = (object[])flatPatternFolder.GetFlatPatterns();
            for (i = featArray.GetLowerBound(0); i <= featArray.GetUpperBound(0); i++)
            {
                feat = (Feature)featArray[i];
                Debug.Print("    " + feat.Name);
            }

        }


        public SldWorks swApp;

    }
} 

This example shows how to get the sheet metal folder and its contents.

//----------------------------------------------------------------------------
// Preconditions: Open a multibody sheet metal part that has a folder
// of sheet metal features.
//
// Postconditions: Inspect the Immediate window.
// ---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
namespace GetSheetMetalFolder_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        ModelDoc2 myModel;
        FeatureManager featureMgr;
        Feature feat;
        SheetMetalFolder sheetMetalFolder;
        object[] featArray;

        int i;

        public void Main()
        {
            myModel = (ModelDoc2)swApp.ActiveDoc;
            featureMgr = myModel.FeatureManager;

            sheetMetalFolder = (SheetMetalFolder)featureMgr.GetSheetMetalFolder();
            feat = (Feature)sheetMetalFolder.GetFeature();
            Debug.Print("Sheet metal folder name: " + feat.Name);
            Debug.Print("  Number of sheet metal features in the folder: " + sheetMetalFolder.GetSheetMetalCount());
            featArray = (object[])sheetMetalFolder.GetSheetMetals();
            for (i = featArray.GetLowerBound(0); i <= featArray.GetUpperBound(0); i++)
            {
                feat = (Feature)featArray[i];
                Debug.Print("    " + feat.Name);
            }
        }

        public SldWorks swApp;
    }
} 
This example shows how to create a hole using the hole wizard.

//--------------------------------- ---------------------------
// Preconditions: Verify that the part template exists. 
// 
// Postconditions: 
// 1. Creates a part.
// 2. Inserts a hole in the part using the hole wizard.
// 3. Examine the graphics area and FeatureManager design tree.
//-------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
namespace Macro1CSharp.csproj
{
    partial class SolidWorksMacro
    {
        public void Main()
        {
             ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            FeatureManager swFeatMgr = default(FeatureManager);
            Feature swFeat = default(Feature);
            SketchManager swSketchMgr = default(SketchManager);
            object sketchLines = null;
            int status = 0;
            bool boolstatus = false;
            double[] P1 = new double[3];
            double[] P2 = new double[3];
            double[] P3 = new double[3];
            //Create the model for the wizard hole 
            swApp.ResetUntitledCount(0, 0, 0);
            swModel = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SOLIDWORKS\\SOLIDWORKS 2019\\templates\\Part.prtdot", 0, 0, 0);
            swApp.ActivateDoc2("Part1", false, ref status);
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swSketchMgr = swModel.SketchManager;
            swModelDocExt = swModel.Extension;
            swFeatMgr = swModel.FeatureManager;
            sketchLines = swSketchMgr.CreateCornerRectangle(-0.05096498314664, 0.05060941349678, 0, 0.1021670127265, -0.05037236706354, 0);
            boolstatus = swModelDocExt.SelectByID2("Line2", "SKETCHSEGMENT", 0, 0, 0, false, 0, null, 0);
            boolstatus = swModelDocExt.SelectByID2("Line2", "SKETCHSEGMENT", 0, 0, 0, true, 0, null, 0);
            boolstatus = swModelDocExt.SelectByID2("Line2", "SKETCHSEGMENT", 0, 0, 0, true, 0, null, 0);
            boolstatus = swModelDocExt.SelectByID2("Line2", "SKETCHSEGMENT", 0, 0, 0, true, 0, null, 0);
            swFeat = swFeatMgr.FeatureExtrusion2(true, false, false, 0, 0, 0.381, 0.381, false, false, false, false, 0.01745329251994, 0.01745329251994, false, false, false, false, true, true, true, 0, 0, false);
            //Create three points for the reference plane 
            P1[0] = -0.0141556764402858;
            P1[1] = 0.00194061273859598;
            P1[2] = 0;
            P2[0] = -0.0141556764402858;
            P2[1] = 0.00194061273859598;
            P2[2] = 1;
            P3[0] = -0.149976101832345;
            P3[1] = -0.988792859011662;
            P3[2] = 0;
            //Create the reference plane 
            swModel.CreatePlaneFixed2(P1, P2, P3, false);
            //Select reference plane 
            boolstatus = swModelDocExt.SelectByID2("Plane1", "PLANE", -0.0156784487003801, -0.00916715285390111, 0.0558270998665543, false, 0, null, 0);
            //Create the hole wizard hole 
            swFeat = swFeatMgr.HoleWizard5((int)swWzdGeneralHoleTypes_e.swWzdCounterSink, (int)swWzdHoleStandards_e.swStandardAnsiMetric, (int)swWzdHoleStandardFastenerTypes_e.swStandardAnsiMetricFlatHead82, "M2", (int)swEndConditions_e.swEndCondThroughAll, 0.0102, 0.010312189893273, 0, 0.0044, 1.57079632679489, 0.000152189893272978, 0, -1, -1, -1, -1, 1, -1, -1, -1, "", false, true, true, true, true, false);
        }
        public SldWorks swApp;
    }
}
This example shows how to use IFeatureManager::HoleWizard5 to insert a straight slot and a counterbore hole in a part.

//-----------------------------------------------
// Preconditions: 
// 1. Verify that the specified part document to open exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens the specified part document.
// 2. Creates a straight slot and a counterbore hole.
// 3. Prints the length of the slot to the 
//    Immediate window.
// 4. To verify steps 2 and 3, examine the part in the 
//    graphics area, the FeatureManager design tree, and 
//    the Immediate window.
//
// NOTE: Because the part document is used elsewhere,
// do not save changes.
//------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
 
Namespace HoleWizard5FeatureManagerCSharp.csproj
{
    Partial Class SolidWorksMacro
    {
 
        public void Main()
        {
 
            ModelDoc2 swModel = default(ModelDoc2);
            FeatureManager swFeatureMgr = default(FeatureManager);
            Feature swFeature = default(Feature);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            string fileName = null;
            int errors = 0;
            int warnings = 0;
            bool status = false;
            int SlotType = 0;
            int HoleType = 0;
            int StandardIndex = 0;
            int FastenerTypeIndex = 0;
            string SSize = null;
            short EndType = 0;
            double ConvFactorLength = 0;
            double ConvFactorAngle = 0;
            double Diameter = 0;
            double Depth = 0;
            double Length = 0;
            double ScrewFit = 0;
            double DrillAngle = 0;
            double NearCsinkDiameter = 0;
            double NearCsinkAngle = 0;
            double FarCsinkDiameter = 0;
            double FarCsinkAngle = 0;
            double Offset = 0;
            string ThreadClass = null;
            double CounterBoreDiameter = 0;
            double CounterBoreDepth = 0;
            double HeadClearance = 0;
            double BotCsinkDiameter = 0;
            double BotCsinkAngle = 0;
            WizardHoleFeatureData2 swWizardHoleFeatData = default(WizardHoleFeatureData2);
 
            fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2019\\samples\\tutorial\\api\\block20.sldprt";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swFeatureMgr = (FeatureManager)swModel.FeatureManager;
            swModelDocExt = (ModelDocExtension)swModel.Extension;
 
            //Create a slot 
 
            //Select the face where to create the slot
            status = swModelDocExt.SelectByID2("", "FACE", -0.000609805077203873, 0.0396239999998897, -0.00830387834611201, false, 0, null, 0);
 
            SlotType = (int)swWzdGeneralHoleTypes_e.swWzdHoleSlot;
            StandardIndex = (int)swWzdHoleStandards_e.swStandardAnsiInch;
            FastenerTypeIndex = (int)swWzdHoleStandardFastenerTypes_e.swStandardAnsiInchAllDrillSizes;
            SSize = "#97";
            EndType = (int)swEndConditions_e.swEndCondBlind;
            ConvFactorLength = 25.4 / 1000; 		//Convert inches to meters
            ConvFactorAngle = (22 / 7) / 180; 		//Convert degrees to radians
            Diameter = 0.5 * ConvFactorLength;
            Depth = 2 * ConvFactorLength;
            Length = 3 * ConvFactorLength;
 
            //Value1 to Value7 arguments; SOLIDWORKS
            //ignores parameters set to -1
            ScrewFit = -1;   		         //Value1
            DrillAngle = 100 * ConvFactorAngle;	//Value2
            NearCsinkDiameter = -1;         		//Value3
            NearCsinkAngle = -1;            		//Value4
            FarCsinkDiameter = -1;          		//Value5
            FarCsinkAngle = -1;             		//Value6
            Offset = -1;                    		//Value7
 
            ThreadClass = "";
 
            swFeature = (Feature)swFeatureMgr.HoleWizard5(SlotType, StandardIndex, FastenerTypeIndex, SSize, EndType, Diameter, Depth, Length, 
            ScrewFit, DrillAngle, NearCsinkDiameter, NearCsinkAngle, FarCsinkDiameter, FarCsinkAngle, Offset, -1, -1, -1, -1, -1,
            ThreadClass, false, false, false, false, false, false);
            //Print length of slot to Immediate window
            swWizardHoleFeatData = (WizardHoleFeatureData2)swFeature.GetDefinition();
            Debug.Print("Length of slot: " + swWizardHoleFeatData.Length);

            //Create a counterbore hole    
 
            //Select the face where to create the hole
            status = swModelDocExt.SelectByID2("", "FACE", -0.0060197480091233, 0.0396239999998329, 0.0270812377555103, false, 0, null, 0);
 
            HoleType = (int)swWzdGeneralHoleTypes_e.swWzdCounterBore;
            StandardIndex = (int)swWzdHoleStandards_e.swStandardAnsiInch;
            FastenerTypeIndex = (int)swWzdHoleStandardFastenerTypes_e.swStandardAnsiInchBinding;
            SSize = "#12";
            EndType = (int)swEndConditions_e.swEndCondThroughAll;
            ConvFactorLength = 25.4 / 1000;	//Convert inches to meters
            ConvFactorAngle = (22 / 7) / 180;	//Convert degrees to radians
            Diameter = 0.5 * ConvFactorLength;
            Depth = -1;
            Length = -1;
 
            //Value1 to Value12 arguments; SOLIDWORKS
            //ignores parameters set to -1      
            CounterBoreDiameter = 0.6 * ConvFactorLength;	//Value1
            CounterBoreDepth = 0.2 * ConvFactorLength;		//Value2
            HeadClearance = -1;                     		//Value3
            ScrewFit = -1;                          		//Value4
            DrillAngle = -1;                        		//Value5
            NearCsinkDiameter = -1;                 		//Value6
            NearCsinkAngle = -1;                    		//Value7
            BotCsinkDiameter = -1;                          	//Value8
            BotCsinkAngle = -1;                             	//Value9
            FarCsinkDiameter = -1;                  		//Value10
            FarCsinkAngle = -1;                     		//Value11
            Offset = -1;                            		//Value12
 
            ThreadClass = "";
 
            swFeature = (Feature)swFeatureMgr.HoleWizard5(HoleType, StandardIndex, FastenerTypeIndex, SSize, EndType,
            Diameter, Depth, Length, CounterBoreDiameter, CounterBoreDepth, HeadClearance, ScrewFit, DrillAngle, 
            NearCsinkDiameter, NearCsinkAngle, BotCsinkDiameter, BotCsinkAngle, FarCsinkDiameter, FarCsinkAngle, 
            Offset, ThreadClass, false, false, false, false, false, false);
 
        }
 
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
 
        public SldWorks swApp;
 
    }
}
This example shows how to insert Center of Mass and Center of Mass Reference Point features.

//----------------------------------------------------------------------------
// Preconditions: Open a part.
//
// Postconditions: The FeatureManager design tree contains:
// * Center of Mass
// * Center of Mass Reference Point1
// ---------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
namespace InsertCenterOfMass_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        ModelDoc2 Part;
        Feature COM;
        Feature COMRP;

        public void Main()
        {
            Part = (ModelDoc2)swApp.ActiveDoc;

            COM = Part.FeatureManager.InsertCenterOfMass();
            COMRP = Part.FeatureManager.InsertCenterOfMassReferencePoint();
        }

        public SldWorks swApp;

    }
} 
This example shows how to combine bodies in a multibody part.

//-------------------------------------------------------------
// Preconditions:
// 1. Verify that the part document to open exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens the specified part document.
// 2. Selects two solid bodies.
// 3. Inserts a combine feature using the two selected
//    bodies.
// 4. Prints the type of combine feature to the Immediate
//    window.
// 5. Examine the Immediate window.
//
// NOTE: Because the part document is used elsewhere, do not
// save changes.
//--------------------------------------------------------------
 
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace CombineBodiesCSharp.csproj
{
    public partial class SolidWorksMacro
    { 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            FeatureManager swFeatureMgr = default(FeatureManager);
            Feature swFeature = default(Feature);
            CombineBodiesFeatureData swCombineBodiesFeatureData = default(CombineBodiesFeatureData);
            string fileName = null;
            bool status = false;
            int errors = 0;
            int warnings = 0;
 
            fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\multibody\\multi_inter.sldprt";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
 
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            status = swModelDocExt.SelectByID2("Extrude-Thin1", "SOLIDBODY", 0, 0, 0, true, 0, null, 0);
            status = swModelDocExt.SelectByID2("Boss-Extrude1", "SOLIDBODY", 0, 0, 0, true, 0, null, 0);
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("Extrude-Thin1", "SOLIDBODY", 0, 0, 0, false, 2, null, 0);
            status = swModelDocExt.SelectByID2("Boss-Extrude1", "SOLIDBODY", 0, 0, 0, true, 2, null, 0);
            swFeatureMgr = (FeatureManager)swModel.FeatureManager;
            swFeature = (Feature)swFeatureMgr.InsertCombineFeature((int)swBodyOperationType_e.SWBODYADD, null, null);
 
            swCombineBodiesFeatureData = (CombineBodiesFeatureData)swFeature.GetDefinition();
            status = swCombineBodiesFeatureData.AccessSelections(swModel, null);
            //swCombineBodiesOperationType_e:
            // swCombineBodiesOperationAdd = 0
            // swCombineBodiesOperationCommon = 2
            // swCombineBodiesOperationSubract = 1
            Debug.Print("Type of combine feature: " + swCombineBodiesFeatureData.OperationType);
            swCombineBodiesFeatureData.ReleaseSelectionAccess();
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}
This example shows how to create a connection point for a tube for routing.

//---------------------------------------------------
// Preconditions:
// 1. Load the SOLIDWORKS Routing Add-in (click
//    Tools > Add-Ins > SOLIDWORKS Routing).
// 2. Verify that the specified part document to open
//    exists.
//
// Postconditions:
// 1. Creates a connection point for a tube
//    using the selected edge.
// 2. Examine the graphics area and Immediate window.
//
// NOTE: Because this part document is used elsewhere,
// do not save changes.
//---------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
namespace InsertConnectionPointFeatureManagerCSharp.csproj
{
    public partial class SolidWorksMacro
    {
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            FeatureManager swFeatMgr = default(FeatureManager);
            int errors = 0;
            int warnings = 0;
            bool status = false;
 
            swModel = (ModelDoc2)swApp.OpenDoc6("C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\routing-pipes\\fittings\\filter.sldprt", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swModelDocExt = (ModelDocExtension)swModel.Extension;
 
            // Select the edge for the connection point; 
            // remember to specify a value of 1 for 
            // the Mark parameter for a circular edge for 
            // a tube's connection point 
            status = swModelDocExt.SelectByID2("", "EDGE", 0.001425156111225, 0.1755840982619, -0.09117938337181, false, 1, null, 0);
 
            // Insert a connection point for a tube 
            swFeatMgr = swModel.FeatureManager;
            Debug.Print("Connection point for tube created? " + swFeatMgr.InsertConnectionPoint((int)swConnectionPointType_e.swConnectionPoint_Tube, 0, true, 25.4 / 1000, 0.1, 0.2, 0.3, 0.4, "", 0,
            0, false, "Specification", ""));
        }
 
        /// <summary> 
        /// The SldWorks swApp variable is pre-assigned for you. 
        /// </summary> 
        public SldWorks swApp;
 
    }
}
This example shows how to convert a solid body to sheet metal.


//-------------------------------------------------------------------------- 
// Preconditions: Open public_documents\samples\tutorial\api\sweepcutextrude.sldprt. 
// 
// Postconditions: 
// 1. Converts Boss-Extrude1 to sheet metal containing two rip edges. 
// 2. Examine the FeatureManager design tree, which now contains: 
//    * Sheet-Metal1 
//    * Convert-Solid1 
//    * Flat-Pattern1 
// NOTE: Because the part is used elsewhere, do not save changes.
//------------------------------------------------------------------------- 
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
namespace InsertConvertSheetMetal_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        public void Main()
        {

            ModelDoc2 swDoc = null;
            bool boolstatus = false;

            swDoc = (ModelDoc2)swApp.ActiveDoc;
            boolstatus = swDoc.Extension.SelectByID2("", "FACE", -0.008205131831119, 0.02357994168915, 0.03366815886659, true, 0, null, 0);
            boolstatus = swDoc.Extension.SelectByID2("", "EDGE", -0.004077318654993, 0.02376323764372, 0.04987547143355, true, 1, null, 0);
            boolstatus = swDoc.Extension.SelectByID2("", "EDGE", 0.02890215593544, 0.02392631827274, 0.03020230805026, true, 1, null, 0);
            boolstatus = swDoc.Extension.SelectByID2("", "EDGE", -0.007010951021414, 0.02376186282277, -0.0001235945334201, true, 1, null, 0);


            // Convert extrusion to sheet metal of thickness=13mm, 
            // bend radius=0.5mm, rip gap=2mm, relief type = rectangular, 
            // relief ratio = 0.5, rip edge overlap type = open butt, and 
            // rip edge overlap ratio = 0.5, do not keep bodies
            boolstatus = swDoc.FeatureManager.InsertConvertToSheetMetal2(0.013, false, false, 0.0005, 0.002, 0, 0.5, 1, 0.5, false);

            swDoc.ClearSelection2(true);
        }

        public SldWorks swApp;

    }
} 
This example shows how to traverse all cosmetic threads in a part and extract their data.

NOTE: In a part or assembly, a cosmetic thread is a subfeature of a hole or cut extrusion. Thus, you can traverse all of the cosmetic threads in a model using the IFeature traversal methods.

//---------------------------------------------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\api\holecube.sldprt.
// 2. Open an Immediate window.
//
// Postconditions:
// 1. Creates a Helicoil Metric standard cosmetic thread.
// 2. Examine the Immediate window.
//
// NOTE: Because the part is used elsewhere, do not save changes.
//---------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;

namespace InsertCosmeticThread3_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            Feature swFeat = default(Feature);
            Feature swSubFeat = default(Feature);
            string sFeatType = null;
            CosmeticThreadFeatureData swCosThread = default(CosmeticThreadFeatureData);
            bool bRet = false;

            swModel = (ModelDoc2)swApp.ActiveDoc;

            bRet = swModel.Extension.SelectByID2("", "EDGE", -0.000802489357837999, -0.0246888176810671, 6.00726028778809E-05, true, 0, null, 0);
            swFeat = swModel.FeatureManager.InsertCosmeticThread3((int)swCosmeticStandardType_e.swStandardType_StandardHelicoilMetric, "Helicoil threads", "M33x2.0", 0.033, (int)swCosmeticEndConditions_e.swEndConditionBlind2Dia, 0.025, "M33x2.0 Helicoil Threads");

            Debug.Print("File = " + swModel.GetPathName());

            swFeat = (Feature)swModel.FirstFeature();

            while ((swFeat != null))
            {
                swSubFeat = (Feature)swFeat.GetFirstSubFeature();
                while ((swSubFeat != null))
                {
                    sFeatType = swSubFeat.GetTypeName();

                    switch (sFeatType)
                    {

                        case "CosmeticThread":
                            Debug.Print("    " + swSubFeat.Name + " [" + sFeatType + "]");

                            swCosThread = (CosmeticThreadFeatureData)swSubFeat.GetDefinition();

                            Debug.Print("      ApplyThread      = " + swCosThread.ApplyThread);
                            Debug.Print("      BlindDepth       = " + swCosThread.BlindDepth * 1000.0 + " mm");
                            Debug.Print("      Diameter         = " + swCosThread.Diameter * 1000.0 + " mm");
                            Debug.Print("      DiameterType     = " + swCosThread.DiameterType);
                            Debug.Print("      ThreadCallout    = " + swCosThread.ThreadCallout);
                            Debug.Print("      ConfigurationOption as defined in swCosmeticConfigOptions_e = " + swCosThread.ConfigurationOption);
                            Debug.Print("      EndCondition as defined in swCosmeticEndConditions_e = " + swCosThread.EndCondition);
                            Debug.Print("      Size = " + swCosThread.Size);
                            Debug.Print("      Standard as defined in swCosmeticStandardType_e = " + swCosThread.Standard);
                            Debug.Print("      StandardType = " + swCosThread.StandardType);


                            Debug.Print("");

                            break;
                    }

                    swSubFeat = (Feature)swSubFeat.GetNextSubFeature();

                }

                swFeat = (Feature)swFeat.GetNextFeature();

            }

        }

        public SldWorks swApp;
    }
}
This example shows how to insert a cosmetic weld bead using geometric entities.

//----------------------------------------------
// Preconditions: 
// 1. Verify that the part to open exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Creates a cosmetic weld bead using the
//    selected geometric entities (i.e., faces).
// 2. To verify, examine the graphics area and
//    expand the Weld Folder and its subfolder
//    in the FeatureManager design tree.
// 3. Examine the Immediate window.
//
// NOTE: Because the part document is used elsewhere,
// do not save any changes to it.
//-----------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace InsertCosmeticWeldBead2CSharp.csproj
{
    public partial class SolidWorksMacro
    {
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            Feature swFeature = default(Feature);
            SelectionMgr swSelMgr = default(SelectionMgr);
            FeatureManager swFeatureMgr = default(FeatureManager);
            CosmeticWeldBeadFeatureData swCosmeticWeldBeadFeatureData = default(CosmeticWeldBeadFeatureData);
            bool status = false;
            int errors = 0;
            int warnings = 0;
            string fileName = null;
            int entityType = 0;
 
            //Open model document
            fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\driveworksxpress\\leg.sldprt";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
 
            //Select the faces
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            //From face
            status = swModelDocExt.SelectByID2("", "FACE", 0.447611268878973, 0.185506718400291, 0.00676112086262037, true, 4, null, 0);
            //To face
            status = swModelDocExt.SelectByID2("", "FACE", 0.567647499089958, 0.0888999999998532, 0.00208831790428121, true, 8, null, 0);
 
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            Face2[] weldFromFace = new Face2[1];
            object[] weldFromArray = new object[1];
            weldFromFace[0] = (Face2)swSelMgr.GetSelectedObject6(1, 4);
            weldFromArray = (object[])weldFromFace;
 
            Face2[] weldToFace = new Face2[1];
            object[] weldToArray = new object[1];
            weldToFace[0] = (Face2)swSelMgr.GetSelectedObject6(1, 8);
            weldToArray = (object[])weldToFace;
 
            //Create cosmetic weld bead using the selected faces
            object[] weldObjs = new object[2];
            swFeatureMgr = swModel.FeatureManager;
            weldObjs = (object[])swFeatureMgr.InsertCosmeticWeldBead2(0, weldFromArray, weldToArray, 15 / 1000);
 
            //Get the weld-from and weld-to entities and their types
            status = swModelDocExt.SelectByID2("Weld Bead1", "COSMETIC_WELD", 0, 0, 0, false, 0, null, 0);
            swFeature = (Feature)swSelMgr.GetSelectedObject6(1, -1);
            swCosmeticWeldBeadFeatureData = (CosmeticWeldBeadFeatureData)swFeature.GetDefinition();
            swCosmeticWeldBeadFeatureData.AccessSelections(swModel, null);
            Debug.Print(swFeature.Name);
            weldObjs = (object[])swCosmeticWeldBeadFeatureData.GetEntitiesWeldFrom(out entityType);
            Debug.Print("  Weld-from type: " + entityType);
            weldObjs = (object[])swCosmeticWeldBeadFeatureData.GetEntitiesWeldTo(out entityType);
            Debug.Print("  Weld-to type:   " + entityType);
            swCosmeticWeldBeadFeatureData.ReleaseSelectionAccess();
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
} 
This example shows how to insert a surface-cut feature. 

//------------------------------------------------------------------------------
// Preconditions: 
// 1. Verify that the specified file to open exists.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Opens the part whose intersecting solid bodies to cut with a plane.
// 2. Creates a plane named Plane1.
// 3. Selects Plane1 to cut all intersecting solid bodies.
// 4. Inserts the surface-cut feature, which cuts all intersecting 
//    solid bodies by the plane.
// 5. Examine the graphics area and Immediate window to verify.
//
// NOTE: Because this part document is used elsewhere, do not save changes.
//------------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace InsertCutSurface2CSharp.csproj
{
 
    partial class SolidWorksMacro
    {
 
        public void Main()
        {
 
            PartDoc swPart = default(PartDoc);
            ModelDoc2 swModel = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            Feature swFeature = default(Feature);
            FeatureManager swFeatureManager = default(FeatureManager);
            RefPlane swRefPlane = default(RefPlane);
            SurfCutFeatureData swSurfaceCutFeature = default(SurfCutFeatureData);
            bool status = false;
            string fileName = null;
            int errors = 0;
            int warnings = 0;
 
            // Open part to cut with a plane
            fileName = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\multibody\\multi_inter.sldprt";
            swPart = (PartDoc)swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swModel = (ModelDoc2)swPart;
            swModelDocExt = (ModelDocExtension)swModel.Extension;
 
 
            // Create and select the plane to cut the 
            // intersecting solid bodies in the part
            status = swModelDocExt.SelectByID2("Front", "PLANE", 0, 0, 0, true, 0, null, 0);
            swFeatureManager = (FeatureManager)swModel.FeatureManager;
            swRefPlane = (RefPlane)swFeatureManager.InsertRefPlane((int)swRefPlaneReferenceConstraints_e.swRefPlaneReferenceConstraint_Distance, 0.045, 0, 0, 0, 0);
            status = swModelDocExt.SelectByID2("Plane1", "PLANE", 0, 0, 0, true, 0, null, 0);
 
            // Insert surface-cut feature to cut 
            // all intersecting solid bodies
            swFeature = (Feature)swFeatureManager.InsertCutSurface(false, 0, false, true, null, out errors);
            Debug.Print("Were any errors generated by the surface cut (0 = no errors)? " + errors);
            // Get surface-cut feature and some properties
            swSurfaceCutFeature = (SurfCutFeatureData)swFeature.GetDefinition();
            Debug.Print("Name of surface-cut feature: " + swFeature.Name);
            Debug.Print(" Is feature scope on? " + swSurfaceCutFeature.FeatureScope);
            Debug.Print(" Number of bodies cut by the plane: " + swSurfaceCutFeature.GetFeatureScopeBodiesCount());
            Debug.Print(" Is auto-select on? " + swSurfaceCutFeature.AutoSelect);
        }
 
 
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
 
 
    }
}
This example shows how to insert a Body-Delete/Keep feature into a multibody part.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\multibody\multi_local.sldprt.
// 2. Open an Immediate window.
//
// Postconditions:
// 1. Creates Body-Delete/Keep 1 in the FeatureManager design tree.
// 2. Inspect the Immediate window.
//
// NOTE: Because the model is used elsewhere, do not save changes.
// ---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
namespace InsertDeleteBody_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        ModelDoc2 Part;
        Feature myFeature;
        DeleteBodyFeatureData insDelBody;

        bool boolstatus;


        public void Main()
        {
            Part = (ModelDoc2)swApp.ActiveDoc;
            // Select body to delete
            boolstatus = Part.Extension.SelectByID2("Fillet5", "SOLIDBODY", 0.0592851881957586, 0.0409115950836281, -0.0197275812591329, true, 0, null, 0);
            // Create a Body-Delete/Keep feature
            myFeature = Part.FeatureManager.InsertDeleteBody2(false);

            insDelBody = (DeleteBodyFeatureData)myFeature.GetDefinition();
            Debug.Print("Number of bodies in this Body-Delete/Keep feature: " + insDelBody.GetBodiesCount());
            Debug.Print("Keep bodies: " + insDelBody.KeepBodies);

        }



        public SldWorks swApp;

    }
} 
This example shows how to insert and position a DXF/DWG file in a drawing.

//---------------------------------------------------------------------------
// Preconditions:
// 1. Open a drawing.
// 2. Replace DXF_file_path with the pathname of an existing DXF/DWG file.
// 3. Open the Immediate window.
//
// Postconditions:
// 1. Inserts the DXF/DWG file as per the specified import data.
// 2. Inspect the Immediate window.
//---------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
namespace InsertDXFDrawing_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        public void Main()
        {
            const string sDwgFileName = "DXF_file_path";

            ModelDoc2 swModel = default(ModelDoc2);
            ModelView swModelView = default(ModelView);
            DrawingDoc swDraw = default(DrawingDoc);
            FeatureManager swFeatMgr = default(FeatureManager);
            Feature swFeat = default(Feature);
            Sketch swSketch = default(Sketch);
            View swView = default(View);
            double[] vPos = null;
            bool bRet = false;
            ImportDxfDwgData importData = default(ImportDxfDwgData);

            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModelView = (ModelView)swModel.ActiveView;

            bRet = swModel.Extension.SelectByID2("Sheet1", "SHEET", 0.0, 0.0, 0, false, 0, null, 0);

            swDraw = (DrawingDoc)swModel;
            swFeatMgr = swModel.FeatureManager;
            importData = (ImportDxfDwgData)swApp.GetImportFileData(sDwgFileName);

            // Unit
            importData.set_LengthUnit("", (int)swLengthUnit_e.swINCHES);

            // Position
            bRet = importData.SetPosition("", (int)swDwgImportEntitiesPositioning_e.swDwgEntitiesCentered, 0, 0);

            // Sheet scale
            bRet = importData.SetSheetScale("", 1.0, 2.0);

            // Paper size
            bRet = importData.SetPaperSize("", (int)swDwgPaperSizes_e.swDwgPaperAsize, 0.0, 0.0);

            //Import method
            importData.set_ImportMethod("", (int)swImportDxfDwg_ImportMethod_e.swImportDxfDwg_ImportToExistingDrawing);

            // Import file with importData
            swFeat = swFeatMgr.InsertDwgOrDxfFile2(sDwgFileName, importData);
            swSketch = (Sketch)swFeat.GetSpecificFeature2();

            swView = (View)swDraw.GetFirstView();

            while ((swView != null))
            {
                if (object.ReferenceEquals(swSketch, swView.GetSketch()))
                {
                    break; 
                }
                swView = (View)swView.GetNextView();
            }

            vPos = (double[])swView.Position;

            Debug.Print("File = " + swModel.GetPathName());
            Debug.Print("  Sketch       = " + swFeat.Name);
            Debug.Print("  View         = " + swView.Name);
            Debug.Print("    Old Pos    = (" + vPos[0] * 1000.0 + ", " + vPos[1] * 1000.0 + ") mm");

            // Move to right
            vPos[0] = vPos[0] + 0.01;
            swView.Position = vPos;

            vPos = (double[])swView.Position;
            Debug.Print("    New Pos    = (" + vPos[0] * 1000.0 + ", " + vPos[1] * 1000.0 + ") mm");

            // Redraw
            double[] rect = null;
            rect = null;
            swModelView.GraphicsRedraw(rect);

        }

        public SldWorks swApp;

    }
} 
This example shows how to insert a DXF/DWG image on a preselected plane or face and then autodimension it.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Open a part.
// 2. Replace path_name with the pathname of an existing DXF/DWG file.
// 3. Select a plane or face on which to insert the DXF/DWG image.
//
// Postconditions:
// 1. Adds the DXF/DWG image as a sketch.
// 2. Autodimensions the sketch.
// 3. Use Zoom to Area to inspect the sketch dimensioning.
// 4. Press F5 to rebuild the model.
//---------------------------------------------------------------------------

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
namespace InsertDXFAndAutodimension_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        const double nTolerance = 1E-08;
        ModelView swModelView;
        SketchManager swSketchMgr;
        int nRetVal;

         public void Main()
        {
            const string sDwgFileName = "path_name";

            ModelDoc2 swModel = default(ModelDoc2);
            FeatureManager swFeatMgr = default(FeatureManager);
            Feature swFeat = default(Feature);
            Sketch swSketch = default(Sketch);
            SelectionMgr swSelMgr = default(SelectionMgr);
            SelectData swSelData = default(SelectData);
            bool bRet = false;
            ImportDxfDwgData importData = default(ImportDxfDwgData);

            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModelView = (ModelView)swModel.ActiveView;
            swFeatMgr = swModel.FeatureManager;
            importData = (ImportDxfDwgData)swApp.GetImportFileData(sDwgFileName);

            //Unit
            importData.set_LengthUnit("", (int)swLengthUnit_e.swMM);

            //Position
            bRet = importData.SetPosition("", (int)swDwgImportEntitiesPositioning_e.swDwgEntitiesCentered, 0, 0);

            //Sheet scale
            bRet = importData.SetSheetScale("", 1.0, 2.0);

            //Paper size
            bRet = importData.SetPaperSize("", (int)swDwgPaperSizes_e.swDwgPaperAsize, 0.0, 0.0);

            //Import method
            importData.set_ImportMethod("", (int)swImportDxfDwg_ImportMethod_e.swImportDxfDwg_ImportToExistingPart);

            swFeat = swFeatMgr.InsertDwgOrDxfFile2(sDwgFileName, importData);

            swSketch = (Sketch)swFeat.GetSpecificFeature2();
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            swSelData = swSelMgr.CreateSelectData();

            nRetVal = AutoDimensionSketch(swApp, swModel, swSketch, swSelData);

            System.Diagnostics.Debugger.Break();

            // Rebuild to update sketch
            swModel.EditRebuild3();

        }

       
        public object GetAllSketchLines(SldWorks swApp, ModelDoc2 swModel, Sketch swSketch)
        {
            object functionReturnValue = null;

            Object[] vSketchSegArr = null;
            object vSketchSeg = null;
            SketchSegment swSketchSeg = default(SketchSegment);
            SketchLine swSketchCurrLine = default(SketchLine);
            SketchLine[] swSketchLineArr = new SketchLine[1];

            vSketchSegArr = (Object[])swSketch.GetSketchSegments();

            if ((vSketchSegArr != null))
            {
                foreach (SketchSegment vSketchSeg_loopVariable in vSketchSegArr)
                {
                    vSketchSeg = vSketchSeg_loopVariable;
                    swSketchSeg = (SketchSegment)vSketchSeg;
                    if ((int)swSketchSegments_e.swSketchLINE == swSketchSeg.GetType())
                    {
                        swSketchCurrLine = (SketchLine)swSketchSeg;
                        swSketchLineArr[swSketchLineArr.GetUpperBound(0)] = swSketchCurrLine;
                        Array.Resize(ref swSketchLineArr, swSketchLineArr.GetUpperBound(0) + 2);
                    }
                }
            }

            if (0 == swSketchLineArr.GetUpperBound(0))
            {
                // No straight lines in this sketch
                functionReturnValue = null;
                return functionReturnValue;
            }

            // Remove last, empty sketch line
            Array.Resize(ref swSketchLineArr, swSketchLineArr.GetUpperBound(0));
            functionReturnValue = swSketchLineArr;
            return functionReturnValue;

        }

        public bool GetSketchPoint(SldWorks swApp, ModelDoc2 swModel, Sketch swSketch, SketchPoint swSketchPt)
        {
            bool functionReturnValue = false;

            SketchPoint[] vSketchPtArr = null;
            vSketchPtArr = (SketchPoint[])swSketch.GetSketchPoints2();
            if ((vSketchPtArr != null))
            {
                // Use first point
                swSketchPt = (SketchPoint)vSketchPtArr[0];
                functionReturnValue = true;
                return functionReturnValue;
            }
            functionReturnValue = false;
            return functionReturnValue;

        }

        public bool FindVerticalOrigin(SldWorks swApp, ModelDoc2 swModel, Sketch swSketch, SketchSegment swSketchSegVert, SketchPoint swSketchPtVert)
        {
            bool functionReturnValue = false;

            SketchLine[] vSketchLineArr = null;
            object vSketchLine = null;
            SketchLine swSketchCurrLine = default(SketchLine);
            SketchPoint swStartPt = default(SketchPoint);
            SketchPoint swEndPt = default(SketchPoint);

            // Get first vertical line
            vSketchLineArr = (SketchLine[])GetAllSketchLines(swApp, swModel, swSketch);

            if ((vSketchLineArr != null))
            {
                foreach (SketchLine vSketchLine_loopVariable in vSketchLineArr)
                {
                    vSketchLine = vSketchLine_loopVariable;
                    swSketchCurrLine = (SketchLine)vSketchLine;
                    swStartPt = (SketchPoint)swSketchCurrLine.GetStartPoint2();
                    swEndPt = (SketchPoint)swSketchCurrLine.GetEndPoint2();

                    if (Math.Abs(swStartPt.X - swEndPt.X) < nTolerance)
                    {
                        swSketchSegVert = (SketchSegment)swSketchCurrLine;
                        functionReturnValue = true;
                        return functionReturnValue;
                    }
                }
            }

            // Get first point
            functionReturnValue = GetSketchPoint(swApp, swModel, swSketch, swSketchPtVert);
            return functionReturnValue;

        }

        public bool FindHorizontalOrigin(SldWorks swApp, ModelDoc2 swModel, Sketch swSketch, SketchSegment swSketchSegHoriz, SketchPoint swSketchPtHoriz)
        {
            bool functionReturnValue = false;

            SketchLine[] vSketchLineArr = null;
            object vSketchLine = null;
            SketchLine swSketchCurrLine = default(SketchLine);
            SketchPoint swStartPt = default(SketchPoint);
            SketchPoint swEndPt = default(SketchPoint);

            // Get first horizontal line
            vSketchLineArr = (SketchLine[])GetAllSketchLines(swApp, swModel, swSketch);

            if ((vSketchLineArr != null))
            {
                foreach (SketchLine vSketchLine_loopVariable in vSketchLineArr)
                {
                    vSketchLine = vSketchLine_loopVariable;
                    swSketchCurrLine = (SketchLine)vSketchLine;
                    swStartPt = (SketchPoint)swSketchCurrLine.GetStartPoint2();
                    swEndPt = (SketchPoint)swSketchCurrLine.GetEndPoint2();

                    if (Math.Abs(swStartPt.Y - swEndPt.Y) < nTolerance)
                    {
                        swSketchSegHoriz = (SketchSegment)swSketchCurrLine;
                        functionReturnValue = true;
                        return functionReturnValue;
                    }
                }
            }

            // Get first point
            functionReturnValue = GetSketchPoint(swApp, swModel, swSketch, swSketchPtHoriz);
            return functionReturnValue;

        }

        public int AutoDimensionSketch(SldWorks swApp, ModelDoc2 swModel, Sketch swSketch, SelectData swSelData)
        {
            int functionReturnValue = 0;

            Feature swFeat = default(Feature);
            SketchSegment swSketchSegHoriz = null;
            SketchPoint swSketchPtHoriz = null;
            SketchSegment swSketchSegVert = null;
            SketchPoint swSketchPtVert = null;
            bool bRet = false;

            if (false == FindHorizontalOrigin(swApp, swModel, swSketch, swSketchSegHoriz, swSketchPtHoriz))
            {
                functionReturnValue = (int)swAutodimStatus_e.swAutodimStatusDatumLineNotHorizontal;
                return functionReturnValue;
            }

            if (false == FindVerticalOrigin(swApp, swModel, swSketch, swSketchSegVert, swSketchPtVert))
            {
                functionReturnValue = (int)swAutodimStatus_e.swAutodimStatusDatumLineNotVertical;
                return functionReturnValue;
            }

            swFeat = (Feature)swSketch;

            bRet = swFeat.Select2(false, 0);

            // Editing sketch clears selections
            swModel.EditSketch();

            // Reselect sketch segments with correct marks for auto-dimensioning
            if ((swSketchSegVert != null))
            {
                // Vertical line is for horizontal datum
                bRet = swSketchSegVert.Select4(true, swSelData);
            }
            else if ((swSketchPtHoriz != null))
            {
                bRet = swSketchPtHoriz.Select4(true, swSelData);
            }
            else if ((swSketchPtVert != null))
            {
                // Use any sketch point for horizontal datum
                bRet = swSketchPtVert.Select4(true, swSelData);
            }

            if ((swSketchSegHoriz != null))
            {
                // Horizontal line is for vertical datum
                bRet = swSketchSegHoriz.Select4(true, swSelData);
            }
            else if ((swSketchPtVert != null))
            {
                bRet = swSketchPtVert.Select4(true, swSelData);
            }
            else if ((swSketchPtHoriz != null))
            {
                // Use any sketch point for vertical datum
                bRet = swSketchPtHoriz.Select4(true, swSelData);
            }

            // If contains circles use sketch points for datums
            if ((GetAllSketchLines(swApp, swModel, swSketch) == null))
            {
                if ((swSketchPtHoriz != null))
                {
                    bRet = swSketchPtHoriz.Select4(false, swSelData);
                }
                else if ((swSketchPtVert != null))
                {
                    bRet = swSketchPtVert.Select4(false, swSelData);
                }
            }

            swSketchMgr = swModel.SketchManager;
            nRetVal = swSketchMgr.FullyDefineSketch(true, true, (int)swSketchFullyDefineRelationType_e.swSketchFullyDefineRelationType_Vertical | (int)swSketchFullyDefineRelationType_e.swSketchFullyDefineRelationType_Horizontal, true, 1, null, 1, null, 1, 1);

            // Redraw so dimensions are displayed immediately
            double[] rect = null;
            rect = null;
            swModelView.GraphicsRedraw(rect);
            return functionReturnValue;

        }

        public SldWorks swApp;

    }
} 
This example shows how to insert the following weldment features into the FeatureManager design tree:

    *  End cap feature

    *  Fillet bead feature

    *  Gusset feature

    *  Structural weldment

    *  Sub weld folder

    *  Weldment trim feature

//---------------------------------------------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\weldments\weldment_box2.sldprt
// 2. Expand the Cut list folder in the FeatureManager design tree 
//    and observe its contents.
// 3. Delete End cap1 from the FeatureManager design tree.
// 4. Change the path specified for profilePathName, if necessary.
//
// Postconditions: Observe the following in the FeatureManager design tree:
//    * Gusset1 moves to the sub weld folder, Sub Folder1, in the Cut list 
//      folder
//    * Trim/Extend8 feature appears at the bottom of the design tree and at 
//      the end of the Cut list folder
//    * Structural Member6 feature appears at the bottom of the design tree 
//      and at the end of the Cut list folder
//    * End cap5 feature appears at the bottom of the design tree and in the 
//      Cut list folder
//    * Gusset5 feature appears at the bottom of the design tree and in the 
//      Cut list folder
//    * Fillet Bead5 feature appears at the bottom of the design tree and 
//      in the Cut list folder
//
// NOTE: Because this part is used elsewhere, 
// do not save any changes when you close it.
//---------------------------------------------------------------------------

 

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System;

namespace InsertWeldmentFeatures_CSharp.csproj

{

    partial class SolidWorksMacro

    {

        FeatureManager fm;

        SelectionMgr selMgr;

        ModelDoc2 Part;

        bool boolstatus;

        public void Main()

        {

            object myFeature = null;

            Body2[] obj = new Body2[1];

            Array v = default(Array);

            Part = (ModelDoc2)swApp.ActiveDoc;

            object myModelView = null;

            myModelView = Part.ActiveView;

            selMgr = (SelectionMgr)Part.SelectionManager;

            //InsertSubWeldFolder2 

            boolstatus = Part.Extension.SelectByID2("Gusset1", "SOLIDBODY", 0, 0, 0, false, 0, null, 0);

            obj[0] = (Body2)selMgr.GetSelectedObject6(1, -1);

            v = obj;

            fm = Part.FeatureManager;

            myFeature = fm.InsertSubWeldFolder2(v);

            Part.ClearSelection2(true);

            //InsertWeldmentTrimFeature2 

            Body2[] obj1 = new Body2[1];

            Body2[] obj2 = new Body2[1];

            long Options = 0;

            Array v1 = default(Array);

            Array v2 = default(Array);

            boolstatus = Part.Extension.SelectByID2("Structural Member1[2]", "SOLIDBODY", 0, 0, 0, true, 2, null, 0);

            boolstatus = Part.Extension.SelectByID2("Structural Member1[1]", "SOLIDBODY", 0, 0, 0, true, 1, null, 0);

            long Count = 0;

            Count = selMgr.GetSelectedObjectCount();

            if (Count == 2)

            {

                obj1[0] = (Body2)selMgr.GetSelectedObject2(1);

                v1 = obj1;

                obj2[0] = (Body2)selMgr.GetSelectedObject2(2);

                v2 = obj2;

                Part.ClearSelection2(true);

                Options = (long)swWeldmentTrimExtendOptionType_e.swWeldmentTrimExtendOption_AllowTrimmedExtensionTrim + (long)swWeldmentTrimExtendOptionType_e.swWeldmentTrimExtendOption_AllowTrimmingExtensionTrim + (long)swWeldmentTrimExtendOptionType_e.swWeldmentTrimExtendOption_CopedCut + (long)swWeldmentTrimExtendOptionType_e.swWeldmentTrimExtendOption_WeldGap;

                myFeature = fm.InsertWeldmentTrimFeature2(1, (int)Options, 0.01, v1, v2);

            }

            //InsertEndCapFeature 

            Feature endCapFeature = default(Feature);

            Face2[] face1 = new Face2[1];

            Array x = default(Array);

            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.6023443450227, 0.6150000000001, -1.013201139555, true, 1, null, 0);

            face1[0] = (Face2)selMgr.GetSelectedObject6(1, -1);

            x = face1;

            endCapFeature = fm.InsertEndCapFeature2(0.005, false, true, 0.003, 0.5, 0.003, x);

            Part.ClearSelection2(true);

            //InsertStructuralWeldment3 

            Array segmentObjects = default(Array);

            SketchSegment[] sketchSegments = new SketchSegment[4];

            string profilePathName = null;

            Feature structuralMember = default(Feature);

            StructuralMemberGroup @group = default(StructuralMemberGroup);

            StructuralMemberGroup[] GroupArray1 = new StructuralMemberGroup[1];

            long i = 0;

            @group = fm.CreateStructuralMemberGroup();

            Part.ClearSelection2(true);

            Part.InsertSketch2(true);

            segmentObjects = (System.Array)Part.SketchManager.CreateCornerRectangle(0, 0, 0, 1.0, 2.0, 0);

            for (i = 0; i <= segmentObjects.GetUpperBound(0); i++)

            {

                sketchSegments[i] = (SketchSegment)segmentObjects.GetValue(i);

            }

            @group.Segments = sketchSegments;

            GroupArray1[0] = @group;

            Part.ViewZoomtofit2();

            Part.InsertSketch2(true);

            profilePathName = "C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\lang\english\\weldment profiles\\ansi inch\\square tube\\2 x 2 x 0.25.SLDLFP";

            structuralMember = fm.InsertStructuralWeldment3(profilePathName, 1, 0.0, false, GroupArray1);

            Part.ClearSelection2(true);

            //InsertGussetFeature2 

            Face2[] faceGFObj = new Face2[2];

            object z = null;

            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.02539999999988, 1.94542628561, 0.00429028534694, true, 1, null, 0);

            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.07780718114736, 1.9746, -0.001856983219, true, 2, null, 0);

            Count = selMgr.GetSelectedObjectCount();

            if (Count == 2)

            {

                faceGFObj[0] = (Face2)selMgr.GetSelectedObject6(1, 1);

                faceGFObj[1] = (Face2)selMgr.GetSelectedObject6(1, 2);

                z = faceGFObj;

                Part.ClearSelection2(true);

                myFeature = fm.InsertGussetFeature2(0.005, 0, 0, false, 0.025, 0.025, 0.015, 0.7853981633975, 0.015, true,

                0.005, 0, false, false, false, z);

            }

            //InsertFilletBeadFeature3 

            Face2[] fbFaceObj1 = new Face2[1];

            Face2[] fbFaceObj2 = new Face2[2];

            Part.ClearSelection2(true);

            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.0412896304482, 0.02548020566445, 0, true, 1, null, 0);

            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.09804264728081, 0.01499999999999, 0.0008069730266129, true, 2, null, 0);

            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.01364526875011, 0.08738481720087, 0.01330055827532, true, 4, null, 0);

            Count = selMgr.GetSelectedObjectCount();

            // Face Set 1 

            fbFaceObj1[0] = (Face2)selMgr.GetSelectedObject6(1, 1);

            // Face Set 2 

            fbFaceObj2[0] = (Face2)selMgr.GetSelectedObject6(1, 2);

            //fbFaceObj2(0) = selMgr.GetSelectedObject6(1, 4) 

            v1 = fbFaceObj1;

            v2 = fbFaceObj2;

            Part.ClearSelection2(true);

            int[] edges = new int[1];

            Array edgeArray = default(Array);

            edges[0] = 0;

            //edges(1) = 0 

            edgeArray = edges;

            myFeature = fm.InsertFilletBeadFeature3(0, 0.003, 0.003, 2, 0.003, 0.006, 0, 0.003, 0.003, 2, 0.003, 0, 1, edgeArray, 0, null, v1, v2);

            Part.ClearSelection2(true);

        }

        public SldWorks swApp;

    }

}
This example shows how to create an end cap on the open face of a structural member.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\api\weldment_box3.sldprt.
// 2. Open an Immediate window.
//
// Postconditions:
// 1. Deletes End cap1.
// 2. Inserts End cap3 in the FeatureManager design tree.
// 3. Inspect the Immediate window.
//
// NOTE: Because the model is used elsewhere, do not save changes.
// ---------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
namespace InsertEndCap_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        Feature myFeature;
        ModelDoc2 Part;
        EndCapFeatureData swEndCap;
        bool boolstatus;

        public void Main()
        {
            Part = (ModelDoc2)swApp.ActiveDoc;

            boolstatus = Part.Extension.SelectByID2("End cap1", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            Part.EditDelete();

            Part.ViewZoomTo2(0.632542197290199, 0.972121141705638, 0.0346184961022406, 1.1852319686392, 0.619681287512073, 0.0346184961022431);

            boolstatus = Part.Extension.SelectByID2("", "FACE", 0.58771345904097, 0.614999999999952, -1.01293869257864, true, 0, null, 0);
            boolstatus = Part.Extension.SelectByID2("", "FACE", -0.0124763445314215, 0.614999999999839, -1.0014248149476, true, 0, null, 0);

            myFeature = Part.FeatureManager.InsertEndCapFeature3(0.005, false, false, 0.003, 0.6, 0.003, true, 0.002, false, 2);

            swEndCap = (EndCapFeatureData)myFeature.GetDefinition();

            Debug.Print("File = " + Part.GetPathName());
            Debug.Print("  " + myFeature.Name);
            Debug.Print("    Chamfer distance or fillet radius                      = " + swEndCap.ChamferDistance * 1000.0 + " mm");
            Debug.Print("    Inset distance                                         = " + swEndCap.DepthDistance * 1000.0 + " mm");
            Debug.Print("    Thickness direction (0=outward, 1=inward, 2=inset)     = " + swEndCap.IsEndCapInward);
            Debug.Print("    Offset distance                                        = " + swEndCap.OffsetDistance * 1000.0 + " mm");
            Debug.Print("    Thickness of end cap                                   = " + swEndCap.Thickness * 1000.0 + " mm");
            Debug.Print("    Thickness ratio for offset                             = " + swEndCap.ThicknessRatioForOffset);
            Debug.Print("    Chamfer corners                                        = " + swEndCap.UseChamferCorners);
            Debug.Print("    Apply corner treatment                                 = " + swEndCap.UseCornerTreatment);
            Debug.Print("    Reverse offset                                         = " + swEndCap.UseReverse);
            Debug.Print("    Use thickness ratio for offset                         = " + swEndCap.UseThicknessRatioForOffset);

        }


        public SldWorks swApp;

    }

}
This example shows how to:

specify levels and values for importing IGES data. 
import an IGES file. 
//------------------------------------------------
// Preconditions: Substitute the path and name
// of your IGES file where noted in the code.
//
// Postconditions: 
// 1. Creates a folder named Layer 25.
// 2. Imports the specified IGES file into SOLIDWORKS
//    and moves the imported IGES features to Layer 25.
// 3. To verify, examine the graphics area and
//    FeatureManager design tree.
//--------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace ImportIGESFilesCSharp.csproj
{
    public partial class SolidWorksMacro
    {
        public void Main()
        {
 
            ModelDoc2 model = default(ModelDoc2);
            bool boolstatus = false;
            string fileName = null;
            string argString = null;
            ImportIgesData importData = default(ImportIgesData);
            int Err = 0;
            bool orgSetting = false;
            bool allLevels = false;
            object vOnlyLev = null;
            int[] onlyLev = new int[2];
            int oneLev = 0;
            Feature lastFeature = default(Feature);
            Feature newFolder = default(Feature);
            string newFolderName = "";
            string lastFeatureName = null;
 
 
            model = (ModelDoc2)swApp.ActiveDoc;
            // Substitute the path and name of your IGES file
            fileName = "C:\\beam_with_holes.igs";
            // "r" means open new document
            // "i" means insert into existing document
            if (model == null)
            {
                argString = "r";
                // There is an existing part, so use it
            }
            else
            {
                argString = "i";
            }
            // Fill in the import data
            importData = (ImportIgesData)swApp.GetImportFileData(fileName);
            if ((importData != null))
            {
                // Test the various flags
                importData.IncludeSurfaces = true;
                importData.IncludeCurves = true;
                importData.CurvesAsSketches = true;
                // False = Curves as Curves                 
                importData.ProcessByLevel = false;
                // Test all levels
                //        allLevels = True
                // False = levels specified in vOnlyLev
                //        newFolderName = "All levels"
                // or, test multiple levels
                //        onlyLev(0) = 0
                //        onlyLev(1) = 6
                //        vOnlyLev = onlyLev
                //        newFolderName = "Layer 0 and 6"
                // Or, test individual levels
                oneLev = 25;
                vOnlyLev = oneLev;
                newFolderName = "Layer " + oneLev.ToString();
                boolstatus = importData.SetLevels(allLevels, (vOnlyLev));
            }
 
            // Keep the last feature to determine what's been added
            //   If this is a new document, that cannot be done, so
            //   just hard code the name of the Origin feature,
            //   which is currently the last feature in a new part document
            //   It is better to always create a new
            //   document first, and then call SldWorks::LoadFile4
            //   with "i" argString to avoid this potential problem
            if ((model != null))
            {
                lastFeature = (Feature)model.FeatureByPositionReverse(0);
                lastFeatureName = lastFeature.Name;
            }
            else
            {
                lastFeatureName = "Origin";
            }
            // Setting this user preference to true means that the IGES
            //   dialog is displayed
            // Setting this user preference to false means that the
            //   IGES dialog is not displayed, and the import IGES data
            //   is used if it is passed in, or, if it is not,
            //   then the default values for the dialog are used
            orgSetting = swApp.GetUserPreferenceToggle((int)swUserPreferenceToggle_e.swIGESImportShowLevel);
            swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swIGESImportShowLevel, false);
            model = (ModelDoc2)swApp.LoadFile4(fileName, argString, importData, ref Err);
 
 
            // swApp.SetUserPreferenceToggle swUserPreferenceToggle_e.swIGESImportShowLevel, orgSetting
            // If the SldWorks::LoadFile4 failed, do not continue
            if (model == null)
            {
                Debug.Print("Problem loading file.");
                return;
            }
            // Retrieve all of the features that were created
            // and move them into their own new folder
            model.ClearSelection2(true);
            // Select features that are then used by FeatureManager::InsertFeatureTreeFolder2
            // Either method of selection seems to take the same amount of time
            boolstatus = select_new_features_individually(model, lastFeatureName);
            // boolstatus = multiselect_new_features(model, lastFeatureName);
            if ((boolstatus))
            {
                newFolder = model.FeatureManager.InsertFeatureTreeFolder2((int)swFeatureTreeFolderType_e.swFeatureTreeFolder_Containing);
                if ((newFolder != null))
                {
                    newFolder.Name = newFolderName;
                }
                model.ClearSelection2(true);
            }
        }
 
        private bool select_new_features_individually(ModelDoc2 model, string lastFeatureName)
        {
            bool functionReturnValue = false;
            Feature testFeature = default(Feature);
            int loopCount = 0;
            bool boolstatus = false;
            functionReturnValue = false;
            loopCount = 0;
            testFeature = (Feature)model.FeatureByPositionReverse(loopCount);
            while (((testFeature != null)) && (!(testFeature.Name == lastFeatureName)))
            {
                loopCount = loopCount + 1;
                boolstatus = testFeature.Select2(true, 0);
                if (!(boolstatus = false))
                {
                    functionReturnValue = true;
                }
                testFeature = (Feature)model.FeatureByPositionReverse(loopCount);
            }
            return functionReturnValue;
        }
 
        private bool multiselect_new_features(ModelDoc2 model, string lastFeatureName)
        {
            bool functionReturnValue = false;
            Feature testFeature = default(Feature);
            int loopCount = 0;
            Feature[] featureList = null;
            object vFeatureList = null;
            int longstatus = 0;
            SelectData selData = default(SelectData);
            SelectionMgr selMgr = default(SelectionMgr);
            functionReturnValue = false;
            loopCount = 0;
            testFeature = (Feature)model.FeatureByPositionReverse(loopCount);
            while (((testFeature != null)) && (!(testFeature.Name == lastFeatureName)))
            {
                loopCount = loopCount + 1;
                testFeature = (Feature)model.FeatureByPositionReverse(loopCount);
            }
            Array.Resize(ref featureList, (loopCount + 1));
 
            loopCount = 0;
            testFeature = (Feature)model.FeatureByPositionReverse(loopCount);
            while (((testFeature != null)) && (!(testFeature.Name == lastFeatureName)))
            {
                featureList[loopCount] = testFeature;
                loopCount = loopCount + 1;
                testFeature = (Feature)model.FeatureByPositionReverse(loopCount);
            }
 
            vFeatureList = featureList;
            selMgr = (SelectionMgr)model.SelectionManager;
            selData = (SelectData)selMgr.CreateSelectData();
            longstatus = model.Extension.MultiSelect2((vFeatureList), true, selData);
            if (longstatus > 0)
            {
                functionReturnValue = true;
            }
            return functionReturnValue;
        }
 
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
 
    }
}
This example shows how to insert a forming tool feature into a sheet metal part.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Open a sheet metal part.
// 2. Verify that the specified forming tool part exists.
// 3. Select a face on which to apply the counter sink emboss forming tool from
//    the Design Library.
//
// Postconditions: 
// 1. Inserts the counter sink emboss1 feature.
// 2. Examine the FeatureManager design tree and graphics area.
// ---------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;

namespace Macro1CSharp.csproj
{
    partial class SolidWorksMacro
    {
        ModelDoc2 Part;
        Feature myFeature;
        string formingTool;

        public void Main()
        {
            Part = (ModelDoc2)swApp.ActiveDoc;

            // Insert a counter sink emboss forming tool feature
            formingTool = "C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2016\\design library\\forming tools\\embosses\\counter sink emboss.sldprt";
            myFeature = Part.FeatureManager.InsertFormToolFeature(formingTool, false, 0.0, "", true, true, true, true, false);
        }

        public SldWorks swApp;
    }
} 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值