Insert Weld Bead Example (VB.NET)
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:
' 1. Weld bead created using the specified
top, stop, and contact
' faces.
' 2. Weld bead appears in the FeatureManager
design tree as a
' feature
and now exists as a SolidWorks part
document
' in c:\temp\bead2.sldprt.
'----------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
Partial Class SolidWorksMacro
Public
Sub main()
Dim
swModel As ModelDoc2
Dim
swModelDocExt As ModelDocExtension
Dim
swSelectionMgr As SelectionMgr
Dim
selFace As Face2
Dim
topFaces(1) As Face2
Dim
t As Object
Dim
stopFaces(3) As Face2
Dim
s As Object
Dim
contactFaces(3) As Face2
Dim
c As Object
Dim
swAssembly As AssemblyDoc
Dim
boolstatus As Boolean
swModel
= swApp.ActiveDoc
swModelDocExt
= swModel.Extension
swSelectionMgr
= swModel.SelectionManager
'
Select top faces
'
Substitute your selections for the weld bead's top faces
boolstatus
= swModelDocExt.SelectByID2("",
"FACE", -0.01559163546833, 0.02520890274226, 0.02853818512551,
True, 0, Nothing, 0)
selFace
= swSelectionMgr.GetSelectedObject6(1,
-1)
topFaces(0)
= selFace
boolstatus
= swModelDocExt.SelectByID2("",
"FACE", 0.01969239735822, 0.03064046036471, 0.01000498670771,
True, 0, Nothing, 0)
selFace
= swSelectionMgr.GetSelectedObject6(2,
-1)
topFaces(1)
= selFace
t
= topFaces
swModel.ClearSelection2(True)
'
Select stop faces
'
Substitute your selections for the weld bead's stop faces
boolstatus
= swModelDocExt.SelectByID2("",
"FACE", -0.01445017029672, 0.01448327651559, 0.07619999999997,
True, 0, Nothing, 0)
selFace
= swSelectionMgr.GetSelectedObject6(1,
-1)
stopFaces(0)
= selFace
boolstatus
= swModelDocExt.SelectByID2("",
"FACE", 0.01773464730298, 0.01977465429431, 0.0432803149497,
True, 0, Nothing, 0)
selFace
= swSelectionMgr.GetSelectedObject6(2,
-1)
stopFaces(1)
= selFace
boolstatus
= swModelDocExt.SelectByID2("",
"FACE", 0.0195767596401, 0.02039971255846, -0.03291968505005,
True, 4, Nothing, 0)
selFace
= swSelectionMgr.GetSelectedObject6(3,
-1)
stopFaces(2)
= selFace
boolstatus
= swModelDocExt.SelectByID2("",
"FACE", -0.0218293117176, 0.01005028977147, 0, True, 4, Nothing,
0)
selFace
= swSelectionMgr.GetSelectedObject6(4,
-1)
stopFaces(3)
= selFace
s
= stopFaces
swModel.ClearSelection2(True)
'
Select contact faces
'
Substitute your selections for the weld bead's contact faces
boolstatus
= swModelDocExt.SelectByID2("",
"FACE", -0.00139666394648, 0.0163969139561, 0.05736881478452,
True, 2, Nothing, 0)
selFace
= swSelectionMgr.GetSelectedObject6(1,
-1)
contactFaces(0)
= selFace
boolstatus
= swModelDocExt.SelectByID2("",
"FACE", 0, 0.009181832977731, 0.05743695965685, True, 2, Nothing,
0)
selFace
= swSelectionMgr.GetSelectedObject6(2,
-1)
contactFaces(1)
= selFace
boolstatus
= swModelDocExt.SelectByID2("",
"FACE", 0.01087386157639, 0.009644726364513, -0.02560526716087,
True, 2, Nothing, 0)
selFace
= swSelectionMgr.GetSelectedObject6(3,
-1)
contactFaces(2)
= selFace
boolstatus
= swModelDocExt.SelectByID2("",
"FACE", 0.006349999999941, 0.02091223363979, -0.01486524507766,
True, 2, Nothing, 0)
selFace
= swSelectionMgr.GetSelectedObject6(4,
-1)
contactFaces(3)
= selFace
c
= contactFaces
swModel.ClearSelection2(True)
'
Insert a weld bead
swAssembly
= swModel
swAssembly.InsertWeld2("BACK", "CNV",
0.009525, 0.009525, 0.0381, "C:\temp\bead2.sldprt", t, s, c)
End
Sub
'''
<summary>
'''
The SldWorks swApp variable is pre-assigned for you.
'''
</summary>
Public
swApp As SldWorks
End Class