×
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

NX8 Associative Measurement to set expression value

NX8 Associative Measurement to set expression value

NX8 Associative Measurement to set expression value

(OP)
Hello,

I am writing a journal to create an airfoil geometry which set by expressions. The journal will be used 1 time to set the geometries and expressions, after that the geometry changes will be made only by the expressions.

My question is, is there a way to define an associative vector expression to an associative datum axis created at an associative percentage of a spline.

For example i have a camberline (studiospline), at 50% of that curve i created a datumaxis normal to the curve. I want to create an associative vector expression that defines that datumaxis. When the inputs are changed, the camberspline will change thus, the datumaxis will change. I want the vector expression also change.

I will explain a method i tried. I created an associative angle measurement between the datum axis and the X-axis, so i have an angle. Then i created a Vector expression "Vector(cos(angle),sin(angle),0)". But the measurement name is automatic (ie. p2) and i can't define this name in journal. I want the journal to create an expression "Vector(cos(p2),sin(p2),0)" if the measurement name is defined as p2 automatically. I setname to measurement, i tried the journalidentifier and the tag but i can't manage to do what i want.

Any help will be appreciated.

Codes are given below.

Function that creates datumaxis

CODE --> C#

public static DatumAxis CreateDatumAxis(Part thePart, NXOpen.Features.StudioSpline spline, double spline_percent, string name)
        {
            NXOpen.Features.Feature nullFeatures_Feature = null;

            NXOpen.Features.StudioSpline studioSpline1 = spline;
            Spline spline1 = (Spline)studioSpline1.FindObject("CURVE 1");

            NXOpen.Features.DatumAxisBuilder datumAxisBuilder1;
            datumAxisBuilder1 = thePart.Features.CreateDatumAxisBuilder(nullFeatures_Feature);
            datumAxisBuilder1.Type = NXOpen.Features.DatumAxisBuilder.Types.OnCurveVector;
            datumAxisBuilder1.ArcLength.IsPercentUsed = true;
            datumAxisBuilder1.CurveOrientation = NXOpen.Features.DatumAxisBuilder.CurveOrientations.Normal;
            datumAxisBuilder1.IsAssociative = true;

            datumAxisBuilder1.Curve.Value = spline1;
            datumAxisBuilder1.ArcLength.Path.Value = spline1;
            datumAxisBuilder1.ArcLength.Update(NXOpen.GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path);
            datumAxisBuilder1.ArcLength.Expression.Value = spline_percent;
            datumAxisBuilder1.IsAxisReversed = true;

            
            NXObject nXObject1;
            nXObject1 = datumAxisBuilder1.Commit();
            nXObject1.SetName(name);
            datumAxisBuilder1.Destroy();

            NXOpen.Features.DatumAxisFeature a = (NXOpen.Features.DatumAxisFeature)nXObject1;

            return a.DatumAxis;

        } 

Function that creates the measurement

CODE --> C#

public static Measure CreateNormalVectorAngleMeasurement(Part thePart, DatumAxis axis1, DatumAxis axis2, string name)
        {
            NXObject nullNXObject = null;
            MeasureAngleBuilder measureAngleBuilder1;
            measureAngleBuilder1 = thePart.MeasureManager.CreateMeasureAngleBuilder(nullNXObject);

            measureAngleBuilder1.Object1.Value = axis1;
            measureAngleBuilder1.Object2.Value = axis2;
            
            Unit nullUnit = null;
            MeasureAngle measureAngle1;
            measureAngle1 = thePart.MeasureManager.NewAngle(nullUnit, axis1, NXOpen.MeasureManager.EndpointType.StartPoint, axis2, NXOpen.MeasureManager.EndpointType.StartPoint, true, false);

            Measure measure1;
            measure1 = measureAngle1.CreateFeature();
            measureAngle1.Dispose();
            measure1.SetName(name);
            measureAngleBuilder1.Destroy();
            
            return measure1;
        } 

Main code

CODE --> C#

