Insert Cosmetic Weld Bead Example (VBA)
This example shows how to insert a cosmetic weld bead feature and access its
properties.
'----------------------------------------------------------------------------
' Preconditions: Open:
' install_dir\samples\tutorial\api\Insert_weld.sldprt
'
' Postconditions:
' 1. A fillet weld, Weld Bead2, is created and added to the Weld Folder in
' the FeatureManager design tree.
' 2. Inspect the Immediate window for Weld Bead1 settings and properties.
'
' NOTE: Because the model is used elsewhere,
' do not save changes when closing it.
' ---------------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim FeatureData As SldWorks.CosmeticWeldBeadFeatureData
Dim WeldFolder As SldWorks.CosmeticWeldBeadFolder
Dim selman As SldWorks.SelectionMgr
Dim myFeature As SldWorks.Feature
Option Explicit
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("",
"FACE", -3.44320907599354E-02, 1.70180000000641E-02, -2.27566098720899E-03,
False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("",
"FACE", -1.61637176506133E-02, 5.03122973344716E-02, -1.3752238241409E-03, True,
0, Nothing, 0)
Set myFeature = Part.FeatureManager.InsertCosmeticWeldBead(0.51)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Weld
Bead1", "COSMETIC_WELD", 0, 0, 0, False, 0, Nothing, 0)
Set selman = Part.SelectionManager
Set myFeature = selman.GetSelectedObject6(1, 0)
Set FeatureData = myFeature.GetDefinition
FeatureData.AccessSelections Part, Nothing
Debug.Print "weld bead settings: "
Debug.Print " weld bead size was " & FeatureData.BeadSize
FeatureData.BeadSize = 0.6
Debug.Print " weld bead size is now " &
FeatureData.BeadSize
Debug.Print " tangent propagation? " &
FeatureData.TangentPropagation
Debug.Print " weld sides as defined in
swCosmeticWeldBeadSide_e: " & FeatureData.Side
Debug.Print " from/to length properties enabled?
" & FeatureData.FromToLength
If FeatureData.FromToLength = False Then
FeatureData.FromToLength =
True
End If
If FeatureData.FromToLength = True Then
Debug.Print " start weld
at: " & FeatureData.FromToStartPoint
Debug.Print " weld
length: " & FeatureData.FromToWeldLength
Debug.Print " reverse
weld? " & FeatureData.FromToReverse
End If
Debug.Print " intermittent weld properties
enabled? " & FeatureData.IntermittentWeld
If FeatureData.IntermittentWeld = False Then
FeatureData.IntermittentWeld =
True
End If
If FeatureData.IntermittentWeld = True Then
If FeatureData.GapOrPitch =
True Then
Debug.Print "
intermittent gap: " & FeatureData.Gap
Debug.Print "
intermittent weld length: " & FeatureData.IntermittentWeldLength
Else
Debug.Print "
intermittent pitch: " & FeatureData.Pitch
Debug.Print "
intermittent weld length: " & FeatureData.IntermittentWeldLength
Debug.Print "
stagger welds if welding on both sides? " & FeatureData.Staggered
End If
End If
Set WeldFolder = FeatureData.GetWeldBeadFolder
Debug.Print "weld bead properties:"
Debug.Print " weld material was " & WeldFolder.Material
WeldFolder.Material = "Steel"
Debug.Print " weld material is now " &
WeldFolder.Material
Debug.Print " welding cost per unit mass: " &
WeldFolder.CostPerUnitMass
Debug.Print " weld mass per unit length: " &
WeldFolder.MassPerUnitLength
Debug.Print " number of weld passes: " &
WeldFolder.NumberOfWeldPasses
Debug.Print " weld process: " & WeldFolder.Process
Debug.Print " welding time per unit length: " &
WeldFolder.TimePerUnitLength
Debug.Print " total welding cost: " & WeldFolder.TotalCost
Debug.Print " total weld length: " & WeldFolder.TotalLength
Debug.Print " total weld mass: " & WeldFolder.TotalMass
Debug.Print " total number of welds: " &
WeldFolder.TotalNumber
Debug.Print " total welding time: " & WeldFolder.TotalTime
boolstatus = myFeature.ModifyDefinition(FeatureData,
Part, Nothing)
End Sub