Hide Table of Contents

Add Components Example (VBA)

This example comes from a Visual Basic form. The form collected all of the transform information for each component to be added to the assembly. This example assumes that the active document is an assembly.

 

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

Private Sub cmdAdd_Click()

Dim swApp As Object

Dim Part As Object

 

Dim count As Long

Dim startX As Double, startY As Double, startZ As Double

Dim incrX As Double, incrY As Double, incrZ As Double

Dim compScale As Double, incrScale As Double

Dim index1 As Integer, index2 As Integer

Dim listSize As Integer, listIndex As Integer

 

Dim compNames() As String

Dim compXforms() As Double

 

Dim vcompNames As Variant

Dim vcompXforms As Variant

Dim vcomponents As Variant

 

‘ Get the number of components to add

count = Val(txtCompCount.Text) 

If (count < 1) Then

Exit Sub

End If

 

‘ Number of unique component filenames to add

listSize = lstCompNames.ListCount 

ReDim compNames(count - 1)

ReDim compXforms(count * 16 - 1)

 

Set swApp = CreateObject("SldWorks.Application")

Set Part = swApp.ActiveDoc

 

' Should make sure this is an Assembly document

' For each component to be added, create a separate transform

If (Not Part Is Nothing) Then

For i = 1 To count

index1 = i - 1

index2 = (i - 1) * 16

 

' Components can be added multiple times, transforms cannot

listIndex = index1 Mod listSize

compNames(index1) = lstCompNames.List(listIndex)

' Fill in the rotation component of the transform

compXforms(index2) = Val(txtCompOrient(0).Text)

compXforms(index2 + 1) = Val(txtCompOrient(1).Text)

compXforms(index2 + 2) = Val(txtCompOrient(2).Text)

compXforms(index2 + 3) = Val(txtCompOrient(3).Text)

compXforms(index2 + 4) = Val(txtCompOrient(4).Text)

compXforms(index2 + 5) = Val(txtCompOrient(5).Text)

compXforms(index2 + 6) = Val(txtCompOrient(6).Text)

compXforms(index2 + 7) = Val(txtCompOrient(7).Text)

compXforms(index2 + 8) = Val(txtCompOrient(8).Text)

 

' Add the translation component of the transform

compXforms(index2 + 9) = Val(txtCompX.Text) + (index1 * Val(txtCompIncrX.Text))

compXforms(index2 + 10) = Val(txtCompY.Text) + (index1 * Val(txtCompIncrY.Text))

compXforms(index2 + 11) = Val(txtCompZ.Text) + (index1 * Val(txtCompIncrZ.Text))

 

' Add the scale component of the transform

compXforms(index2 + 12) = Val(txtCompScale.Text) + (index1 * Val(txtCompIncrScale.Text))

Next i

 

' Add the components to the assembly.

vcompNames = compNames

vcompXforms = compXforms

vcomponents = Part.AddComponents((vcompNames), (vcompXforms))

End If

 

End Sub

 

 



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:   Add Components Example (VBA)
*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) 2010 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.