Make Smart Component with Associated Features Example (VBA)
This example shows how to create a Smart Component with associated features.
'--------------------------------------------------
'
' Preconditions: Assembly with a rod and plate with a
' hole
for the rod is open.
'
' Postconditions: A Smart Component with associated
' features
is created.
'
'--------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssembly As SldWorks.AssemblyDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim pFeat As Object
Dim pComp As Object
Dim pFeatArr(0) As Object
Dim boolstatus As Boolean
Dim relcomp As Variant
Dim relfeat As Variant
Dim boundval As Variant
Dim retval As Boolean
Sub main()
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swAssembly = swModel
Set
swSelMgr = swModel.SelectionManager
Set
swModelDocExt = swModel.Extension
'
Select the feature to make smart
boolstatus
= swModelDocExt.SelectByID2("Extrude1@rod-1@Assem5",
"BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
'
Select the component to make smart
boolstatus
= swModelDocExt.SelectByID2("plate-1@Assem5",
"COMPONENT", 0, 0, 0, True, 0, Nothing, 0)
Set
pFeat = swSelMgr.GetSelectedObject6(1,
0)
Set
pComp = swSelMgr.GetSelectedObject6(2,
0)
Set
pFeatArr(0) = pFeat
relfeat
= pFeatArr
'
Create the Smart Component
retval
= swAssembly.CreateSmartComponent(pComp,
(relcomp), (relfeat), False, Nothing, boundval)
End Sub