2627235904 发表于 2013-12-16 14:22:09

getchildren方法问题讨论

SolidWorks二次开发中 getchildren方法获取零件名字顺序与模型树中的顺序不一致,并且API帮助中getchildren方法最后提示NOTE: Components might not be returned in the same order from call to call.

获取的顺序与模型树顺序不一致,这类问题怎么解决?????????????????


Option Explicit
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

    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc
   Set swConf = swModel.GetActiveConfiguration
    Set swRootComp = swConf.GetRootComponent3(True)
    TraverseComponent swRootComp

End Sub


Sub TraverseComponent(swComp As SldWorks.Component2)
    Dim vChildComp                  As Variant
   Dim swchildcomp               As SldWorks.Component2
      Dim i                           As Long


    vChildComp = swComp.GetChildren

    For i = 0 To UBound(vChildComp)
      Set swchildcomp = vChildComp(i)

    Debug.Print swchildcomp.Name2
    Next i
'
End Sub


jimmide 发表于 2019-5-3 11:29:37

高手在民间小调
页: [1]
查看完整版本: getchildren方法问题讨论