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