Hide Table of Contents

Insert Variable Pattern Feature Example (VB.NET)

This example shows how to insert a variable pattern feature.

'----------------------------------------------------------------------------
' Preconditions:
' 1. Verify that the specified part to open exists.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Inserts a variable pattern feature.
' 2. Examine the graphics area and the Immediate window.
'
NOTE: Because this model is used elsewhere, do not save any
' changes when closing it.
'----------------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
 
Partial Class SolidWorksMacro
 
    Public Sub Main()
 
        Dim swModel As ModelDoc2
        Dim swModelDocExt As ModelDocExtension
        Dim swFeatureManager As FeatureManager
        Dim swFeature As Feature
        Dim swDimensionDrivenTablePatternFeat As DimPatternFeatureData 
        Dim fileName As String
        Dim status As Boolean
        Dim errors As Integer, warnings As Integer
        Dim nbr As Integer
        Dim dimNbr As Integer
        Dim i As Integer
	Dim j As Integer
	Dim controllingDimNames() As String
	Dim controllingDimName As String
	Dim instanceName As String
	Dim instanceNames() As String
	Dim patternName As String
 
        fileName = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\api\cstick.sldprt"
        swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
        swModelDocExt = swModel.Extension
 
        status = swModelDocExt.SelectByID2("Sweep1""BODYFEATURE", 0, 0, 0, True, 0, Nothing, 0)
        status = swModelDocExt.SelectByID2("Sketch1""SKETCH", 0, 0, 0, True, 0, Nothing, 0)
        swModel.ClearSelection2(True)
 
        'Select feature to pattern
        status = swModelDocExt.SelectByID2("Sweep1""BODYFEATURE", 0, 0, 0, False, 4, Nothing, 0)
 
        'Select reference geometry to drive seed feature
        status = swModelDocExt.SelectByID2("Sketch1""SKETCH", 0, 0, 0, True, 1048576, Nothing, 0)
 
        'Populate pattern table
        swFeatureManager = swModel.FeatureManager
        status = swFeatureManager.InsertVaryInstanceOverride("D1@Sketch2@cstick.SLDPRT", 256, 1, 0, 1, 0, 0.085)
        status = swFeatureManager.InsertVaryInstanceOverride("D3@Sketch2@cstick.SLDPRT", 256, 1, 0, 1, 0, 0.04)
        status = swFeatureManager.InsertVaryInstanceOverride("D4@Sketch2@cstick.SLDPRT", 256, 1, 0, 1, 0, 0.03)
        status = swFeatureManager.InsertVaryInstanceOverride("D1@Sketch2@cstick.SLDPRT", 256, 1, 0, 2, 0, 0.105)
        status = swFeatureManager.InsertVaryInstanceOverride("D3@Sketch2@cstick.SLDPRT", 256, 1, 0, 2, 0, 0.06)
        status = swFeatureManager.InsertVaryInstanceOverride("D4@Sketch2@cstick.SLDPRT", 256, 1, 0, 2, 0, 0.05)
 
        'Insert the advanced variable pattern feature
        'and access its feature data
        swFeature = swFeatureManager.FeatureAdvancedTableDrivenPattern
        swDimensionDrivenTablePatternFeat = swFeature.GetDefinition
        status = swDimensionDrivenTablePatternFeat.AccessSelections(swModel, Nothing)

        nbr = swDimensionDrivenTablePatternFeat.GetInstanceCount
        Debug.Print("Number of pattern instances: " & nbr)
        dimNbr = swDimensionDrivenTablePatternFeat.GetControllingDimensionCount
        Debug.Print("Number of controlling dimensions: " & dimNbr)
        Debug.Print("  Controlling dimension names: ")
        ReDim controllingDimNames(dimNbr)
        For i = 0 To dimNbr - 1
            controllingDimNames(i) = swDimensionDrivenTablePatternFeat.GetControllingDimensionName(i)
            controllingDimName = controllingDimNames(i)
            Debug.Print("     " & controllingDimName)
        Next i
 
        Debug.Print("Names of pattern instances:")
        ReDim instanceNames(nbr - 1)
        j = 0
        For i = 1 To nbr
            instanceName = swDimensionDrivenTablePatternFeat.GetInstanceNameByIndex(i)
            Debug.Print("  " & instanceName)
            instanceNames(j) = instanceName
            j = j + 1
        Next i
 
        Debug.Print("Table row indices of pattern instances:")
        For i = 0 To nbr - 1
            Debug.Print("  " & swDimensionDrivenTablePatternFeat.GetTableRowIndex(instanceNames(i)) & ": " & instanceNames(i))
        Next i

        Debug.Print("Pattern dimension names: ")
        j = 1
        For i = 0 To nbr - 1
            patternName = swDimensionDrivenTablePatternFeat.GetInstanceDimensionName(instanceNames(i), controllingDimNames(i + 1))
            Debug.Print("  " & patternName & ": " & instanceNames(i) & ": Controlling dimension name: " & swDimensionDrivenTablePatternFeat.GetControllingDimensionName(i + 1))
            j = j + 1
        Next i

        Debug.Print("Pattern instance suppression state:")
        For i = 0 To nbr - 1
            Debug.Print("  " & swDimensionDrivenTablePatternFeat.GetInstanceSuppressStateByIndex(swDimensionDrivenTablePatternFeat.GetTableRowIndex(instanceNames(i))) & ": " & instanceNames(i))
        Next i

        swDimensionDrivenTablePatternFeat.ReleaseSelectionAccess()
  
    End Sub
 
    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    Public swApp As SldWorks
 
 
End Class
 


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Insert Variable Pattern Feature Example (VB.NET)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.