Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find the location of a Part (Child) on my monitor when an assembly is opened VB.NET 1

Status
Not open for further replies.

ulink2rle

Electrical
Feb 17, 2017
1
I have tried to search for sample code or something that can guide me to the solution but I have not be able to. If you can please help me. What is would like to do is very similar to the problem of getting the location of the cursor on the monitor screen but instead it is the location of a part (in an assembly and I am viewing the assembly on monitor). Ideally, I would like to have a list of locations for all the parts but if someone can guide me to find location of just 1 part, I will very appreciate.

Edited 1: I have some functions that may be able to help me. However, how can I assign the value to "aView"? I guess it must be an active view of my work space

Code:
  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

 
Replies continue below

Recommended for you

Hi User,

Your approach of finding parts inside assembly based on loaction may not be fool proof.
What if
1. The application you try to build ran in a different screen resolution​
2. Your logic might fail when the zoom level of your assembly differs with your actual saved view orientation​

I would approach this by getting the part (in need) object using NXOpen / UFunc API's to select.

Thanks,
P M
 
Before you write a bunch of code, I suggest looking at turning on object names (preferences -> visualization -> names/borders -> show object names = work view). Turning this option on will show the component names on screen, making particular components easier to find.

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor