Hide Table of Contents

Get Names of Creators of Features Example (VBA)

This example shows how to get the names of the creators of the features in multiple part documents.

' Preconditions: Create the input file c:\temp\SOLIDWORKSFilenames.txt
' in a text editor and add the paths and file names of the
' SOLIDWORKS part documents for which you want the creators of the
' features identified.
' Postconditions:
' 1. Opens c:\temp\SOLIDWORKSFilenames.txt.
' 2. Creates and opens c:\temp\SOLIDWORKSFilenamesFeatureCreators.txt.
' 2. Reads the name of the first part document.
' 3. Writes the name of the part document to 
'    c:\temp\SOLIDWORKSFilenamesFeatureCreators.txt.
' 4. Opens the part document and iterates over its FeatureManager design tree 
'    and writes the name of each feature and its creator to 
'    c:\temp\SOLIDWORKSFilenamesFeatureCreators.txt.
' 5. Closes the part document.
' 6. Repeats steps 2 - 5 for each subsequent part document in
'    c:\temp\SOLIDWORKSFilenamesFeatureCreators.txt.
' 7. Closes c:\temp\SOLIDWORKSFilenamesFeatureCreators.txt and
'    c:\temp\SOLIDWORKSFilenamesFeatureCreators.txt.
' 8. Open c:\temp\SOLIDWORKSFilenamesFeatureCreators.txt in a text editor
'    and examine the contents of the file.
Option Explicit
Sub main()
    Dim Filename As String
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swFeat As SldWorks.Feature
    Dim fileerror As Long
    Dim filewarning As Long
    ' Disable Visual Basic error on implicit Query Interface
    On Error Resume Next
    Set swApp = Application.SldWorks
    ' Open the input file with the list of part documents to
    ' open and get feature and name of its creator
    Open "C:\temp\SOLIDWORKSFilenames.txt" For Input As #1
    ' Create and open the output file where to write the
    ' name of the part document and its features and their creators
    Open "C:\temp\SOLIDWORKSFilenamesFeatureCreators.txt" For Output As #2
       ' While not at the end of the input file, read the name of
       ' the part document to open
       Do While Not EOF(1)
            Line Input #1, Filename
            'Write the name of the part document to open to the output file
            Write #2, "============================================================================="
            Write #2, Filename
            ' Open document
            swApp.OpenDoc6 Filename, swDocPART, swOpenDocOptions_Silent, "", fileerror, filewarning
            Set swModel = swApp.ActiveDoc
            ' Get first feature in this part document
            Set swFeat = swModel.FirstFeature
            ' Iterate over features in this part document in FeatureManager design tree
            Do While Not swFeat Is Nothing
                ' Write the name of the feature and its creator to the output file
                Write #2, "  Feature " & swFeat.Name & " created by " & swFeat.CreatedBy
                ' Get next feature in this part document
                Set swFeat = swFeat.GetNextFeature
            ' Close part document
            swApp.CloseDoc Filename
    ' Close the input file
    Close #1
    'Close the output file
    Write #2, "============================================================================="
    Close #2
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

Subject:   Feedback on Help Topics
Page:   Get Names of Creators of Features Example (VBA)
*   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:


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

Web Help Content Version: API Help (English only) 2016 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.