2 Replies Latest reply on Jan 20, 2013 5:15 PM by Artem Taturevych

    How to understand the function of  GetRootComponent?

    Yong Ning

      How to understand the difference between GetRootcomponent and GetFirstSubFeature?

      ********************************************************************************************************

       

       

       

      GetRootComponent→ http://help.solidworks.com/2012/English/api/sldworksapi/Traverse_Assembly_at_Component_and_Feature_Level_Example_VB.htm

       

      a0.jpg

       

      Traversing Assembly at Component and Feature Levels?

       

       

      File = D:\Backup\我的文档\Draw\Assem1.SLDASM
          注解 [DetailCabinet]
          Comments [CommentsFolder]
          设计活页夹 [DocsFolder]
          光源与相机 [EnvFolder]
            环境光源 [AmbientLight]
            线光源1 [DirectionLight]
          前视 [RefPlane]
          上视 [RefPlane]
          右视 [RefPlane]
          原点 [OriginProfileFeature]
          Part1-1 [Reference]
          Part2-1 [Reference]
          配合 [MateGroup]
            距离1 [MateDistanceDim]
        +Part2-1 <默认>
          注解 [DetailCabinet]
          备注 [CommentsFolder]
          设计活页夹 [DocsFolder]
          曲面实体 [SurfaceBodyFolder]
          实体 [SolidBodyFolder]
          材质 <未指定> [MaterialFolder]
          光源与相机 [EnvFolder]
            环境光源 [AmbientLight]
            线光源 1 [DirectionLight]
            线光源 2 [DirectionLight]
          前视基准面 [RefPlane]
          上视基准面 [RefPlane]
          右视基准面 [RefPlane]
          原点 [OriginProfileFeature]
          Sketch1 [ProfileFeature]
          Extrude1 [Extrusion]
            Sketch1 [ProfileFeature]
        +Part1-1 <Default>
          注解 [DetailCabinet]
            细节1 [DetailFolder]
          Comments [CommentsFolder]
          设计活页夹 [DocsFolder]
          Material <not specified> [MaterialFolder]
          光源与相机 [EnvFolder]
            环境光源 [AmbientLight]
            线光源1 [DirectionLight]
          方程序 [EqnFolder]
          Surface Bodies [SurfaceBodyFolder]
          Solid Bodies [SolidBodyFolder]
          前视 [RefPlane]
          上视 [RefPlane]
          右视 [RefPlane]
          原点 [OriginProfileFeature]
          Sketch1 [ProfileFeature]
          Extrude1 [Extrusion]
            Sketch1 [ProfileFeature]
          Sketch2 [ProfileFeature]
          包覆1 [Emboss]
            Sketch2 [ProfileFeature]

        • Re: How to understand the function of  GetRootComponent?
          Yong Ning

          http://help.solidworks.com/2012/English/api/sldworksapi/traverse_subfeatures_example_vb.htm

           

          If use the GetFirstSubFeature function

          Result

          ****

          Sub ls1()

            Dim swApp As SldWorks.SldWorks, swPart As SldWorks.ModelDoc2

            Dim swFeat As SldWorks.Feature

            Set swApp = Application.SldWorks

            Set swPart = swApp.ActiveDoc

            With swPart

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

              ' Get the first feature in part

              Set Feature = .FirstFeature

            End With

            ' While we have a valid feature

            While Not Feature Is Nothing

              ' Get the name of the feature

              FeatureName = Feature.Name

              Message = "Feature: " & FeatureName & Chr(10) & " SubFeatures:"

              Set SubFeat = Feature.GetFirstSubFeature

              ' While we have a valid sub-feature

              While Not SubFeat Is Nothing

                ' Get the name of the sub-feature

                SubFeatureName = SubFeat.Name

                Message = Message & Chr(10) & " " & SubFeatureName

                'message = message & Chr(10) & " " & subFeatureName

                Set SubFeat = SubFeat.GetNextSubFeature

                ' Continue until the last sub-feature is done

              Wend

              ' Display the sub-features

              'swApp.SendMsgToUser message

              Debug.Print Message

              ' Get the next feature

              Set Feature = Feature.GetNextFeature()

              ' Continue until the last feature is done

            Wend

            ''

          End Sub

          ********************

          Feature: 注解
          SubFeatures:
          Feature: Comments
          SubFeatures:
          Feature: 设计活页夹
          SubFeatures:
          Feature: 光源与相机
          SubFeatures:
          环境光源
          线光源1
          Feature: 前视
          SubFeatures:
          Feature: 上视
          SubFeatures:
          Feature: 右视
          SubFeatures:
          Feature: 原点
          SubFeatures:
          Feature: Part1-1
          SubFeatures:
          Feature: Part2-1
          SubFeatures:
          Feature: 配合
          SubFeatures:
          距离1