Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

How to get a point information from a curve/line

Status
Not open for further replies.

lugan2

Mechanical
Apr 10, 2013
42
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
 
Replies continue below

Recommended for you

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
 
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
 
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();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor