Hide Table of Contents

Copy Components With Mates to Assembly Example (VB.NET)

This example shows how to copy components with mates in an assembly.

'----------------------------------------------------------------------------

' Preconditions:

' 1. Open:

' <SolidWorks_install_dir>\samples\tutorial\driveworksxpress\mobile gantry.SLDASM.

' 2. Observe Leg<1> and Leg<2> in the FeatureManager design tree.

'

' Postconditions:

'    Leg<1> is replaced by a copy of Leg<2>:  observe Leg<3> in the mobile gantry.

'

' NOTE: Because this assembly is used in a SolidWorks online tutorial,

'       do not save any changes when you close it.

'----------------------------------------------------------------------------

Imports SolidWorks.Interop.sldworks

Imports System.Runtime.InteropServices

Partial Class SolidWorksMacro

    Sub main()

        Dim swModel As ModelDoc2

        Dim swModelDocExt As ModelDocExtension

        Dim swSelMgr As SelectionMgr

        Dim blRepeat(2) As Boolean

        Dim blFlip(2) As Boolean

        Dim SelectedComps As Object

        Dim RepeatOptions As Object

        Dim MateRefs As Object

        Dim InpValues As Object

        Dim FlipValues As Object

        Dim swAssy As AssemblyDoc

        Dim swItem As Component

        Dim swFeature As Feature

        Dim refPlane As RefPlane

        Dim arrMateEntities(2) As Object

        Dim arrCompsToCopy(0) As Object

        Dim boolstatus As Boolean

        Dim dValues(2) As Double

        ' Disable Visual Basic error on implicit Query Interface

        'On Error Resume Next

        swModel = swApp.ActiveDoc

        swAssy = swModel

        swSelMgr = swModel.SelectionManager

        swModelDocExt = swModel.Extension

        boolstatus = swModelDocExt.SelectByID2("Leg-1@mobile gantry", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

        swModel.EditDelete()

        swModel.ClearSelection2(True)

        boolstatus = swModelDocExt.SelectByID2("Leg-2@mobile gantry", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

        swItem = CType(swSelMgr.GetSelectedObject6(1, -1), Component2)

        arrCompsToCopy(0) = swItem

        arrMateEntities(0) = Nothing

        arrMateEntities(1) = Nothing

        swModel.ClearSelection2(True)

        boolstatus = swModelDocExt.SelectByID2("Left End@Universal Beam-1@mobile gantry", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

        swFeature = CType(swSelMgr.GetSelectedObject6(1, -1), Feature)

        refPlane = CType(swFeature.GetSpecificFeature2, RefPlane)

        arrMateEntities(2) = refPlane

        swModel.ClearSelection2(True)

        blRepeat(0) = True

        blRepeat(1) = True

        blRepeat(2) = False

        SelectedComps = arrCompsToCopy

        RepeatOptions = blRepeat

        MateRefs = arrMateEntities

        dValues(0) = 0.0

        dValues(1) = 0.0

        dValues(2) = 0.0

        InpValues = dValues

        blFlip(0) = False

        blFlip(1) = False

        blFlip(2) = False

        FlipValues = blFlip

 

        Dim disparrCompsToCopy(0) As DispatchWrapper

        disparrCompsToCopy(0) = New DispatchWrapper(arrCompsToCopy(0))

 

        Dim dispMateRefs(2) As DispatchWrapper

        dispMateRefs(0) = New DispatchWrapper(MateRefs(0))

        dispMateRefs(1) = New DispatchWrapper(MateRefs(1))

        dispMateRefs(2) = New DispatchWrapper(MateRefs(2))

 

        'Repeat all mates except the coincident mate with Right End@Universal Beam-1

        swAssy.CopyWithMates((disparrCompsToCopy), RepeatOptions, (dispMateRefs), InpValues, FlipValues)

        swAssy.EditRebuild()

    End Sub

    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:   Copy Components With Mates to Assembly 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) 2014 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.