public static void Main(string[] args)
        {
            Session theSession = Session.GetSession();
            Part workPart = theSession.Parts.Work;
            Part displayPart = theSession.Parts.Display;

            CamberClass Camber = new CamberClass(workPart, theSession);

            #region Camber Inputs and Expression
            Camber.B1m = 19.0;
            Camber.B2m = -65;
            Camber.Cax = 14.115;
            Camber.Stagger = -38.45;
            Camber.grc = 1;
            Camber.degree = 3;

            Functions.CreateExpression(workPart, "B1m", Camber.B1m.ToString(CultureInfo.InvariantCulture), "Number");
            Functions.CreateExpression(workPart, "B2m", Camber.B2m.ToString(CultureInfo.InvariantCulture), "Number");
            Functions.CreateExpression(workPart, "Cax", Camber.Cax.ToString(CultureInfo.InvariantCulture), "Number");
            Functions.CreateExpression(workPart, "Stagger", Camber.Stagger.ToString(CultureInfo.InvariantCulture), "Number");
            Functions.CreateExpression(workPart, "Camber_grc", Camber.grc.ToString(CultureInfo.InvariantCulture), "Number");
            Functions.CreateExpression(workPart, "Camberdegree", Camber.degree.ToString(CultureInfo.InvariantCulture), "Number");

            //degree>3 input Cys
            if (Camber.degree > 3)
            {
                Camber.Cy.Add(3);  //y coordinate of control points except P0,P1,Pn-1 [P2=Cy(0)...Pn-2=Cy(degree-4)]
                Camber.Cy.Add(-5); //Degree-4 //e kadar gir, girilmezse 0 alır

                for (int i = 2; i <= Camber.degree - 2; i++)
                {
                    Functions.CreateExpression(workPart, "Camber_Cy" + i.ToString(), Camber.Cy[i - 2].ToString(CultureInfo.InvariantCulture), "Number");
                }
            }
            #endregion

            Point3d StartPoint = new Point3d(0, 0, 0);

            NXOpen.Features.DatumCsys ABSCSYS;
            ABSCSYS = Functions.CreateAbsoluteCoordinateSystem(workPart, "Absolute Coordinate System");

            Camber.CamberControlPointsExpressions(StartPoint, "Camber");
          
            DatumAxis x1;
            x1 = Functions.CreateDatumAxis(workPart, Camber.CamberSpline, 50, "datum1");
            DatumAxis x2;
            x2 = (DatumAxis)workPart.Datums.FindObject(ABSCSYS.JournalIdentifier.ToString() + " X axis");

            Measure a;
            a = Functions.CreateNormalVectorAngleMeasurement(workPart, x1, x2, "a1");

        } 

The section below creates the measurement. Now i want the journal to create an expression of a vector "Vector(cos(p2),sin(p2),0)" if the measurement name in expression tab is p2.

CODE --> C#

DatumAxis x1;
            x1 = Functions.CreateDatumAxis(workPart, Camber.CamberSpline, 50, "datum1");
            DatumAxis x2;
            x2 = (DatumAxis)workPart.Datums.FindObject(ABSCSYS.JournalIdentifier.ToString() + " X axis");

            Measure a;
            a = Functions.CreateNormalVectorAngleMeasurement(workPart, x1, x2, "a1"); 

RE: NX8 Associative Measurement to set expression value

(OP)
I figured out the solution.

CODE --> C#

DatumAxis x1;
x1 = Functions.CreateDatumAxis(workPart, Camber.CamberSpline, 50, "datum1");
DatumAxis x2;
x2 = (DatumAxis)workPart.Datums.FindObject(ABSCSYS.JournalIdentifier.ToString() + " X axis");

Measure a;
a = Functions.CreateNormalVectorAngleMeasurement(workPart, x1, x2, "a1"); 


After the "measurement a1" is created by the code above. NXObjectManager.Get gets the measurement expression. Then .Name method gives the automatically assigned measurement name (i.e. "p2").

CODE --> C#

Expression n1 = (Expression)NXObjectManager.Get(a.GetExpressions()[0].Tag);
Functions.CreateExpression(thePart, "V1", "Vector(cos(" + n1.Name + "),sin(" + n1.Name + "),0)", "Vector"); 

CreateExpression function is given below

CODE --> C#

public static void CreateExpression(Part thePart, string expName, string expValue, string expType)
        {
            thePart.Expressions.CreateSystemExpression(expType, expName + "=" + expValue.ToString(CultureInfo.InvariantCulture));
        } 

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