Files
Get weldment profile and cut list custom properties Associated model(s)
Code
'This macro demonstrates how to get weldment feature and cut list _
property information, which could be used as the basis for a _
macro that changes the weldment feature and cut list properties.
'Preconditions: part with weldment member made from iso pipe 26.9 x 3.2 _
is open
'Results: all weldment features have their profile and cut list _
properties information printed to the immediate window
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Sub main()
Set swApp = Application.SldWorks
'traverse features
Set swModel = swApp.ActiveDoc
Set swFeat = swModel.FirstFeature
While Not swFeat Is Nothing
If swFeat.GetTypeName = "WeldMemberFeat" Then Call VerifyStructuralMember
If swFeat.GetTypeName = "CutListFolder" Then Call GetCutListCustProps
Set swFeat = swFeat.GetNextFeature
Wend
End Sub
'change the weldment member to 33.7 x 4.0 if it is 26.9 x 3.2
Sub VerifyStructuralMember()
Dim swStructFeatData As SldWorks.StructuralMemberFeatureData
Dim swWeldCutListFeat As SldWorks.WeldmentCutListFeature
Dim swWeldCutListAnn As SldWorks.WeldmentCutListAnnotation
Dim strProfileFolder As String
Dim strProfile As String
'get weldment profile location; note that if a list exists the values are _
separated by a semi-colon
strProfileFolder = _
swApp.GetUserPreferenceStringValue(swFileLocationsWeldmentProfiles)
If InStr(1, strProfileFolder, ";") <> 0 Then _
strProfileFolder = Left(strProfileFolder, InStr(1, strProfileFolder, ";") - 1)
strProfileFolder = strProfileFolder & "\"
'get the feature definition and modify if condition is true
Set swStructFeatData = swFeat.GetDefinition
swStructFeatData.AccessSelections swModel, Nothing
Debug.Print swFeat.Name
strProfile = swStructFeatData.WeldmentProfilePath
strProfile = Replace(strProfile, ".sldlfp", "")
strProfile = Right(strProfile, Len(strProfile) - InStrRev(strProfile, "\"))
Debug.Print " Current profile: " & strProfile
If strProfile = "26.9 x 3.2" Then
strProfile = strProfileFolder & "iso\pipe\33.7 x 4.0.sldlfp"
swStructFeatData.WeldmentProfilePath = strProfile
End If
swFeat.ModifyDefinition swStructFeatData, swModel, Nothing
End Sub
'Get the weldment cut list properties
Sub GetCutListCustProps()
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim vPropNames As Variant, vPropTypes As Variant, vPropValues As Variant
Dim i As Integer
Set swCustPropMgr = swFeat.CustomPropertyManager
swCustPropMgr.GetAll vPropNames, vPropTypes, vPropValues
For i = 0 To UBound(vPropNames)
Debug.Print " Property name: " & vPropNames(i)
Debug.Print " Property types: " & vPropTypes(i)
Debug.Print " Property values: " & vPropValues(i)
Next i
End Sub
'Notes:
'The feature type name for the Weldment feature (the one that appears at the _
beginning of the feature manager tree is a "WeldmentFeature". A structural _
member is considered a "WeldMemberFeat". The cut list folder is considered _
a "CutListFolder" object. The cut list folder is technically an IBodyFolder _
object.
'Even though IStructuralMemberFeatureData::WeldmentProfilePath doesn't seem _
to affect entity selections, you still need to use IStructuralMemberFeatureData:: _
AccessSelections
'IWeldmentCutListFeature pertains only to the weldment cut list table found in drawings.