Hide Table of Contents

Get Custom Property Values on Weldment Cut-list Folders Example (VBA)

This example shows how to get all of the custom property values on the weldment cut-list folders of a part in an assembly.

'-------------------------------------------------------
' Preconditions:
' 1. Open a new SOLIDWORKS session.
' 2. Open install_dir\samples\tutorial\api\weldment_box3.sldprt.
' 3. Click Tools > Options > Document Properties > Weldments >
'    Rename cut list folders with Description property value > OK.
' 4. Right-click Cut list(31) in the FeatureManager design tree
'    and click Update.
' 5. Verify that the specified assembly template exists.
' 6. Open the Immediate window.
'
' Postconditions:
' 1. Creates an assembly document and inserts the part document.
' 2. Traverses the part's FeatureManager design tree and gets
'    the names of custom properties, values, and evaluated values
'    for the cut-list folders in the part document.
' 3. Examine the Immediate window.
'
' NOTE: Because the part document is used elsewhere, do not
' save changes.
'-------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swAssem As SldWorks.AssemblyDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim status As Boolean
Dim errors As Long
Dim warnings As Long
Dim fileName As String
 
Sub VisitFeatureCustomProperties(swDocFeat As SldWorks.Feature)
    Dim swCustPropMgr As SldWorks.CustomPropertyManager
    Dim propNames As Variant
    Dim vName As Variant
    Dim propName As String
    Dim Value As String
    Dim resolvedValue As String
    Set swCustPropMgr = swDocFeat.CustomPropertyManager
    If Not swCustPropMgr Is Nothing Then
        propNames = swCustPropMgr.GetNames
        If Not IsEmpty(propNames) Then
            Debug.Print swDocFeat.Name, swDocFeat.GetTypeName
            For Each vName In propNames
                propName = vName
                Call swCustPropMgr.Get2(propName, Value, resolvedValue)
                Debug.Print "", "", propName, Value, resolvedValue
            Next vName
        End If
    End If
End Sub
 
Sub VisitDocWeldmentProperties(swCompDoc As SldWorks.ModelDoc2)
    Dim swFeature As SldWorks.Feature
    Dim swSubFeature As SldWorks.Feature
    Dim swCutFolder As SldWorks.BodyFolder
    Set swFeature = swCompDoc.FirstFeature
    Do While Not swFeature Is Nothing
        Set swSubFeature = swFeature.GetFirstSubFeature
        Do While Not swSubFeature Is Nothing
            If swSubFeature.GetTypeName2 = "CutListFolder" Then
                Set swCutFolder = swSubFeature.GetSpecificFeature2
            End If
            If Not swCutFolder Is Nothing Then
                    Call VisitFeatureCustomProperties(swSubFeature)
            End If
            Set swSubFeature = swSubFeature.GetNextSubFeature
        Loop
        Set swFeature = swFeature.GetNextFeature
    Loop
End Sub
 
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2016\templates\assembly.asmdot", 0, 0, 0)
    swApp.ActivateDoc2 "Assem1", False, errors
    Set swModel = swApp.ActiveDoc
    fileName = "C:\Program Files\SolidWorks Corp\SOLIDWORKS\samples\tutorial\api\weldment_box3.sldprt"
    Set swAssem = swModel
    swApp.ActivateDoc2 "Assem1", False, errors
    swAssem.AddComponent5 fileName, swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, "", False, "", 0.508489013092717, 0.724898979334123, 0.550645508621615
    Set swSelMgr = swModel.SelectionManager
    Set swModelDocExt = swModel.Extension
    status = swModelDocExt.SelectByID2("weldment_box3-1@Assem1", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
    Dim swSelComp As SldWorks.Component2
    Dim refConfig As String
    Dim swCompDoc As SldWorks.ModelDoc2
    Set swSelComp = swSelMgr.GetSelectedObject6(1, -1)
    Set swCompDoc = swSelComp.GetModelDoc
    Dim configNames As Variant
    Dim vName As Variant
    Dim configName As String
    configNames = swCompDoc.GetConfigurationNames()
    For Each vName In configNames
        configName = vName
        Debug.Print "-----------------------------------------------"
        Debug.Print "Configuration: " + configName
        status = swCompDoc.ShowConfiguration2(configName)
        Call VisitDocWeldmentProperties(swCompDoc)
    Next vName
End Sub


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Custom Property Values On Weldment Cut-list Folders Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.