AnsweredAssumed Answered

Can't select successful when I use "ModelDoc2.SelectByRay" in assembly environment

Question asked by Win Lai on Nov 16, 2018
Latest reply on Dec 12, 2018 by Win Lai

dear everybody,

I can use "ModelDoc2.SelectByRay" correctly in a Part document. But when I use the same code in Assemlby document ,it is unsuccessful.

Demo file have been uploaded.I am looking forward to someone who can tell me why.

thank you very much!


'Here is the code in vba====================================

Option Explicit

Sub main()


    Dim swApp As SldWorks.SldWorks

    Dim swModel As SldWorks.ModelDoc2

    Dim selParams(6) As Double

    Dim varSelParams As Variant

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc


    ' Selection ray definitions

    ' Origin X location

    selParams(0) = 0#

    ' Origin Y location

    selParams(1) = 0#

    ' Origin Z location

    selParams(2) = 1#

    ' Direction X component

    selParams(3) = 0#

    ' Direction Y component

    selParams(4) = 0#

    ' Direction Z component

    selParams(5) = 1#

    ' Intersection radius

    selParams(6) = 0.01


    'try "selParams(6)=0.01" in part1 =====>then successful

    'try "selParams(6)=0.009" in part1 =====>then unsuccessful(it is correctly, because the minimum distance from the part to the origin is"0.01")

    'try "selParams(6)=1" in part1 =====>then successful


    ‘The coordinate system of the part and assembly is completely coincident

    'try "selParams(6)=0.01" in Assem1 =====>then unsuccessful

    'try "selParams(6)=1" in Assem1 =====>then unsuccessful


    varSelParams = selParams

    Dim Status As Boolean

    Status = swModel.SelectByRay((varSelParams), swSelectType_e.swSelEDGES)

    Debug.Print ("Selection successful: " & Status)

End Sub

'Here is the code in vba====================================