Having difficulty with FindUsingRay method

Having difficulty with FindUsingRay method

dylanTEV9W
Advocate Advocate
493 Views
1 Reply
Message 1 of 2

Having difficulty with FindUsingRay method

dylanTEV9W
Advocate
Advocate

Hi all I wrote a program that is supposed to return the intersection of a ray and a surface but I'm not having much luck with it so far. It should print out a 1 for the found_entities ObjectEnumerator if the ray going through a surface but I've only gotten zeros back from it. Even when I surrounded the origin with a sphere. 

 

'defines base sketch, active application, active document and transient geometry before
'pulling anything from the active document

'Dim oSketch As PlanarSketch

'oSketch = _invApp.ActiveEditObject 'set the planar sketch as the active edit object

Dim part_doc As PartDocument ' get the active part document

part_doc = _invApp.ActiveDocument 'set part_doc as the active part document

Dim trans_geo As TransientGeometry 'get transient geometry from the application

trans_geo = _invApp.TransientGeometry 'set trans_geo as Transient Geometry object

'get the part component

Dim oDef As PartComponentDefinition

oDef = part_doc.ComponentDefinition

'define a neutral object to hold whats been picked

Dim oObject As Object


'select the surface to project to

oObject = _invApp.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a surface")

 

Dim oSurface As Face 'define a face.

oSurface = oObject ' set oSurface as the selected surface.

Dim vect As UnitVector 'define a vector

vect = trans_geo.CreateUnitVector(1, 1, 1)

Dim point1 As Point

point1 = trans_geo.CreatePoint(0, 0, 0)

Dim dist As Double = 0

'Entities for sending Find using ray outputs

Dim found_entities As ObjectsEnumerator = _invApp.TransientObjects.CreateObjectCollection()

Dim locate As ObjectsEnumerator = _invApp.TransientObjects.CreateObjectCollection()

'Dim point2 As Point

oDef.FindUsingRay(point1, vect, 0.0001, found_entities, locate, True)

 

Debug.Print(found_entities.Count)

0 Likes
494 Views
1 Reply
Reply (1)
Message 2 of 2

dylanTEV9W
Advocate
Advocate

In looking for a solution I found a great lab on Mod the machine from 2012. Lab 5 in the series features the FindUsingRay command, which I was able to get working I commented out most of the rest of the changes and had it print out the location on the intersection with the object and the ray. 

 

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
' Get PartComponentDefinition
Dim oCompDef As PartComponentDefinition
oCompDef = _invApp.ActiveDocument.ComponentDefinition

' Get the SurfaceBody
Dim oBody As SurfaceBody
oBody = oCompDef.SurfaceBodies.Item(1)

' Get the TransientGeometry
Dim oTG As TransientGeometry
oTG = _invApp.TransientGeometry

' 1. Declare to ObjectsEnumerator objects. One will be for Found Entities
' the other will be for located points
Dim oFoundEnts As ObjectsEnumerator = Nothing
Dim oLocPoints As ObjectsEnumerator = Nothing

' 2. Use FindUsingRay method fo the SurfaceBody instantiated above
' (oBody). for the first parameter use the TransientGeometry object
' CreatePoint use (0,0,0). For the second parameter use TransientGeometry
' CreateUnitVecor with a value of (0,0,-1). Ise 0.00001 for the radius
' then passin the Found entities varaible and located points variable
' declared above. Use True for the last parameter FindFirstOnly
Call oBody.FindUsingRay(oTG.CreatePoint(0, 0, 0),
oTG.CreateUnitVector(0, 0, -1), 0.00001,
oFoundEnts, oLocPoints, True)

' 3. Use and if statement to see if the Found entities varaible
' count property equals one. If it does not display a MsgBox that
' "No face is along the specified ray.
If oFoundEnts.Count = 1 Then
' 2. If Found entities does equal one declare a Face object
' and instantiate it using the first Item in the Found entities
' variable. Use a MsgBox and display the area of the face.
'Dim oFace As Face

Debug.Print(oLocPoints.Count)

Debug.Print(oFoundEnts.Count)

Dim point1 As Point

point1 = oLocPoints.Item(1)

Debug.Print("Location of intersection Point")

Debug.Print(point1.X)

Debug.Print(point1.Y)

Debug.Print(point1.Z)

'oFace = oFoundEnts.Item(1)

'MsgBox("Found face with area " & oFace.Evaluator.Area & " cm^2")

'' 3. Declare an Edge varaible and instantitate it using
'' the Edges collection of the face. (Item)
'Dim oEdge As Edge
'oEdge = oFace.Edges.Item(1)

'' 4. Declare an FilletFeatures variable and instantiate it with
'' the FilletFeatures property of the Features collection of the
'' PartComponentDefinition
'Dim oFilFeatures As FilletFeatures
'oFilFeatures = oCompDef.Features.FilletFeatures


'' 5. Declare a EdgesCollection and instantiate it using
'' CreateEdgeCollection of the TransientObjects of the application
'' use the Add method and add the edge from step 4.
'Dim oFilletEdges As EdgeCollection
'oFilletEdges = _invApp.TransientObjects.CreateEdgeCollection
'oFilletEdges.Add(oEdge)

'' 6. Create the fillet with the AddSimple method of the
'' FilletFeatures collection. Pass in the EdgeCollection from step 5
'' Use a radius of .5 for the second parameter
'Dim oFillet As FilletFeature
'oFillet = oFilFeatures.AddSimple(oFilletEdges, 0.5)

Else
MsgBox("Please Align the points such that they overlap the part.")
End If

End Sub

0 Likes