×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

select by ray API

select by ray API

select by ray API

(OP)
Hi all
has anybody tried to select entities using ModelDoc2:RayIntersections or ModelDoc2:multiselectbyray API's?
I am finding some problem with it and am not able to trace it. The code is given as below... Also does anyone know how to handle exceptions coming from solidworks or get info about these?
What I am trying to do is I get box on the main part body. then I fire a ray from center of one of the face towards the body and try to select all the faces in between. but it's not working.. if anybody has pointers please let me know.
thanks


   Set actDoc = solidModeler.ActiveDoc
    
    If actDoc.GetType <> swDocPART Then
        Call MsgBox("Only Allowed on Parts", vbOKOnly, "Error") ' Display error message
        Exit Function ' Exit this program
    End If
    ReDim boxParams(6)
    Set bodyObj = actDoc.Body
    If (bodyObj Is Nothing) Then
        solidModeler.SendMsgToUser "Error! Part has no body."
        Exit Function
    End If
    boxParams = bodyObj.GetBodyBox()
    If Not (IsEmpty(boxParams) Or IsNull(boxParams)) Then
        For i = 0 To UBound(boxParams)   ' For each string in the SafeArray
            boxParams(i) = boxParams(i) * 100
            Debug.Print boxParams(i)
        Next i
    End If
    ln = boxParams(3) - boxParams(0)
    wd = boxParams(4) - boxParams(1)
    ht = boxParams(5) - boxParams(2)
    zUpper = boxParams(5)
    yUpper = boxParams(4)
    xUpper = boxParams(3)
    zLower = boxParams(2)
    yLower = boxParams(1)
    xLower = boxParams(0)

    Dim rayOrigin(3) As Variant
    'Dim org(3) As Double
    Dim rayDir(3) As Variant

    rayOrigin(0) = xLower + ln / 2
    rayOrigin(1) = yLower + wd / 2
    rayOrigin(2) = zLower - 1
    rayDir(0) = 0
    rayDir(1) = 0
    rayDir(2) = 1
    
    Call RayFire(rayOrigin, rayDir)
    
    Set bodyObj = Nothing
    Set actDoc = Nothing
End Function

Sub RayFire(origin As Variant, dir As Variant)
    Dim hits As Integer
    Dim bIn(0) As Variant
    Dim params(7) As Variant
    Dim res As Boolean
    Dim i As Integer
            
    Set bIn(0) = actDoc.Body
    params(0) = origin(0)
    params(1) = origin(1)
    params(2) = origin(2)
    params(3) = dir(0)
    params(4) = dir(1)
    params(5) = dir(2)
    params(6) = 0.1
    
    For i = 0 To 7
        Debug.Print "param " & i & " : " & params(i)
    Next i
    
    res = actDoc.MultiSelectByRay(params, swSelFACES, False)
    Debug.Print res
    res = actDoc.SelectByRay(params, swSelFACES)
    Debug.Print res

/////////////the below code throws some unknown error to me...
    
    'On Error Resume Next
     '   MsgBox ("Error # " & CStr(Err.Number) & " " & Err.Description)
        
    'hits = actDoc.RayIntersections(bIn, origin, dir, 2, 0.01, 0.01)
           
    'Debug.Print "hits " & hits
    
End Sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources