Find intersection point between line segment and workplane

Find intersection point between line segment and workplane

Anonymous
Not applicable
832 Views
3 Replies
Message 1 of 4

Find intersection point between line segment and workplane

Anonymous
Not applicable

Hi,

 

I have to create a hole (extrude) in a wall part in my assembly document where a stack will be installed.

 

To determine where, I verify if a line segment pass through the wall (XY Plane).

 

But I get an error with the command: IntersectWithLine

 

Here's my code:

 

Public Function IntersectionPoint(ByVal app As Inventor.Application,
                                      ByVal wp As Inventor.WorkPlane) As Inventor.Point

        Dim oTransGeom As Inventor.TransientGeometry = app.TransientGeometry
        Dim startPoint As Inventor.Point = oTransGeom.CreatePoint(Me.StartVertex.X, Me.StartVertex.Y,
                                                                                                        Me.StartVertex.Z)
        Dim endPoint As Inventor.Point = oTransGeom.CreatePoint(Me.EndVertex.X, Me.EndVertex.Y,
                                                                Me.EndVertex.Z)
        Try
            Dim pt1 As Inventor.Point = oTransGeom.CreatePoint(startPoint.X, startPoint.Y, startPoint.Z)
            Dim pt2 As Inventor.Point = oTransGeom.CreatePoint(endPoint.X, endPoint.Y, endPoint.Z)
            Dim vector As Inventor.Vector = pt1.VectorTo(pt2)

            Dim lineSeg As Inventor.LineSegment = oTransGeom.CreateLineSegment(pt1, pt2)
            Dim pt As Inventor.Point = wp.Plane.IntersectWithLine(lineSeg)  'THIS LINE GIVE ME AN ERROR

            Return pt
        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function

 

 

Thanks for help.

 

 

Pascal

0 Likes
833 Views
3 Replies
Replies (3)
Message 2 of 4

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

I created a standalone EXE and tested the code below. It works well. The attached screenshot shows it. I suspected the failure at your side occurs in specific scenario.

 

    Private Sub test()

 

        Dim oApp As Inventor.Application
        Try
            oApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        Catch ex As Exception
        End Try

        Dim oPartDoc As PartDocument = oApp.ActiveDocument
        Dim wp As Inventor.WorkPlane = oPartDoc.ComponentDefinition.WorkPlanes("XY Plane")

        IntersectionPoint(oApp, wp)


    End Sub

 

    Public Function IntersectionPoint(ByVal app As Inventor.Application, _
                                      ByVal wp As Inventor.WorkPlane) As Inventor.Point

        Dim oTransGeom As Inventor.TransientGeometry = app.TransientGeometry
        Dim startPoint As Inventor.Point = oTransGeom.CreatePoint(0, 0, 1)
        Dim endPoint As Inventor.Point = oTransGeom.CreatePoint(0, 0, -1)
        Try
            Dim pt1 As Inventor.Point = oTransGeom.CreatePoint(startPoint.X, startPoint.Y, startPoint.Z)
            Dim pt2 As Inventor.Point = oTransGeom.CreatePoint(endPoint.X, endPoint.Y, endPoint.Z)
            Dim vector As Inventor.Vector = pt1.VectorTo(pt2)

            Dim lineSeg As Inventor.LineSegment = oTransGeom.CreateLineSegment(pt1, pt2)
            Dim pt As Inventor.Point = wp.Plane.IntersectWithLine(lineSeg)  'THIS LINE GIVE ME AN ERROR

            Return pt
        Catch ex As Exception
            Throw New Exception(ex.Message, ex)
        End Try
    End Function

 

 

Best regards,

 
autodesk_logo_signature.png

Xiaodong Liang

Developer Consultant

Autodesk Developer Technical Services

0 Likes
Message 3 of 4

Anonymous
Not applicable

Hi,

 

I do that in an AssemblyDocument.  So, my ActiveDocument is not a PartDocument but an AssemblyDocument.

 

Maybe that is the reason why I get an error?

 

Is it possible to do that in an Assembly document?

 

 

Thank you,

 

Pascal

0 Likes
Message 4 of 4

staff7NWEE
Explorer
Explorer

Is there another solution to this problem yet?

0 Likes