Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Getting a point on a NURBS surface for given params

Status
Not open for further replies.

WilsonBlr

Aerospace
Jun 11, 2014
19


Hi

I am creating a surface using a thru curves option UF_MODL_create_thru_curves. I need to get a point on this surface for a given u and v parameter values. How can this be done ?
Thanks for the help.
Regards
Wilson


 
Replies continue below

Recommended for you

There is a CreatePoint method that will do it. You will need to create 2 scalar objects for the U and V values you are interested in.

Code:
CreatePoint Method (face, scalarU, scalarV, updateOption)

public:
Point^ CreatePoint(
	IParameterizedSurface^ face, 
	Scalar^ scalarU, 
	Scalar^ scalarV, 
	SmartObject.UpdateOption updateOption
)

www.nxjournaling.com
 

Cowski, thanks for the reply.

I see there is no straight way to create scalar objects as the constructor for those are protected.

I saw this function UF_CALL(UF_POINT_create_on_surface(tGeometry, tag_u, tag_v, PtTag)); to which I need to pass tags to scalar objects for u and v.

It can be done this way (I just recorded a journal in NX and snipped this code)
Code:
Part *workPart(m_Session->Parts()->Work());
	
Expression *expression20;
expression20 = workPart->Expressions()->CreateSystemExpressionWithUnits("p1=0.203236403109067", nullUnit);
   
Expression *expression21;
expression21 = workPart->Expressions()->CreateSystemExpressionWithUnits("p2=0.159664232702566", nullUnit);
	
Scalar *scalar4;
scalar4 = workPart->Scalars()->CreateScalarExpression(expression20, Scalar::DimensionalityTypeNone, SmartObject::UpdateOptionWithinModeling);
    
Scalar *scalar5;
scalar5 = workPart->Scalars()->CreateScalarExpression(expression21, Scalar::DimensionalityTypeNone, SmartObject::UpdateOptionWithinModeling);

Point *point2;
point2 = workPart->Points()->CreatePoint(face1, scalar4, scalar5, SmartObject::UpdateOptionWithinModeling);


Is there any straightforward way to create the scalars?

And finally the point is returned through a tag_t. How do I convert it back to a point so that I can see the coordinates ?
 
I won't be much help with the C++ syntax, but here goes...

If you have the tag of an object, you can get the object through the NXObjectManager:

Code:
Dim myPoint As Point = Utilities.NXObjectManager.Get(thePointTag)

The object manager will return an object of type "TaggedObject"; but if I know what type of object I'm asking for, I can create my object accordingly and the API will implicitly cast it to the type I specified. Of course you can perform an explicit cast after you get the tagged object if you prefer not to use implicit type casting.


Below is a VB journal that will allow you to select a B surface and create a point at the 50% U and 50% V location. I'll bet you can translate it to C++ better than I can.

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUfSession As UFSession = UFSession.GetUFSession
        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Const undoMarkName As String = "NXJ journal"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)


        Dim mySurf As TaggedObject
        If SelectBsurface("Select B surface", mySurf) = Selection.Response.Cancel Then
            Return
        End If

        'lw.WriteLine(mySurf.GetType.ToString)
        Dim mySurfInfo As UFModl.Bsurface
        theUfSession.Modl.AskBsurf(mySurf.Tag, mySurfInfo)
        lw.WriteLine("num U poles: " & mySurfInfo.num_poles_u.ToString)
        lw.WriteLine("num V poles: " & mySurfInfo.num_poles_v.ToString)

        Dim u As Scalar = workPart.Scalars.CreateScalar(0.5, Scalar.DimensionalityType.None, SmartObject.UpdateOption.DontUpdate)
        Dim v As Scalar = workPart.Scalars.CreateScalar(0.5, Scalar.DimensionalityType.None, SmartObject.UpdateOption.DontUpdate)

        Dim theFace As IParameterizedSurface = mySurf
        Dim uvPoint As Point = workPart.Points.CreatePoint(theFace, u, v, SmartObject.UpdateOption.AfterModeling)
        uvPoint.SetVisibility(SmartObject.VisibilityOption.Visible)

        lw.WriteLine(uvPoint.Coordinates.ToString)

        lw.Close()

    End Sub

    Function SelectBsurface(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a B surface"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = UFConstants.UF_b_surface_type
            .Subtype = 0
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selobj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        '----Other unload options-------
        'Unloads the image immediately after execution within NX
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function

End Module

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

Part and Inventory Search

Sponsor