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
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?
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.
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.
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.
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.
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.
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?
Dear Naveen
MultiplyRotation3D is taken from Xiaodong's Blog.
https://adndevblog.typepad.com/aec/2012/06/navisworks-net-api-2013-new-feature-viewpoint-2.html
Can't find what you're looking for? Ask the community or share your knowledge.