Hello SW Forums,
I get a lot of part files from China. As such, the entire feature tree is in Chinese, and makes working with the files a headache. I would like to rename each element in the feature tree back to English, starting from the top. See below picture for an ideal before/after:
This seems like an ideal task for a macro. I've done some googling and found this thread: feature manager drawwing renaming macro
This seems to do exactly what I want, but it only works on drawings. I would like it to work on parts, and I have very little experience in the way of SolidWorks coding. Can anyone make this work for part files? That would be tremendous.
Victor,
I use a macro to rename all the imported pieces under the origin after the main file (eliminates proprietary info). It's not exactly what you need since I skip over everything above the origin, but you should be able to rewrite those sections to fit your needs. I have a lot of Japanese stored in files, so gettypename works better than trying to get ascii characters that VBA treats as wildcards.
Good luck:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swFeatMgr As SldWorks.FeatureManager
Dim count As Long
Dim featArr As Variant
Dim swSelMgr As SldWorks.SelectionMgr
Dim swModeler As SldWorks.Modeler
Dim TYP
Dim f, fs, fso
Dim strPath As String
Dim strFile As String
Dim X, path, xlWB
Public fr
Dim ExcelRunning As Boolean
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub Rename_Feature()
Set swApp = Application.SldWorks
Set swModeler = swApp.GetModeler
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set swFeatMgr = swModel.FeatureManager
count = swFeatMgr.GetFeatureCount(False)
featArr = swFeatMgr.GetFeatures(False)
Set swSelMgr = swModel.SelectionManager
'MsgBox featArr(i).Name
Dim doc_nam, doc_split, doc_count, doc_path, d, nam, rcount
doc_nam = swModel.GetPathName
doc_split = Split(doc_nam, "\")
doc_count = UBound(doc_split)
nam = Split(doc_split(doc_count), ".")
rcount = swFeatMgr.GetFeatureCount(True) + 1
Dim i, t
i = 1
Set swSelMgr = swModel.SelectionManager
Do Until i = rcount + 1
If featArr(i).GetTypeName = "MateGroup" Then
Exit Do
Else
If featArr(i).GetTypeName = "OriginProfileFeature" Then
i = i + 1 ' skip 2 folders (1 normally)
Do Until i = rcount
If Len(i - 15) = 1 Then
t = nam(0) & "_000" & i - 15
Else
If Len(i - 15) = 2 Then
t = nam(0) & "_00" & i - 15
Else
If Len(i - 15) = 3 Then
t = nam(0) & "_0" & i - 15
Else
t = nam(0) & "_" & i - 15
End If
End If
End If
If featArr(i).Name = t Then
'Do Nothing
Else
featArr(i).Name = t
End If
i = i + 1
Loop
End If
End If
i = i + 1
Loop
swModel.Save
End Sub