Insert Weld Bead Example (VBA)
This example shows how to create a weld bead by programmatically selecting
the top, stop, and contact faces and passing those faces as arrays to
IAssemblyDoc::InsertWeld2.
'----------------------------------
' Preconditions: Open an assembly document
' in
which you want to insert a
' weld
bead.
'
' Postconditions: Weld bead created using the
' specified
top, stop, and contact
' faces.
Weld bead appears in the
' FeatureManager
design tree as a
' feature
and now exists as a SolidWorks
' part
document in c:\temp\bead2.sldprt.
'----------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swSelectionMgr As SldWorks.SelectionMgr
Dim topFaces(1) As Object
Dim t As Variant
Dim stopFaces(3) As Object
Dim s As Variant
Dim contactFaces(3) As Object
Dim c As Variant
Dim swAssembly As SldWorks.AssemblyDoc
Dim boolstatus As Boolean
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set swSelectionMgr = swModel.SelectionManager
' Select top faces for the weld bead
' Substitute your selections for the weld bead's top faces
boolstatus = swModelDocExt.SelectByID2("",
"FACE", -0.01559163546833, 0.02520890274226, 0.02853818512551,
True, 0, Nothing, 0)
Set topFaces(0) = swSelectionMgr.GetSelectedObject6(1,
-1)
boolstatus = swModelDocExt.SelectByID2("",
"FACE", 0.01969239735822, 0.03064046036471, 0.01000498670771,
True, 0, Nothing, 0)
Set topFaces(1) = swSelectionMgr.GetSelectedObject6(2,
-1)
t = topFaces
swModel.ClearSelection2
True
' Select stop faces for the weld bead
' Substitute your selections for the weld bead's stop
faces
boolstatus = swModelDocExt.SelectByID2("",
"FACE", -0.01445017029672, 0.01448327651559, 0.07619999999997,
True, 0, Nothing, 0)
Set stopFaces(0) = swSelectionMgr.GetSelectedObject6(1,
-1)
boolstatus = swModelDocExt.SelectByID2("",
"FACE", 0.01773464730298, 0.01977465429431, 0.0432803149497,
True, 0, Nothing, 0)
Set stopFaces(1) = swSelectionMgr.GetSelectedObject6(2,
-1)
boolstatus = swModelDocExt.SelectByID2("",
"FACE", 0.0195767596401, 0.02039971255846, -0.03291968505005,
True, 4, Nothing, 0)
Set stopFaces(2) = swSelectionMgr.GetSelectedObject6(3,
-1)
boolstatus = swModelDocExt.SelectByID2("",
"FACE", -0.0218293117176, 0.01005028977147, 0, True, 4, Nothing,
0)
Set stopFaces(3) = swSelectionMgr.GetSelectedObject6(4,
-1)
s = stopFaces
swModel.ClearSelection2
True
' Select contact faces for the weld bead
' Substitute your selections for the weld bead's contact
faces
boolstatus = swModelDocExt.SelectByID2("",
"FACE", -0.00139666394648, 0.0163969139561, 0.05736881478452,
True, 2, Nothing, 0)
Set contactFaces(0) = swSelectionMgr.GetSelectedObject6(1,
-1)
boolstatus = swModelDocExt.SelectByID2("",
"FACE", 0, 0.009181832977731, 0.05743695965685, True, 2, Nothing,
0)
Set contactFaces(1) = swSelectionMgr.GetSelectedObject6(2,
-1)
boolstatus = swModelDocExt.SelectByID2("",
"FACE", 0.01087386157639, 0.009644726364513, -0.02560526716087,
True, 2, Nothing, 0)
Set contactFaces(2) = swSelectionMgr.GetSelectedObject6(3,
-1)
boolstatus = swModelDocExt.SelectByID2("",
"FACE", 0.006349999999941, 0.02091223363979, -0.01486524507766,
True, 2, Nothing, 0)
Set contactFaces(3) = swSelectionMgr.GetSelectedObject6(4,
-1)
c = contactFaces
swModel.ClearSelection2
True
' Insert a weld bead
Set swAssembly = swModel
swAssembly.InsertWeld2
"BACK", "CNV", 0.009525, 0.009525, 0.0381, "C:\temp\bead2.sldprt",
t, s, c
End Sub