Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NXOpen > how to calculate a new coordinate based on a Delta distance

Status
Not open for further replies.

lklo

Industrial
Nov 24, 2010
226
Hi -

Current situation.
Dim axisPt(2) As Double = xxxxxxx
I do have calculated a intersection Point between a hole-axis and a planar-face,
from where I have to fire a Ray (ufs.Modl.TraceARay(theBodytags.Count, theBodytags.ToArray, axisPt, unitNormal, identity, 0, numHits, hits)

But instead of Firing from the center point itself, I would like to offset the Point a certain Delta distance....
The offset shall be parallel to the planar face - but no requirements to the index angle from centerpoint....
(It means the new point can be at "point on a the Delta Radius distance" from center point of the hole....)

In shortness:
axisPt(2) shall contain a random Point on a Delta Radius centered in current intersection point...

Can someone maybe advice a bit....

please see attached pic..

br lklo

 
 https://files.engineering.com/getfile.aspx?folder=7df199be-4aaf-4f3a-a06f-1032be453a83&file=TraceARay.png
Replies continue below

Recommended for you

UPDATE:
a VB code is now attached , and also a NX .prt file as well....

Basically I'm stucked in Line no.157 in this journal....
I do have the Intersection point of the holeaxis and the planarface...
Also the FaceNormal is present..
I will be very happy for some help, if someone can guy me in a direction of, how to calculate a Point a delta distance
from current intersection-point... In this journal we are dealing with the variable: myDelta=12
The Calculated Point can have any index-angle....Just be on the Planar Face and have "myDelta" distance from the intersection-point....

thanks....
lklo

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
'Imports NXOpen.Drawings
'Imports NXOpen.Assemblies
'Imports NXOpen.PDM
'Imports System.Collections
Imports System.Collections.Generic
'Imports NXOpen.Annotations
'Imports System.Text
'Imports NXOpen.Utilities
'Imports System.Text.RegularExpressions
'Imports System.Diagnostics
'Imports NXOpen.Routing
'Imports NXOpen.Features



Module Lkl_rename_My_MODULE

    Dim theSession As Session = Session.GetSession()
    Dim theUI As UI = UI.GetUI()
    Dim workPart As Part = theSession.Parts.Work
    Dim displayPart As Part = theSession.Parts.Display
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim output_To_NXListingWindow As Boolean = True
    Dim output_To_NXLogFile As Boolean = True

    Sub Main()
        ufs.Ui.ExitListingWindow() ' close windows before displaying it again
        workPart.ModelingViews.WorkView.Regenerate()
        'START HERE

        Dim thePlanarFace As Face = Nothing
        'select Planar Face...
        While select_a_Planarface("The Planar Face", thePlanarFace) = Selection.Response.Ok
            'Select cylindrical Face...
            Dim theCylindricalFace As Face = select_a_CylindricalFace("The cylindrical hole Face")
            'Some output to NX Lising Window...TAG
            NX(" ")
            NX("PlanarFace tag: " & thePlanarFace.Tag)
            NX("CylindricalFace tag: " & theCylindricalFace.Tag)
            ' Calculat Point3D...
            Dim tempPoint1 As NXOpen.Point3d = CalcIntersectionPoint(thePlanarFace, theCylindricalFace)
            ' Set point as double...
            Dim axisPt(2) As Double '> the Intersection point between the Hole-axis and the Planar Face...
            axisPt(0) = tempPoint1.X
        axisPt(1) = tempPoint1.Y
            axisPt(2) = tempPoint1.Z
            'Some output to NX Lising Window...COORDINATE
            NX("Intersection Point > point/hole")
            NX("AbsXPos: " & Math.Round(axisPt(0), 3).ToString("0.000"))
            NX("AbsYPos: " & Math.Round(axisPt(1), 3).ToString("0.000"))
            NX("AbsZPos: " & Math.Round(axisPt(2), 3).ToString("0.000"))
            NX(" ")

            ' display temp point at intersection...
            Dim poicolour As New NXOpen.UF.UFObj.DispProps()
            poicolour.color = 36
            ufs.Disp.DisplayTemporaryPoint(NXOpen.Tag.Null, UFDisp.ViewType.UseWorkView, axisPt, poicolour, UFDisp.PolyMarker.Asterisk)

            ' Lets play with face props
            Dim param(1) As Double
            Dim newOrigin(2) As Double
            Dim unitNormal(2) As Double
            Dim u1(2) As Double
            Dim u2(2) As Double
            Dim v1(2) As Double
            Dim v2(2) As Double
            Dim radii(1) As Double

            ' ask Face Properties...we need the normal vector of the Planar Face...
            ufs.Modl.AskFaceProps(thePlanarFace.Tag, param, newOrigin, u1,
                              v1, u2, v2, unitNormal, radii)
            'Some output to NX Lising Window...DIRECTION of the Planar Face...
            NX("PlanarFaceDirection X: " & unitNormal(0).ToString("0.000"))
            NX("PlanarFaceDirection Y: " & unitNormal(1).ToString("0.000"))
            NX("PlanarFaceDirection Z: " & unitNormal(2).ToString("0.000"))
            'Some output to NX Lising Window...U & V of the Planar Face...
            NX("PlanarFace-u1(0) : " & u1(0))
            NX("PlanarFace-u1(1) : " & u1(1))
            NX("PlanarFace-u1(2) : " & u1(2))
            NX("PlanarFace-v1(0) : " & v1(0))
            NX("PlanarFace-v1(1) : " & v1(1))
            NX("PlanarFace-v1(2) : " & v1(2))
            NX("PlanarFace-u2(0) : " & u2(0))
            NX("PlanarFace-u2(1) : " & u2(1))
            NX("PlanarFace-u2(2) : " & u2(2))
            NX("PlanarFace-v2(0) : " & v2(0))
            NX("PlanarFace-v2(1) : " & v2(1))
            NX("PlanarFace-v2(2) : " & v2(2))
            NX(" ")
            ' ask Face Properties...we need the normal vector of the Planar Face...
            ufs.Modl.AskFaceProps(theCylindricalFace.Tag, param, newOrigin, u1,
                              v1, u2, v2, unitNormal, radii)
            'Some output to NX Lising Window...DIRECTION of the Planar Face...
            NX("CylindricalFaceDirection X: " & unitNormal(0).ToString("0.000"))
            NX("CylindricalFaceDirection Y: " & unitNormal(1).ToString("0.000"))
            NX("CylindricalFaceDirection Z: " & unitNormal(2).ToString("0.000"))
            'Some output to NX Lising Window...U & V of the Cylindrical Face...
            NX("CylindricalFace-u1(0) : " & u1(0))
            NX("CylindricalFace-u1(1) : " & u1(1))
            NX("CylindricalFace-u1(2) : " & u1(2))
            NX("CylindricalFace-v1(0) : " & v1(0))
            NX("CylindricalFace-v1(1) : " & v1(1))
            NX("CylindricalFace-v1(2) : " & v1(2))
            NX("CylindricalFace-u2(0) : " & u2(0))
            NX("CylindricalFace-u2(1) : " & u2(1))
            NX("CylindricalFace-u2(2) : " & u2(2))
            NX("CylindricalFace-v2(0) : " & v2(0))
            NX("CylindricalFace-v2(1) : " & v2(1))
            NX("CylindricalFace-v2(2) : " & v2(2))

            'Some output to NX Lising Window...MATRIX 3X3 based on the Planar Face

            ' ask Face Properties...we need the normal vector of the Planar Face...
            ufs.Modl.AskFaceProps(thePlanarFace.Tag, param, newOrigin, u1,
                              v1, u2, v2, unitNormal, radii)

            Dim thePlanarFaceOrientation As Matrix3x3 = CalcMatrix(thePlanarFace)
            NX(" ")
            NX("Mátrix 3x3 - Planar Face ")
            NX(thePlanarFaceOrientation.Xx)
            NX(thePlanarFaceOrientation.Xy)
            NX(thePlanarFaceOrientation.Xz)
            NX(thePlanarFaceOrientation.Yx)
            NX(thePlanarFaceOrientation.Yy)
            NX(thePlanarFaceOrientation.Yz)
            NX(thePlanarFaceOrientation.Zx)
            NX(thePlanarFaceOrientation.Zy)
            NX(thePlanarFaceOrientation.Zz)


            'Some output to NX Lising Window...MATRIX 3X3 based on the cylindrical Face
            ' ask Face Properties...we need the normal vector of the Planar Face...
            ufs.Modl.AskFaceProps(theCylindricalFace.Tag, param, newOrigin, u1,
                              v1, u2, v2, unitNormal, radii)
            Dim theCylindricalFaceOrientation As Matrix3x3 = CalcMatrix(theCylindricalFace)
            NX(" ")
            NX("Mátrix 3x3 - Cylindrical Face ")
            NX(theCylindricalFaceOrientation.Xx)
            NX(theCylindricalFaceOrientation.Xy)
            NX(theCylindricalFaceOrientation.Xz)
            NX(theCylindricalFaceOrientation.Yx)
            NX(theCylindricalFaceOrientation.Yy)
            NX(theCylindricalFaceOrientation.Yz)
            NX(theCylindricalFaceOrientation.Zx)
            NX(theCylindricalFaceOrientation.Zy)
            NX(theCylindricalFaceOrientation.Zz)


'#########################################################################################################################
            
            Dim myDelta As Double = 12 ' the offset distance that the Point shall be calculated from...
' Inside here a function call is needed..'current axisPt shall have the value of myDelta added to the ABS coordinate, based on the normaldirection from either planars face ot hole axis






'#########################################################################################################################

            ' display temp point at Delta distance...
            poicolour.color = 42
            ufs.Disp.DisplayTemporaryPoint(NXOpen.Tag.Null, UFDisp.ViewType.UseWorkView, axisPt, poicolour, UFDisp.PolyMarker.Asterisk)

            NX(" ")
            NX("--------------------------------------------")
            NX("--------------------------------------------")
        End While

    End Sub



    '=========================== NX LISTING WINDOW FUNCTION=======================================

    Public Sub NX(ByVal input As String) '' output variable listwindow - just for building VB

        If output_To_NXListingWindow Then
            Dim displayPart As Part = theSession.Parts.Display
            Dim lw As ListingWindow = theSession.ListingWindow()
            lw.Open()
            lw.WriteLine(input)
        End If

    End Sub
    '===============================================================================================

    '=========================== NX WRITE TO LOGFILE FUNCTION=======================================

    Public Sub NX_log(ByVal input As String) '' output variable listwindow - just for building VB

        If output_To_NXLogFile Then
            theSession.LogFile.WriteLine(input)
        End If

    End Sub
    '================================================================================================

    '=========================== NX UNLOAD FUNCTION ================================================

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination ' typically used in Checkmate only

    End Function
    '================================================================================================

    '================================================================================================
    '================================================================================================

    Function select_a_Planarface(ByVal prompt As String, ByRef obj As Face)
        Dim ui As UI = GetUI()
        Dim mask(0) As Selection.MaskTriple
        With mask(0)
            .Type = UFConstants.UF_solid_type
            .Subtype = UFConstants.UF_solid_face_subtype
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_PLANAR_FACE
        End With
        Dim cursor As Point3d = Nothing

        Dim resp As Selection.Response =
        ui.SelectionManager.SelectObject(prompt, prompt,
            Selection.SelectionScope.AnyInAssembly,
            Selection.SelectionAction.ClearAndEnableSpecific,
            False, False, mask, obj, cursor)

        If resp = Selection.Response.ObjectSelected Or
           resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

    '================================================================================================
    '================================================================================================

    Function select_a_CylindricalFace(ByRef prompt As String) As Face

        Dim mask(0) As Selection.MaskTriple
        With mask(0)
            .Type = UFConstants.UF_solid_type
            .Subtype = 0
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_CYLINDRICAL_FACE
        End With
        Dim cursor As Point3d = Nothing
        select_a_CylindricalFace = Nothing

        ufs.Ui.LockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)

        UI.GetUI.SelectionManager.SelectTaggedObject(prompt, "Select a Cylindrical Hole Face:",
            Selection.SelectionScope.AnyInAssembly,
            Selection.SelectionAction.ClearAndEnableSpecific, False,
            False, mask, select_a_CylindricalFace, cursor)

        ufs.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)

    End Function

    '================================================================================================
    '================================================================================================
    Public Function CalcIntersectionPoint(ByVal whichPlanarFace As Face, ByVal whichCylindricalFace As Face) As Point3d

        Dim newPoint As Point3d = Nothing

        newPoint.X = 0
        newPoint.Y = 0
        newPoint.Z = 0

        Try

            ' Variables for ufs.Curve.Intersect..
            Dim mystartpoint(2) As Double
            Dim intersectdata1 As NXOpen.UF.UFCurve.IntersectInfo = Nothing

            ' create temporary line
            Dim line1 As NXOpen.Line = Nothing
            line1 = workPart.Lines.CreateFaceAxis(whichCylindricalFace, NXOpen.SmartObject.UpdateOption.WithinModeling)

            ' get the intersection point
            ufs.Curve.Intersect(line1.Tag, whichPlanarFace.Tag, mystartpoint, intersectdata1)

            If Not intersectdata1.type_of_intersection = 1 Then
                ' list the intersection type
                NX(intersectdata1.type_of_intersection)
                MsgBox("no face/line-axis intersect found")
                Return newPoint ' just in case no intersection was calculated...
            End If

            ' delete the line straight after...
            Dim objectstoDelete(0) As NXOpen.NXObject
            objectstoDelete(0) = line1
            Dim nErrs3 As Integer = Nothing
            nErrs3 = theSession.UpdateManager.AddObjectsToDeleteList(objectstoDelete)

            ' Transfer the calculated Point Data into Point3d...
            newPoint.X = intersectdata1.curve_point(0)
            newPoint.Y = intersectdata1.curve_point(1)
            newPoint.Z = intersectdata1.curve_point(2)

            Return newPoint

        Catch

            MsgBox("no face/line-axis intersect found")
            Return newPoint ' just in case no intersection was calculated...

        End Try

    End Function

    '================================================================================================
    '================================================================================================

    Public Function CalcMatrix(ByVal whichPlanarFace As Face) As Matrix3x3

        ' Matrix to be returned -
        Dim newMtx3x3 As Matrix3x3

        newMtx3x3.Xx = 1.0
        newMtx3x3.Xy = 0.0
        newMtx3x3.Xz = 0.0
        newMtx3x3.Yx = 0.0
        newMtx3x3.Yy = 1.0
        newMtx3x3.Yz = 0.0
        newMtx3x3.Zx = 0.0
        newMtx3x3.Zy = 0.0
        newMtx3x3.Zz = 1.0

        Try

            'Dim uvMinMax(3) As Double
            'ufs.Modl.AskFaceUvMinmax(BoltHeadFace(0).Tag, uvMinMax)
            Dim param(1) As Double
            'param(0) = ((uvMinMax(0) + uvMinMax(1)) / 2)
            'param(1) = ((uvMinMax(2) + uvMinMax(3)) / 2)
            Dim newOrigin(2) As Double
            Dim unitNormal(2) As Double
            Dim u1(2) As Double
            Dim u2(2) As Double
            Dim v1(2) As Double
            Dim v2(2) As Double
            Dim radii(1) As Double

            ' ask Face Properties...we need the normal vector...
            ufs.Modl.AskFaceProps(whichPlanarFace.Tag, param, newOrigin, u1,
                              v1, u2, v2, unitNormal, radii)

            Dim newMtx(8) As Double

            ' convert vector 2 Matrix...nice one....
            ufs.Mtx3.InitializeZ(unitNormal, newMtx)
            'build the Matrix 3x3...based on Bolt/Nut Face-vector... 
            newMtx3x3.Xx = newMtx(0)
            newMtx3x3.Xy = newMtx(1)
            newMtx3x3.Xz = newMtx(2)
            newMtx3x3.Yx = newMtx(3)
            newMtx3x3.Yy = newMtx(4)
            newMtx3x3.Yz = newMtx(5)
            newMtx3x3.Zx = newMtx(6)
            newMtx3x3.Zy = newMtx(7)
            newMtx3x3.Zz = newMtx(8)

            'Return the Matrix 
            Return newMtx3x3

        Catch
            MsgBox("cant calculate Matrix 3x3  - we returned the Absolute one instead...")
            Return newMtx3x3
        End Try

    End Function

