Option Explicit '選択するフィーチャー名(一部でも可) Const SearchName As String = "3Dスケッチ1" Sub TraverseFeatureFeatures(swFeat As SldWorks.Feature, nLevel As Long) Dim swSubFeat As SldWorks.Feature Dim swSubSubFeat As SldWorks.Feature Dim swSubSubSubFeat As SldWorks.Feature Dim sPadStr As String Dim i As Long For i = 0 To nLevel sPadStr = sPadStr + " " Next i While Not swFeat Is Nothing Debug.Print sPadStr + swFeat.Name + " [" + swFeat.GetTypeName + "]" 'フィーチャー名にSearchNameが含まれていれば選択 If InStr(swFeat.Name, SearchName) > 0 Then swFeat.Select2 True, 0 Set swSubFeat = swFeat.GetFirstSubFeature While Not swSubFeat Is Nothing Debug.Print sPadStr + " " + swSubFeat.Name + " [" + swSubFeat.GetTypeName + "]" 'フィーチャー名にSearchNameが含まれていれば選択 If InStr(swSubFeat.Name, SearchName) > 0 Then swSubFeat.Select2 True, 0 Set swSubSubFeat = swSubFeat.GetFirstSubFeature While Not swSubSubFeat Is Nothing Debug.Print sPadStr + " " + swSubSubFeat.Name + " [" + swSubSubFeat.GetTypeName + "]" 'フィーチャー名にSearchNameが含まれていれば選択 If InStr(swSubSubFeat.Name, SearchName) > 0 Then swSubSubFeat.Select2 True, 0 Set swSubSubSubFeat = swSubFeat.GetFirstSubFeature While Not swSubSubSubFeat Is Nothing Debug.Print sPadStr + " " + swSubSubSubFeat.Name + " [" + swSubSubSubFeat.GetTypeName + "]" 'フィーチャー名にSearchNameが含まれていれば選択 If InStr(swSubSubSubFeat.Name, SearchName) > 0 Then swSubSubSubFeat.Select2 True, 0 Set swSubSubSubFeat = swSubSubSubFeat.GetNextSubFeature() Wend Set swSubSubFeat = swSubSubFeat.GetNextSubFeature() Wend Set swSubFeat = swSubFeat.GetNextSubFeature() Wend Set swFeat = swFeat.GetNextFeature Wend End Sub Sub TraverseComponentFeatures(swComp As SldWorks.Component2, nLevel As Long) Dim swFeat As SldWorks.Feature Set swFeat = swComp.FirstFeature TraverseFeatureFeatures swFeat, nLevel End Sub Sub TraverseComponent(swComp As SldWorks.Component2, nLevel As Long) Dim vChildComp As Variant Dim swChildComp As SldWorks.Component2 Dim swCompConfig As SldWorks.Configuration Dim sPadStr As String Dim i As Long For i = 0 To nLevel - 1 sPadStr = sPadStr + " " Next i vChildComp = swComp.GetChildren For i = 0 To UBound(vChildComp) Set swChildComp = vChildComp(i) Debug.Print sPadStr & "+" & swChildComp.Name2 & " <" & swChildComp.ReferencedConfiguration & ">" TraverseComponentFeatures swChildComp, nLevel TraverseComponent swChildComp, nLevel + 1 Next i End Sub Sub TraverseModelFeatures(swModel As SldWorks.ModelDoc2, nLevel As Long) Dim swFeat As SldWorks.Feature Set swFeat = swModel.FirstFeature TraverseFeatureFeatures swFeat, nLevel End Sub Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swAssy As SldWorks.AssemblyDoc Dim swConf As SldWorks.Configuration Dim swRootComp As SldWorks.Component2 Dim nStart As Single Dim bRet As Boolean Set swApp = CreateObject("SldWorks.Application") Set swModel = swApp.ActiveDoc Set swConf = swModel.GetActiveConfiguration Set swRootComp = swConf.GetRootComponent nStart = Timer Debug.Print "File = " & swModel.GetPathName '一応すべての選択解除 swModel.ClearSelection2 True TraverseModelFeatures swModel, 1 TraverseComponent swRootComp, 1 Debug.Print "" Debug.Print "Time = " & Timer - nStart & " s" End Sub