Hide Table of Contents

Create Derived Pattern Feature Example (VB.NET)

This example shows how to create a derived pattern feature.

'--------------------------------------------------------------------
' Preconditions:
' 1. Verify that the assembly to open exists.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Opens the assembly.
' 2. Creates a derived pattern feature.
' 3. Gets the type and name of the pattern feature used for
'    the derived pattern feature.
' 4. Changes the position of the pattern instance used as the seed
'    feature in the derived pattern feature.
' 5. Examine the FeatureManager design tree, Immediate window, and
'    graphics area.
'
' NOTE: Because the assembly is used elsewhere, do not save changes.
'--------------------------------------------------------------------
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 swModelDocExtension As ModelDocExtension
        Dim swFeatureManager As FeatureManager
        Dim swFeature As Feature
        Dim swDerivedPatternFeatureData As DerivedPatternFeatureData
        Dim fileName As String
        Dim status As Boolean
        Dim errors As Integer
        Dim warnings As Integer
        Dim patternObj As Feature
 
        fileName = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2017\tutorial\api\assem2.sldasm"
        swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
        swModelDocExtension = swModel.Extension
        swFeatureManager = swModel.FeatureManager

        swModel.ClearSelection2(True)
 
        ' Create derived pattern feature
        status = swModelDocExtension.SelectByID2("Part2^assem2-7@assem2""COMPONENT", 0, 0, 0, False, 1, Nothing, 0)
        status = swModelDocExtension.SelectByID2("LPattern1@Part3^assem2-1@assem2""BODYFEATURE", 0, 0, 0, True, 2, Nothing, 0)
        swFeature = swFeatureManager.InsertDerivedPattern2()
 
        ' Get derived pattern feature name and type
        If Not swFeature Is Nothing Then
            Debug.Print("Derived pattern feature name = " & swFeature.Name)
            Debug.Print("  Type of feature: " & swFeature.GetTypeName2)
            swDerivedPatternFeatureData = swFeature.GetDefinition()
            If Not swDerivedPatternFeatureData Is Nothing Then
                swDerivedPatternFeatureData.AccessSelections(swModel, Nothing)
                ' Get type of pattern feature used for derived pattern feature
                patternObj = swDerivedPatternFeatureData.PatternFeature
                Debug.Print("    Type of pattern feature used for derived pattern feature: " & patternObj.GetTypeName2)
		' Get pattern feature name
		Debug.Print("    Name of pattern feature used for the derived pattern feature: " & patternObj.Name)
		Dim swLinearPatternFeatureData As LinearPatternFeatureData
		' Get the pattern feature used for the derived pattern feature
		swLinearPatternFeatureData = patternObj.GetDefinition
		Dim nbrPatternInstances As Integer
		nbrPatternInstances = (swLinearPatternFeatureData.D1TotalInstances * swLinearPatternFeatureData.D2TotalInstances)
		Debug.Print("    Total number of pattern instances in pattern feature used for the derived pattern feature: " & nbrPatternInstances)
		' Get position of the pattern instance used as the seed feature in the derived pattern feature
		Debug.Print("      Position of the pattern instance used as the seed feature in the derived pattern feature: " & swDerivedPatternFeatureData.SeedPosition)
		' Change position of the pattern instance to use as the seed feature in the derived pattern feature
		swDerivedPatternFeatureData.SeedPosition = nbrPatternInstances - 1
		Debug.Print("      Modified position of the pattern instance to use as the seed feature in the derived pattern feature: " & swDerivedPatternFeatureData.SeedPosition)
		swFeature.ModifyDefinition(swDerivedPatternFeatureData, swModel, Nothing)
            End If
        End If
 
        swModel.ClearSelection2(True)
 
    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:   Create Derived 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) 2017 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.