End Module
 
 https://files.engineering.com/getfile.aspx?folder=7b6f2278-7d0e-48b6-b642-17906e97afeb&file=NX_Transformation_Matrix.prt
Since you know the normal vector of the planar face, you can use .AskPerpendicular to find an arbitrary vector that is parallel to the face. If it really doesn't matter which direction it points, you can use it directly.

www.nxjournaling.com
 
Thanks a lot, Cowski...
That advice helped me a lot...
By using the perpendicular vector of the Planar Face > and then some Math manipulation of the Vector & Delta distance, did the trick...
I got some help for these Vector calculations, on another NX forum.....

Try have a look in below code...
Line 108 to Line124
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
'Imports NXOpen.Drawings
'Imports NXOpen.Assemblies
'Imports NXOpen.PDM
'Imports System.Collections
Imports System.Collections.Generic
'Imports NXOpen.Annotations
'Imports System.Text
'Imports NXOpen.Utilities
'Imports System.Text.RegularExpressions
'Imports System.Diagnostics
'Imports NXOpen.Routing
'Imports NXOpen.Features



Module Lkl_rename_My_MODULE
    ' 1. This piece of code is a "Proof_Of_Concept" on how to calculate a new Point coordinate, based on
    '       an existing intersection-point coordinate and a Delta value perpendicular to the Planar Face where the Hole is located...
    ' 2. Select a Planar Face > Select A Cylindrical Hole Face (on the selected planar face)...
    ' 3. A temporary Asterisk is displayed in the intersection-point...
    ' 4. A Point3D is created the Delta distance from the intersection-point...(vector perpendicular to the Planar Face...

    Dim theSession As Session = Session.GetSession()
    Dim theUI As UI = UI.GetUI()
    Dim workPart As Part = theSession.Parts.Work
    Dim displayPart As Part = theSession.Parts.Display
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim output_To_NXListingWindow As Boolean = True
    Dim output_To_NXLogFile As Boolean = True

    Sub Main()
        ufs.Ui.ExitListingWindow() ' close windows before displaying it again
        workPart.ModelingViews.WorkView.Regenerate()
        For Each tmpPoint As Point In workPart.Points
            workPart.Points.DeletePoint(tmpPoint)
        Next
        'START HERE

        Dim thePlanarFace As Face = Nothing
        'select Planar Face...
        While select_a_Planarface("The Planar Face", thePlanarFace) = Selection.Response.Ok
            'Select cylindrical Face...
            Dim theCylindricalFace As Face = select_a_CylindricalFace("The cylindrical hole Face")
            'Some output to NX Lising Window...TAG
            NX(" ")
            NX(" • Face Tag.")
            NX("    PlanarFace tag: " & thePlanarFace.Tag)
            NX("    CylindricalFace tag: " & theCylindricalFace.Tag)
            NX(" ")
            ' Calculat Point3D...
            Dim tempPoint1 As NXOpen.Point3d = CalcIntersectionPoint(thePlanarFace, theCylindricalFace)
            ' Set point as double...
            Dim axisPt(2) As Double '> the Intersection point between the Hole-axis and the Planar Face...
            axisPt(0) = tempPoint1.X
            axisPt(1) = tempPoint1.Y
            axisPt(2) = tempPoint1.Z
            'Some output to NX Lising Window...COORDINATE
            NX(" • Intersection Point Coordinate > point/hole.")
            NX("    AbsXPos: " & Math.Round(axisPt(0), 3).ToString("0.000"))
            NX("    AbsYPos: " & Math.Round(axisPt(1), 3).ToString("0.000"))
            NX("    AbsZPos: " & Math.Round(axisPt(2), 3).ToString("0.000"))
            NX(" ")

            ' display temp point at intersection...
            Dim poicolour As New NXOpen.UF.UFObj.DispProps()
            poicolour.color = 36
            ufs.Disp.DisplayTemporaryPoint(NXOpen.Tag.Null, UFDisp.ViewType.UseWorkView, axisPt, poicolour, UFDisp.PolyMarker.Asterisk)

            ' Lets play with face props
            Dim param(1) As Double
            Dim newOrigin(2) As Double
            Dim unitNormal(2) As Double
            Dim u1(2) As Double
            Dim u2(2) As Double
            Dim v1(2) As Double
            Dim v2(2) As Double
            Dim radii(1) As Double

            ' ask Face Properties...we need the normal vector of the Planar Face...
            ufs.Modl.AskFaceProps(thePlanarFace.Tag, param, newOrigin, u1,
                              v1, u2, v2, unitNormal, radii)
            'Some output to NX Lising Window...DIRECTION of the Planar Face...
            NX(" • Vector Planar Face.")
            NX("    PlanarFaceDirection X: " & unitNormal(0).ToString("0.000"))
            NX("    PlanarFaceDirection Y: " & unitNormal(1).ToString("0.000"))
            NX("    PlanarFaceDirection Z: " & unitNormal(2).ToString("0.000"))
            NX(" ")
            ' ask Face Properties...we need the normal vector of the Cylindrical Face...
            ufs.Modl.AskFaceProps(theCylindricalFace.Tag, param, newOrigin, u1,
                              v1, u2, v2, unitNormal, radii)
            'Some output to NX Lising Window...DIRECTION of the Cylindrical Face...
            NX(" • Vector CylindricalFace.")
            NX("    CylindricalFaceDirection X: " & unitNormal(0).ToString("0.000"))
            NX("    CylindricalFaceDirection Y: " & unitNormal(1).ToString("0.000"))
            NX("    CylindricalFaceDirection Z: " & unitNormal(2).ToString("0.000"))
            NX(" ")
            'Some output to NX Lising Window...Calculate the coordinates of a point...

            ' ask Face Properties...we need the normal vector of the Planar Face...
            ufs.Modl.AskFaceProps(thePlanarFace.Tag, param, newOrigin, u1,
                              v1, u2, v2, unitNormal, radii)

            Dim perpVector(2) As Double
            ufs.Vec3.AskPerpendicular(unitNormal, perpVector)
            'Some output to NX Lising Window...PERPENDICULAR VECTOR Planar Face
            NX(" • Vector Perpendicular Planar Face.")
            NX("    PerpendicularPlanarFaceDirection X: " & perpVector(0).ToString("0.000"))
            NX("    PerpendicularPlanarFaceDirection Y: " & perpVector(1).ToString("0.000"))
            NX("    PerpendicularPlanarFaceDirection Z: " & perpVector(2).ToString("0.000"))
            NX(" ")

            'Some output to NX Lising Window... VECTOR CALCULATION
            Dim myDelta As Double = 12 ' the offset distance that the Point shall be calculated from...
            Dim vLength As Double = Math.Sqrt(perpVector(0) ^ 2 + perpVector(1) ^ 2 + perpVector(2) ^ 2)
            Dim newPt(2) As Double

            newPt(0) = axisPt(0) + (myDelta / vLength) * perpVector(0)
            newPt(1) = axisPt(1) + (myDelta / vLength) * perpVector(1)
            newPt(2) = axisPt(2) + (myDelta / vLength) * perpVector(2)

            'Some output to NX Lising Window...RE-GENERATED COORDINATE...
            NX(" • Re-generated Point Coordinate incl the Delta distance.")
            NX("    AbsXPos: " & Math.Round(newPt(0), 3).ToString("0.000"))
            NX("    AbsYPos: " & Math.Round(newPt(1), 3).ToString("0.000"))
            NX("    AbsZPos: " & Math.Round(newPt(2), 3).ToString("0.000"))
            NX(" ")

            Dim myPt3D As Point3d = New NXOpen.Point3d(newPt(0), newPt(1), newPt(2))
            Dim myPoint As NXOpen.Point = Nothing
            myPoint = workPart.Points.CreatePoint(myPt3D)
            workPart.Points.RemoveParameters(myPoint)
            myPoint.SetVisibility(NXOpen.SmartObject.VisibilityOption.Visible)
            myPoint.RedisplayObject()

            'point6.RedisplayObject()

            ' display temp point at Delta distance...
            poicolour.color = 42
            'ufs.Disp.DisplayTemporaryPoint(NXOpen.Tag.Null, UFDisp.ViewType.UseWorkView, newPt, poicolour, UFDisp.PolyMarker.Asterisk)

            NX("--------------------------------------------")
            NX("--------------------------------------------")
        End While

    End Sub



    '=========================== NX LISTING WINDOW FUNCTION=======================================

    Public Sub NX(ByVal input As String) '' output variable listwindow - just for building VB

        If output_To_NXListingWindow Then
            Dim displayPart As Part = theSession.Parts.Display
            Dim lw As ListingWindow = theSession.ListingWindow()
            lw.Open()
            lw.WriteLine(input)
        End If

    End Sub
    '===============================================================================================

    '=========================== NX WRITE TO LOGFILE FUNCTION=======================================

    Public Sub NX_log(ByVal input As String) '' output variable listwindow - just for building VB

        If output_To_NXLogFile Then
            theSession.LogFile.WriteLine(input)
        End If

    End Sub
    '================================================================================================

    '=========================== NX UNLOAD FUNCTION ================================================

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination ' typically used in Checkmate only

    End Function
    '================================================================================================

    '================================================================================================
    '================================================================================================

    Function select_a_Planarface(ByVal prompt As String, ByRef obj As Face)
        Dim ui As UI = GetUI()
        Dim mask(0) As Selection.MaskTriple
        With mask(0)
            .Type = UFConstants.UF_solid_type
            .Subtype = UFConstants.UF_solid_face_subtype
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_PLANAR_FACE
        End With
        Dim cursor As Point3d = Nothing

        Dim resp As Selection.Response =
        ui.SelectionManager.SelectObject(prompt, prompt,
            Selection.SelectionScope.AnyInAssembly,
            Selection.SelectionAction.ClearAndEnableSpecific,
            False, False, mask, obj, cursor)

        If resp = Selection.Response.ObjectSelected Or
           resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

    '================================================================================================
    '================================================================================================

    Function select_a_CylindricalFace(ByRef prompt As String) As Face

        Dim mask(0) As Selection.MaskTriple
        With mask(0)
            .Type = UFConstants.UF_solid_type
            .Subtype = 0
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_CYLINDRICAL_FACE
        End With
        Dim cursor As Point3d = Nothing
        select_a_CylindricalFace = Nothing

        ufs.Ui.LockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)

        UI.GetUI.SelectionManager.SelectTaggedObject(prompt, "Select a Cylindrical Hole Face:",
            Selection.SelectionScope.AnyInAssembly,
            Selection.SelectionAction.ClearAndEnableSpecific, False,
            False, mask, select_a_CylindricalFace, cursor)

        ufs.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)

    End Function

    '================================================================================================
    '================================================================================================
    Public Function CalcIntersectionPoint(ByVal whichPlanarFace As Face, ByVal whichCylindricalFace As Face) As Point3d

        Dim newPoint As Point3d = Nothing

        newPoint.X = 0
        newPoint.Y = 0
        newPoint.Z = 0

        Try

            ' Variables for ufs.Curve.Intersect..
            Dim mystartpoint(2) As Double
            Dim intersectdata1 As NXOpen.UF.UFCurve.IntersectInfo = Nothing

            ' create temporary line
            Dim line1 As NXOpen.Line = Nothing
            line1 = workPart.Lines.CreateFaceAxis(whichCylindricalFace, NXOpen.SmartObject.UpdateOption.WithinModeling)

            ' get the intersection point
            ufs.Curve.Intersect(line1.Tag, whichPlanarFace.Tag, mystartpoint, intersectdata1)

            If Not intersectdata1.type_of_intersection = 1 Then
                ' list the intersection type
                NX(intersectdata1.type_of_intersection)
                MsgBox("no face/line-axis intersect found")
                Return newPoint ' just in case no intersection was calculated...
            End If

            ' delete the line straight after...
            Dim objectstoDelete(0) As NXOpen.NXObject
            objectstoDelete(0) = line1
            Dim nErrs3 As Integer = Nothing
            nErrs3 = theSession.UpdateManager.AddObjectsToDeleteList(objectstoDelete)

            ' Transfer the calculated Point Data into Point3d...
            newPoint.X = intersectdata1.curve_point(0)
            newPoint.Y = intersectdata1.curve_point(1)
            newPoint.Z = intersectdata1.curve_point(2)

            Return newPoint

        Catch

            MsgBox("no face/line-axis intersect found")
            Return newPoint ' just in case no intersection was calculated...

        End Try

    End Function

    '================================================================================================
    '================================================================================================

    Public Function CalcMatrix(ByVal whichPlanarFace As Face) As Matrix3x3

        ' Matrix to be returned -
        Dim newMtx3x3 As Matrix3x3

        newMtx3x3.Xx = 1.0
        newMtx3x3.Xy = 0.0
        newMtx3x3.Xz = 0.0
        newMtx3x3.Yx = 0.0
        newMtx3x3.Yy = 1.0
        newMtx3x3.Yz = 0.0
        newMtx3x3.Zx = 0.0
        newMtx3x3.Zy = 0.0
        newMtx3x3.Zz = 1.0

        Try

            'Dim uvMinMax(3) As Double
            'ufs.Modl.AskFaceUvMinmax(BoltHeadFace(0).Tag, uvMinMax)
            Dim param(1) As Double
            'param(0) = ((uvMinMax(0) + uvMinMax(1)) / 2)
            'param(1) = ((uvMinMax(2) + uvMinMax(3)) / 2)
            Dim newOrigin(2) As Double
            Dim unitNormal(2) As Double
            Dim u1(2) As Double
            Dim u2(2) As Double
            Dim v1(2) As Double
            Dim v2(2) As Double
            Dim radii(1) As Double

            ' ask Face Properties...we need the normal vector...
            ufs.Modl.AskFaceProps(whichPlanarFace.Tag, param, newOrigin, u1,
                              v1, u2, v2, unitNormal, radii)

            Dim newMtx(8) As Double

            ' convert vector 2 Matrix...nice one....
            ufs.Mtx3.InitializeZ(unitNormal, newMtx)
            'build the Matrix 3x3...based on Bolt/Nut Face-vector... 
            newMtx3x3.Xx = newMtx(0)
            newMtx3x3.Xy = newMtx(1)
            newMtx3x3.Xz = newMtx(2)
            newMtx3x3.Yx = newMtx(3)
            newMtx3x3.Yy = newMtx(4)
            newMtx3x3.Yz = newMtx(5)
            newMtx3x3.Zx = newMtx(6)
            newMtx3x3.Zy = newMtx(7)
            newMtx3x3.Zz = newMtx(8)

            'Return the Matrix 
            Return newMtx3x3

        Catch
            MsgBox("cant calculate Matrix 3x3  - we returned the Absolute one instead...")
            Return newMtx3x3
        End Try

    End Function

End Module

Thanks a lot...

br lklo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor