Professional Documents
Culture Documents
This example shows how to delete and insert instances in a variable pattern
feature.
//--------------------------------------------------------------
// Preconditions:
// 1. Open public_documents\tutorial\api\bottle.sldprt.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Selects the variable pattern feature.
// 2. Rolls back and accesses the variable pattern feature.
// a. Deletes the last instance of the variable pattern in the table.
// b. Deletes a dimension in the table.
// c. Gets the names of the controlling dimensions.
// d. Inserts a new instance in the table.
// e. Rolls forward the variable pattern feature.
// NOTE: It can take several minutes for this step to complete.
// 3. Selects the variable pattern again.
// a. Rolls back and accesses the variable pattern feature.
// b. Sets new values for the new instance.
// c. Rolls forward the variable pattern feature.
// 4. Examine the Immediate window and graphics area.
//
// NOTE: Because the part is used elsewhere, do not save change.
//---------------------------------------------------------------
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()
{
swModel = (ModelDoc2)swApp.ActiveDoc;
swModelDocExt = (ModelDocExtension)swModel.Extension;
swSelMgr = (SelectionMgr)swModel.SelectionManager;
status = swModelDocExt.SelectByID2("VarPattern1", "BODYFEATURE", 0, 0,
0, false, 0, null, 0);
swFeature = (Feature)swSelMgr.GetSelectedObject6(1, -1);
swDimensionDrivenTablePatternFeat =
(DimPatternFeatureData)swFeature.GetDefinition();
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}