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: Input file, SOLIDWORKSFilenames.txt, exists in the

' the specified folder and contains the paths and names of

' the SOLIDWORKS part documents for which you want the

' creators of the features identified.

'

' Postconditions: Output file, SOLIDWORKSFilenamesFeatureCreators.txt,

' is created in the specified folder and contains the names of the part

' documents, their features, and the names of their creators.

'-------------------------------------------------

Option Explicit
 

Sub main()    
 

    Dim Filename

    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:\SOLIDWORKSFilenames.txt" For Input As #1

 

    ' Create and open the output file where to write the

    ' name of the part document and its feature and their creators

    Open "C:\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

            Loop

     

            ' Close part document

            swApp.CloseDoc Filename

        

       Loop

    

    ' 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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Names of Creators of Features 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.