Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

ProjectPoint returns null after manipulation of view.

timw3333
Contributor

ProjectPoint returns null after manipulation of view.

timw3333
Contributor
Contributor

I'm developing plugin which jumped to Point3D then select object at the point. However ProjectPoint returns Null after manipulation of view. How can I avoid this issue?

Dim oDoc As Document = Autodesk.Navisworks.Api.Application.ActiveDocument
Dim oCurrVCopy As Viewpoint = oDoc.CurrentViewpoint.CreateCopy
If oDoc.ActiveView.IsInteractive Then oDoc.ActiveView.EndInteractive()
[After modifying oCurrVCopy]
oDoc.CurrentViewpoint.CopyFrom(oCurrVCopy)

Dim oView As Autodesk.Navisworks.Api.View = oDoc.ActiveView
Dim pr As ProjectionResult = oView.ProjectPoint(oPoint, True, True)
If Not pr Is Nothing Then
   Dim iResult As PickItemResult = oView.PickItemFromPoint(pr.X, pr.Y, 2, False)
   If Not iResult.ModelItem Is Nothing Then
        Dim oItem As ModelItem = iResult.ModelItem
        oDoc.CurrentSelection.Clear()
        oDoc.CurrentSelection.Add(oItem)
   Else
        oDoc.CurrentSelection.Clear()
   End If
End If







0 Likes
Reply
493 Views
7 Replies
Replies (7)

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @timw3333 ,

 

As far as I understood you are getting ProjectionResult(pr) value as null. Am I right?

Could you please provide us a non-confidential Navisworks file and oPoint value to reproduce the issue at my end?


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes

timw3333
Contributor
Contributor

Dear Naveen
Thanks for your reply.
As I mentioned, ProjectionPoint returns null not by ProjectionResult.
It was strange that if I call the same function twice manually with the same Point3D, it works.
The Navisworks file I'm testing is more than 700MB. I cannot attach here.
Screen capture attached.



0 Likes

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @timw3333 ,

 

Sorry, I have no clue what is causing the issue at your end.

 

Looks like,  you cannot share the sample file(700 MB) with us.

 

If possible, Could you please create a simple small non-confidential file to reproduce the issue and share it with us?


Please understand it is extremely difficult for us to understand what is happening at your end without a sample file.

 

One suggestion I have, We have samples in this path(C:\Program Files\Autodesk\Navisworks Manage 2023\Samples).

 

Please test your plugin in these Navisworks Sample files and let me know whether you are able to reproduce the issue in any of these sample files.

 

If you are able to reproduce the issue in any of these sample files, then please send me the below details
1)Navisworks Version details
2)Sample File Name
3)Point3D value used in ProjectPoint()

I am waiting for your response.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes

timw3333
Contributor
Contributor

Dear Naveen
I could reproduce with sample file in the product. (gatehouse_pub.nwd)
Select WALL_549 under FASCIA_BOARD_G20 then run the code here. It returns null for the first time.

timw3333_0-1668412767092.png

 

    Private Sub CmdTest_Click(sender As Object, e As EventArgs) Handles CmdTest.Click
        Dim oDoc As Document = Autodesk.Navisworks.Api.Application.ActiveDocument
        Dim oModelItem As ModelItem = oDoc.CurrentSelection.SelectedItems.First
        Dim oPoint = oModelItem.BoundingBox.Center
        Dim oCurrVCopy As Viewpoint = oDoc.CurrentViewpoint.CreateCopy
        Dim oViewDir As Vector3D = getViewDir(oCurrVCopy)
        Dim length As Double = 1000

        If oDoc.ActiveView.IsInteractive Then oDoc.ActiveView.EndInteractive()

        oCurrVCopy.Position = New Point3D(oPoint.X - oViewDir.X * length * 2, oPoint.Y - oViewDir.Y * length * 2, oPoint.Z - oViewDir.Z * length * 2)
        oCurrVCopy.PointAt(oPoint)
        oCurrVCopy.FocalDistance = length * 2

        oDoc.CurrentViewpoint.CopyFrom(oCurrVCopy)

        Dim oView As Autodesk.Navisworks.Api.View = oDoc.ActiveView
        Dim pr As ProjectionResult = oView.ProjectPoint(oPoint, True, True)
        Dim iResult As PickItemResult
        If Not pr Is Nothing Then
            iResult = oView.PickItemFromPoint(pr.X, pr.Y, 2, False)
            If Not iResult.ModelItem Is Nothing Then
                Dim oItem As ModelItem = iResult.ModelItem
                oDoc.CurrentSelection.Clear()
                oDoc.CurrentSelection.Add(oItem)
            Else
                oDoc.CurrentSelection.Clear()
            End If
        Else
            MsgBox("ProjectPoint returns Null")
        End If

        oDoc.ActiveView.StartInteractive()
    End Sub
   Public Function getViewDir(oVP As Viewpoint) As Vector3D
        Dim oRot As Rotation3D = oVP.Rotation
        Dim oNegtiveZ As Rotation3D = New Rotation3D(0, 0, -1, 0)

        Dim otempRot As Rotation3D = MultiplyRotation3D(oNegtiveZ, oRot.Invert())
        Dim oViewDirRot As Rotation3D = MultiplyRotation3D(oRot, otempRot)

        Dim oViewDir As Vector3D = New Vector3D(oViewDirRot.A, oViewDirRot.B, oViewDirRot.C)

        oViewDir.Normalize()

        Return New Vector3D(oViewDir.X, oViewDir.Y, oViewDir.Z)

    End Function


Navisworks Simulate 2020.

0 Likes

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @timw3333 ,

 

I have raised your issue to the Engineering team and asked for their suggestion.

I will come back to you as soon as I receive a response from them.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @timw3333 ,

 

Sorry, I haven't received any response from the Engineering team yet.

I tested the sample code at my end.

First of all, I am not getting ProjectPoint or ProjectionResult values as null.

If possible could you please share the sample code of MultiplyRotation3D?

I used this below code

private Rotation3D MultiplyRotation3D(Rotation3D r1, Rotation3D r2)
        {
           
            Rotation3D r3d = new Rotation3D
            (
                ((r2.D)*(r1.A))+((r2.A)*(r1.D))+((r2.B)*(r1.C))-((r2.C)*(r1.B)),
                ((r2.D)*(r1.B))+((r2.B)*(r1.D))+((r2.C)*(r1.A))-((r2.A)*(r1.C)),
                ((r2.D)*(r1.C))+((r2.C)*(r1.D))+((r2.A)*(r1.B))-((r2.B)*(r1.A)),
                ((r2.D)*(r1.D))-((r2.A)*(r1.A))+((r2.B)*(r1.B))-((r2.C)*(r1.C))
            ) ;
            return r3d;            
        }

 Am I doing anything wrong?


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes

timw3333
Contributor
Contributor
0 Likes