I would like to find the location of all the Parts available in an Assembly on my monitor screen. After doing my research/asking for guidance, I was able to get someone told me these functions could help me do it. I tried to search for example of how to use NXOpen.View
because I need to pass aView as View
to input parameter of the function but I could not really find an example.
How can I declare my current monitor view of the assembly as View in order to pass it these Function inputs?
Function MapView2Abs(ByVal aView As View, ByVal loc As Point3d)
Dim vmx As Matrix3x3 = aView.Matrix
Dim vw() As Double = {0, 0, 0, vmx.Xx, vmx.Xy, vmx.Xz, vmx.Yx, vmx.Yy, vmx.Yz}
Dim abs() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
Dim mx(11) As Double
Dim irc As Integer
Dim c() As Double = {loc.X, loc.Y, loc.Z}
ufs.Trns.CreateCsysMappingMatrix(vw, abs, mx, irc)
ufs.Trns.MapPosition(c, mx)
MapView2Abs = New Point3d(c(0), c(1), c(2))
End Function
Function Reverse(ByVal forward As Point3d)
Reverse = New Point3d(-forward.X, -forward.Y, -forward.Z)
End Function
Function MapAbs2View(ByVal aView As View, ByVal loc As Point3d)
Dim vmx As Matrix3x3 = aView.Matrix
Dim origin_abs As Point3d = MapView2Abs(aView, Reverse(aView.Origin))
Dim vw() As Double = {origin_abs.X, origin_abs.Y, origin_abs.Z, _
vmx.Xx, vmx.Xy, vmx.Xz, vmx.Yx, vmx.Yy, vmx.Yz}
Dim abs() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
Dim mx(11) As Double
Dim irc As Integer
Dim c() As Double = {loc.X, loc.Y, loc.Z}
ufs.Trns.CreateCsysMappingMatrix(abs, vw, mx, irc)
ufs.Trns.MapPosition(c, mx)
MapAbs2View = New Point3d(c(0), c(1), c(2))
End Function
re: work view
My answer below assumes that we are talking about the current view in the modeling application (not a drafting view).
You can get the current view through the part's .Views collection:
{part variable}.Views.WorkView
Here is an example of passing it in to the "MapAbs2View" function:
Dim myPt as New Point3d(0,0,0)
MapAbs2View(theSession.Parts.Work.Views.WorkView, myPt)