×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to get a point information from a curve/line

How to get a point information from a curve/line

How to get a point information from a curve/line

(OP)
Hello all

I don't know if I post the thread in the right forum place? If not, please any suggest me where should I post it to? Thanks
My intention is to use NX Open API to do 2D engine drawing at this moment. For example, I want to use the primitives, such as, lines and arcs to build a 2D machine component.
The question is how to get the information of a point which is existing on a curve/line? That is, if I build an arc using UgArc::create() or NXOpen::Arc, how can I get the coordinate of the point lies at the place of 1/3 of the arc? By reading the documentation, I assume this should be done through the 'Evaluator' method, but I don't know how to use it.

Many thanks
Gan

RE: How to get a point information from a curve/line

(OP)
Btw, the version we are licensed is NX8.5. we are not going to use the GUI the NX provided, but just use the geometric primitives by calling the functions from NX open or NXOpen.


Thanks
Gan

RE: How to get a point information from a curve/line

The AskCurveProps function will do what you want. Open/create a part and draw an arc, the following code will prompt you to select the arc, then will report the point 1/3 along the arc and the end point.

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Dim theSession As Session = Session.GetSession()
    Dim workPart As Part = theSession.Parts.Work
    Dim ufs As UFSession = UFSession.GetUFSession

    Sub Main()

        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim myArc As Arc
        Dim myStartPoint As Point3d
        Dim myEndPoint As Point3d

        Do Until SelectAnArc("select an arc", myArc) = Selection.Response.Cancel
            'workPart.Points.CreatePoint(myArc.CenterPoint).SetVisibility(SmartObject.VisibilityOption.Visible)
            lw.WriteLine("Center: " & myArc.CenterPoint.ToString)
            lw.WriteLine("Start angle: " & myArc.StartAngle.ToString)
            lw.WriteLine("End Angle: " & myArc.EndAngle.ToString)


            'use AskCurveProps to find start/end point of arc
            'curve parameter is normalized (0 to 1)
            lw.WriteLine("AskCurveProps")
            Dim stPt(2) As Double
            Dim edPt(2) As Double
            Dim junk3(2) As Double
            Dim junk1 As Double
            ufs.Modl.AskCurveProps(myArc.Tag, 1/3, stPt, junk3, junk3, junk3, junk1, junk1)
            lw.WriteLine("1/3 point: " & stPt(0) & ", " & stPt(1) & ", " & stPt(2))
            Dim newStartPoint As Point3d = New Point3d(stPt(0), stPt(1), stPt(2))
            workPart.Points.CreatePoint(newStartPoint).SetVisibility(SmartObject.VisibilityOption.Visible)
            ufs.Modl.AskCurveProps(myArc.Tag, 1.0, edPt, junk3, junk3, junk3, junk1, junk1)
            lw.WriteLine("end point: " & edPt(0) & ", " & edPt(1) & ", " & edPt(2))
            Dim newEndPoint As Point3d = New Point3d(edPt(0), edPt(1), edPt(2))
            workPart.Points.CreatePoint(newEndPoint).SetVisibility(SmartObject.VisibilityOption.Visible)
            lw.WriteLine("")

        Loop

    End Sub


    Function SelectAnArc(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select an Arc"
        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_circle_type
            .Subtype = 0
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(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

End Module 

www.nxjournaling.com

RE: How to get a point information from a curve/line

(OP)
Thanks for your reply, cowski.
It's very useful.
I also worked out the way of using object evaluator to do it, using C++. I post the code in below in the hope of that may help others as well:

/* Initialize the Open C API environment */
int errorCode = UF_initialize();
if ( errorCode != 0 )
throw NXOpen::NXException::Create(errorCode);

/* Initialize the NX Open C++ API environment */
NXOpen::Session *theSession = NXOpen::Session::GetSession();


NXOpen::Part *part1;
//To get the part from the part tag
part1 = (NXOpen::Part*)NXOpen::NXObjectManager::Get(partTag);

/* Set Undo mark */
NXOpen::Session::UndoMarkId session_UndoMarkId1;
session_UndoMarkId1 = theSession->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "InteropNXOpenWithUFunc");

/* Create a line using NX Open C++ API*/
//NXOpen::Point3d point3d1(-2.17019791346668, 1.13935390457001, 0);
//NXOpen::Point3d point3d2(-0.714356813182783, 1.13935390457001, 0);
NXOpen::Point3d point3d1(-3., 0.4, 0);
NXOpen::Point3d point3d2( 3., 0.4, 0);
NXOpen::Line *line1;
line1 = part1->Curves()->CreateLine(point3d1, point3d2);

UF_CURVE_line_t line_coords;
UF_CURVE_ask_line_data(line1->Tag(), &line_coords);
tag_t lineTag= line1->Tag();

/* Interrogate line parameters using evaluator object */
UF_EVAL_p_t line_evaluator;
UF_EVAL_initialize ( lineTag, &line_evaluator );

// Get line/arc/edge data.
{
UF_EVAL_line_t line_data;
UF_EVAL_ask_line ( line_evaluator, &line_data ) ;
}
double limits [ 2 ]={0., 0};
double mid_t =0.;
double point [ 3 ];

UF_EVAL_ask_limits ( line_evaluator, limits );
mid_t = ( limits [ 1 ] - limits [ 0 ] ) / 2.0;

cout<<" lineTag= "<<lineTag<<endl;
cout<<" limits[0]= "<< limits[0] << ", limits[1]= "<< limits[1] <<", mid_t= "<<mid_t <<endl;

UF_EVAL_evaluate ( line_evaluator, 1, 0, point, derivative ) ;
cout<<" line start point is: point= {"<<point[0]<<", "<<point[1]<<", "<<point[2]<<"};\n";

UF_EVAL_evaluate ( line_evaluator, 1, mid_t, point, derivative ) ;
cout<<" line interp at "<<mid_t<<" is: point= {"<<point[0]<<", "<<point[1]<<", "<<point[2]<<"};\n";

UF_EVAL_evaluate ( line_evaluator, 1, 1, point, derivative ) ;
cout<<" line end point is: point= {"<<point[0]<<", "<<point[1]<<", "<<point[2]<<"};\n";


/* To save work part using NX Open C++ APIs */
NXOpen::PartSaveStatus *partSaveStatus = part1->Save(NXOpen::Part::SaveComponentsTrue, NXOpen::Part::CloseAfterSaveTrue);
/* To close all parts using NX Open C++ APIs */
theSession->Parts()->CloseAll(NXOpen::BasePart::CloseModifiedCloseModified, NULL);

/* Terminate the Open C API environment */
errorCode = UF_terminate();

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources