Exemplo n.º 1
0
    public NXOpen.Features.DatumCsys CsysCreation(Part workPart, Point3d pointOrigin3d, Point3d pointAxis13d, Point3d pointAxis23d)
    {
        NXOpen.Features.Feature          nullFeatures_Feature = null;
        NXOpen.Features.DatumCsysBuilder datumCsysBuilder;
        datumCsysBuilder = workPart.Features.CreateDatumCsysBuilder(nullFeatures_Feature);

        Point pointOrigin = workPart.Points.CreatePoint(pointOrigin3d);
        Point pointAxis2  = workPart.Points.CreatePoint(pointAxis13d);
        Point pointAxis1  = workPart.Points.CreatePoint(pointAxis23d);

        Xform xform1;

        xform1 = workPart.Xforms.CreateXform(pointOrigin, pointAxis1, pointAxis2, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0);

        CartesianCoordinateSystem cartesianCoordinateSystem;

        cartesianCoordinateSystem = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, NXOpen.SmartObject.UpdateOption.WithinModeling);

        datumCsysBuilder.Csys = cartesianCoordinateSystem;
        datumCsysBuilder.ComponentsCreation = true;
        datumCsysBuilder.FixedSizeDatum     = true;
        datumCsysBuilder.DisplayScaleFactor = 1.25;

        NXObject cSys = datumCsysBuilder.Commit();

        string journalName = cSys.JournalIdentifier.ToString();

        NXOpen.Features.DatumCsys datumCsys = (NXOpen.Features.DatumCsys)workPart.Features.FindObject(journalName);

        datumCsysBuilder.Destroy();

        return(datumCsys);
    }
Exemplo n.º 2
0
    public NXOpen.Features.DatumCsys CsysCreation(Part workPart, Point pointOrigin, DatumAxis Axis1, DatumAxis Axis2)
    {
        NXOpen.Features.Feature          nullFeatures_Feature = null;
        NXOpen.Features.DatumCsysBuilder datumCsysBuilder;
        datumCsysBuilder = workPart.Features.CreateDatumCsysBuilder(nullFeatures_Feature);

        Sense sense1 = new Sense();
        Sense sense2 = new Sense();

        Direction direction1;

        direction1 = workPart.Directions.CreateDirection(Axis1, sense1, SmartObject.UpdateOption.WithinModeling);

        Direction direction2;

        direction2 = workPart.Directions.CreateDirection(Axis2, sense2, SmartObject.UpdateOption.WithinModeling);

        Xform xform1;

        xform1 = workPart.Xforms.CreateXform(pointOrigin, direction1, direction2, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0);

        CartesianCoordinateSystem cartesianCoordinateSystem;

        cartesianCoordinateSystem = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, NXOpen.SmartObject.UpdateOption.WithinModeling);

        datumCsysBuilder.Csys = cartesianCoordinateSystem;
        datumCsysBuilder.ComponentsCreation = true;
        datumCsysBuilder.FixedSizeDatum     = true;
        datumCsysBuilder.DisplayScaleFactor = 1.25;

        NXObject cSys = datumCsysBuilder.Commit();

        string journalName = cSys.JournalIdentifier.ToString();

        NXOpen.Features.DatumCsys datumCsys = (NXOpen.Features.DatumCsys)workPart.Features.FindObject(journalName);

        datumCsysBuilder.Destroy();

        return(datumCsys);
    }
Exemplo n.º 3
0
    public static void Main(string[] args)
    {
        Console.WriteLine("Starting NX Golden Cantilever Journal");

        //Declare Part Variables
        //Convert Strings to doubles from the args
        double heightA   = System.Convert.ToDouble(args[0]);
        double length    = System.Convert.ToDouble(args[1]);
        double thickness = System.Convert.ToDouble(args[2]);


        //Declare part name for the part file and the IGES file
        string part_name     = args[3];
        string part_name_prt = part_name + ".prt";
        string part_name_igs = part_name + ".igs";

        //Measurements need to be converted from m to mm
        //length = 1000 * length;
        //thickness = 1000 * thickness;
        //heightA = 1000 * heightA;
        double heightB = 1.618 * heightA;


        //Convert necessary values back to strings because I already
        //converted them to doubles and I'm too lazy to go back and change
        //this since it works.
        string length_string    = System.Convert.ToString(length);
        string thickness_string = System.Convert.ToString(thickness);
        string heightA_string   = System.Convert.ToString(heightA);
        string heightB_string   = System.Convert.ToString(heightB);

        NXOpen.Session theSession = NXOpen.Session.GetSession();
        // ----------------------------------------------
        //   Menu: File->New...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId1;
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        NXOpen.FileNew fileNew1;
        fileNew1 = theSession.Parts.FileNew();

        theSession.SetUndoMarkName(markId1, "New Dialog");

        NXOpen.Session.UndoMarkId markId2;
        markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "New");

        theSession.DeleteUndoMark(markId2, null);

        NXOpen.Session.UndoMarkId markId3;
        markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "New");

        fileNew1.TemplateFileName = "model-plain-1-mm-template.prt";

        fileNew1.UseBlankTemplate = false;

        fileNew1.ApplicationName = "ModelTemplate";

        fileNew1.Units = NXOpen.Part.Units.Millimeters;

        fileNew1.RelationType = "";

        fileNew1.UsesMasterModel = "No";

        fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item;

        fileNew1.TemplatePresentationName = "Model";

        fileNew1.ItemType = "";

        fileNew1.Specialization = "";

        fileNew1.SetCanCreateAltrep(false);

        fileNew1.NewFileName = part_name_prt;

        fileNew1.MasterFileName = "";

        fileNew1.MakeDisplayedPart = true;

        NXOpen.NXObject nXObject1;
        nXObject1 = fileNew1.Commit();

        NXOpen.Part workPart    = theSession.Parts.Work;
        NXOpen.Part displayPart = theSession.Parts.Display;
        theSession.DeleteUndoMark(markId3, null);

        fileNew1.Destroy();

        theSession.ApplicationSwitchImmediate("UG_APP_MODELING");

        NXOpen.Session.UndoMarkId markId4;
        markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Enter Gateway");

        NXOpen.Session.UndoMarkId markId5;
        markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Enter Modeling");

        // ----------------------------------------------
        //   Menu: Insert->Sketch...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId6;
        markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        NXOpen.Sketch nullNXOpen_Sketch = null;
        NXOpen.SketchInPlaceBuilder sketchInPlaceBuilder1;
        sketchInPlaceBuilder1 = workPart.Sketches.CreateNewSketchInPlaceBuilder(nullNXOpen_Sketch);

        NXOpen.Unit       unit1 = (NXOpen.Unit)workPart.UnitCollection.FindObject("MilliMeter");
        NXOpen.Expression expression1;
        expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

        NXOpen.Expression expression2;
        expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

        NXOpen.SketchAlongPathBuilder sketchAlongPathBuilder1;
        sketchAlongPathBuilder1 = workPart.Sketches.CreateSketchAlongPathBuilder(nullNXOpen_Sketch);

        sketchAlongPathBuilder1.PlaneLocation.Expression.RightHandSide = "0";

        theSession.SetUndoMarkName(markId6, "Create Sketch Dialog");

        NXOpen.DatumPlane datumPlane1 = (NXOpen.DatumPlane)workPart.Datums.FindObject("DATUM_CSYS(0) YZ plane");
        NXOpen.Point3d    point1      = new NXOpen.Point3d(11.1863449593062, 6.4875984180345, 0.0);
        sketchInPlaceBuilder1.PlaneOrFace.SetValue(datumPlane1, workPart.ModelingViews.WorkView, point1);

        NXOpen.Features.DatumCsys datumCsys1 = (NXOpen.Features.DatumCsys)workPart.Features.FindObject("DATUM_CSYS(0)");
        NXOpen.Point point2 = (NXOpen.Point)datumCsys1.FindObject("POINT 1");
        sketchInPlaceBuilder1.SketchOrigin = point2;

        sketchInPlaceBuilder1.PlaneOrFace.Value = null;

        sketchInPlaceBuilder1.PlaneOrFace.Value = datumPlane1;

        NXOpen.DatumAxis datumAxis1 = (NXOpen.DatumAxis)workPart.Datums.FindObject("DATUM_CSYS(0) X axis");
        sketchInPlaceBuilder1.Axis.Value = datumAxis1;

        NXOpen.Session.UndoMarkId markId7;
        markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Create Sketch");

        theSession.DeleteUndoMark(markId7, null);

        NXOpen.Session.UndoMarkId markId8;
        markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Create Sketch");

        theSession.Preferences.Sketch.CreateInferredConstraints = true;

        theSession.Preferences.Sketch.ContinuousAutoDimensioning = true;

        theSession.Preferences.Sketch.DimensionLabel = NXOpen.Preferences.SketchPreferences.DimensionLabelType.Expression;

        theSession.Preferences.Sketch.TextSizeFixed = true;

        theSession.Preferences.Sketch.FixedTextSize = 3.0;

        theSession.Preferences.Sketch.ConstraintSymbolSize = 3.0;

        theSession.Preferences.Sketch.DisplayObjectColor = false;

        theSession.Preferences.Sketch.DisplayObjectName = true;

        NXOpen.NXObject nXObject2;
        nXObject2 = sketchInPlaceBuilder1.Commit();

        NXOpen.Sketch           sketch1 = (NXOpen.Sketch)nXObject2;
        NXOpen.Features.Feature feature1;
        feature1 = sketch1.Feature;

        NXOpen.Session.UndoMarkId markId9;
        markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "update");

        int nErrs1;

        nErrs1 = theSession.UpdateManager.DoUpdate(markId9);

        sketch1.Activate(NXOpen.Sketch.ViewReorient.True);

        theSession.DeleteUndoMark(markId8, null);

        theSession.SetUndoMarkName(markId6, "Create Sketch");

        sketchInPlaceBuilder1.Destroy();

        sketchAlongPathBuilder1.Destroy();

        try
        {
            // Expression is still in use.
            workPart.Expressions.Delete(expression2);
        }
        catch (NXException ex)
        {
            ex.AssertErrorCode(1050029);
        }

        try
        {
            // Expression is still in use.
            workPart.Expressions.Delete(expression1);
        }
        catch (NXException ex)
        {
            ex.AssertErrorCode(1050029);
        }

        // ----------------------------------------------
        //   Menu: Insert->Sketch Curve->Line...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId10;
        markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Profile short list");

        NXOpen.Session.UndoMarkId markId11;
        markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Curve");

        NXOpen.Expression expression3;
        expression3 = workPart.Expressions.CreateSystemExpression(length_string);

        theSession.SetUndoMarkVisibility(markId11, "Curve", NXOpen.Session.MarkVisibility.Visible);

        NXOpen.Point3d startPoint1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
        NXOpen.Point3d endPoint1   = new NXOpen.Point3d(length, 0.0, 0.0);
        NXOpen.Line    line1;
        line1 = workPart.Curves.CreateLine(startPoint1, endPoint1);

        theSession.ActiveSketch.AddGeometry(line1, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        NXOpen.Sketch.ConstraintGeometry geom1_1 = new NXOpen.Sketch.ConstraintGeometry();
        geom1_1.Geometry  = line1;
        geom1_1.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom1_1.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_1    = new NXOpen.Sketch.ConstraintGeometry();
        NXOpen.Features.DatumCsys        datumCsys2 = (NXOpen.Features.DatumCsys)workPart.Features.FindObject("SKETCH(1:1B)");
        NXOpen.Point point3 = (NXOpen.Point)datumCsys2.FindObject("POINT 1");
        geom2_1.Geometry  = point3;
        geom2_1.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom2_1.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint1;
        sketchGeometricConstraint1 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_1, geom2_1);

        NXOpen.Sketch.ConstraintGeometry geom1 = new NXOpen.Sketch.ConstraintGeometry();
        geom1.Geometry  = line1;
        geom1.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom1.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint2;
        sketchGeometricConstraint2 = theSession.ActiveSketch.CreateHorizontalConstraint(geom1);

        NXOpen.Sketch.DimensionGeometry dimObject1_1 = new NXOpen.Sketch.DimensionGeometry();
        dimObject1_1.Geometry    = line1;
        dimObject1_1.AssocType   = NXOpen.Sketch.AssocType.StartPoint;
        dimObject1_1.AssocValue  = 0;
        dimObject1_1.HelpPoint.X = 0.0;
        dimObject1_1.HelpPoint.Y = 0.0;
        dimObject1_1.HelpPoint.Z = 0.0;
        NXOpen.NXObject nullNXOpen_NXObject = null;
        dimObject1_1.View = nullNXOpen_NXObject;
        NXOpen.Sketch.DimensionGeometry dimObject2_1 = new NXOpen.Sketch.DimensionGeometry();
        dimObject2_1.Geometry    = line1;
        dimObject2_1.AssocType   = NXOpen.Sketch.AssocType.EndPoint;
        dimObject2_1.AssocValue  = 0;
        dimObject2_1.HelpPoint.X = 0.0;
        dimObject2_1.HelpPoint.Y = 0.0;
        dimObject2_1.HelpPoint.Z = 0.0;
        dimObject2_1.View        = nullNXOpen_NXObject;
        NXOpen.Point3d dimOrigin1 = new NXOpen.Point3d(45.0, -9.0598069411704, 0.0);
        NXOpen.SketchDimensionalConstraint sketchDimensionalConstraint1;
        sketchDimensionalConstraint1 = theSession.ActiveSketch.CreateDimension(NXOpen.Sketch.ConstraintType.ParallelDim, dimObject1_1, dimObject2_1, dimOrigin1, expression3, NXOpen.Sketch.DimensionOption.CreateAsDriving);

        NXOpen.SketchHelpedDimensionalConstraint sketchHelpedDimensionalConstraint1 = (NXOpen.SketchHelpedDimensionalConstraint)sketchDimensionalConstraint1;
        NXOpen.Annotations.Dimension             dimension1;
        dimension1 = sketchHelpedDimensionalConstraint1.AssociatedDimension;

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId12;
        markId12 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Curve");

        NXOpen.Expression expression4;
        expression4 = workPart.Expressions.CreateSystemExpression(heightA_string);

        NXOpen.Expression expression5;
        expression5 = workPart.Expressions.CreateSystemExpression(length_string);

        workPart.Expressions.Edit(expression4, heightA_string);

        theSession.SetUndoMarkVisibility(markId12, "Curve", NXOpen.Session.MarkVisibility.Visible);

        NXOpen.Point3d startPoint2 = new NXOpen.Point3d(length, 0.0, 0.0);
        NXOpen.Point3d endPoint2   = new NXOpen.Point3d(length, heightA, 0.0);
        NXOpen.Line    line2;
        line2 = workPart.Curves.CreateLine(startPoint2, endPoint2);

        theSession.ActiveSketch.AddGeometry(line2, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        NXOpen.Sketch.ConstraintGeometry geom1_2 = new NXOpen.Sketch.ConstraintGeometry();
        geom1_2.Geometry  = line2;
        geom1_2.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom1_2.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_2 = new NXOpen.Sketch.ConstraintGeometry();
        geom2_2.Geometry  = line1;
        geom2_2.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom2_2.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint3;
        sketchGeometricConstraint3 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_2, geom2_2);

        NXOpen.Sketch.ConstraintGeometry geom2 = new NXOpen.Sketch.ConstraintGeometry();
        geom2.Geometry  = line2;
        geom2.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom2.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint4;
        sketchGeometricConstraint4 = theSession.ActiveSketch.CreateVerticalConstraint(geom2);

        workPart.Expressions.Delete(expression5);

        NXOpen.Sketch.DimensionGeometry dimObject1_2 = new NXOpen.Sketch.DimensionGeometry();
        dimObject1_2.Geometry    = line2;
        dimObject1_2.AssocType   = NXOpen.Sketch.AssocType.StartPoint;
        dimObject1_2.AssocValue  = 0;
        dimObject1_2.HelpPoint.X = 0.0;
        dimObject1_2.HelpPoint.Y = 0.0;
        dimObject1_2.HelpPoint.Z = 0.0;
        dimObject1_2.View        = nullNXOpen_NXObject;
        NXOpen.Sketch.DimensionGeometry dimObject2_2 = new NXOpen.Sketch.DimensionGeometry();
        dimObject2_2.Geometry    = line2;
        dimObject2_2.AssocType   = NXOpen.Sketch.AssocType.EndPoint;
        dimObject2_2.AssocValue  = 0;
        dimObject2_2.HelpPoint.X = 0.0;
        dimObject2_2.HelpPoint.Y = 0.0;
        dimObject2_2.HelpPoint.Z = 0.0;
        dimObject2_2.View        = nullNXOpen_NXObject;
        NXOpen.Point3d dimOrigin2 = new NXOpen.Point3d(99.0598069411704, 15.0, 0.0);
        NXOpen.SketchDimensionalConstraint sketchDimensionalConstraint2;
        sketchDimensionalConstraint2 = theSession.ActiveSketch.CreateDimension(NXOpen.Sketch.ConstraintType.ParallelDim, dimObject1_2, dimObject2_2, dimOrigin2, expression4, NXOpen.Sketch.DimensionOption.CreateAsDriving);

        NXOpen.SketchHelpedDimensionalConstraint sketchHelpedDimensionalConstraint2 = (NXOpen.SketchHelpedDimensionalConstraint)sketchDimensionalConstraint2;
        NXOpen.Annotations.Dimension             dimension2;
        dimension2 = sketchHelpedDimensionalConstraint2.AssociatedDimension;

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId13;
        markId13 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Curve");

        NXOpen.Expression expression6;
        expression6 = workPart.Expressions.CreateSystemExpression(heightB_string);

        NXOpen.Expression expression7;
        expression7 = workPart.Expressions.CreateSystemExpression(length_string);

        theSession.SetUndoMarkVisibility(markId13, "Curve", NXOpen.Session.MarkVisibility.Visible);

        NXOpen.Point3d startPoint3 = new NXOpen.Point3d(0.0, 0.0, 0.0);
        NXOpen.Point3d endPoint3   = new NXOpen.Point3d(7.02873218749514e-014, heightB, 0.0);
        NXOpen.Line    line3;
        line3 = workPart.Curves.CreateLine(startPoint3, endPoint3);

        theSession.ActiveSketch.AddGeometry(line3, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        NXOpen.Sketch.ConstraintGeometry geom1_3 = new NXOpen.Sketch.ConstraintGeometry();
        geom1_3.Geometry  = line3;
        geom1_3.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom1_3.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_3 = new NXOpen.Sketch.ConstraintGeometry();
        geom2_3.Geometry  = line1;
        geom2_3.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_3.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint5;
        sketchGeometricConstraint5 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_3, geom2_3);

        NXOpen.Sketch.ConstraintGeometry geom3 = new NXOpen.Sketch.ConstraintGeometry();
        geom3.Geometry  = line3;
        geom3.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom3.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint6;
        sketchGeometricConstraint6 = theSession.ActiveSketch.CreateVerticalConstraint(geom3);

        workPart.Expressions.Delete(expression7);

        NXOpen.Sketch.DimensionGeometry dimObject1_3 = new NXOpen.Sketch.DimensionGeometry();
        dimObject1_3.Geometry    = line3;
        dimObject1_3.AssocType   = NXOpen.Sketch.AssocType.StartPoint;
        dimObject1_3.AssocValue  = 0;
        dimObject1_3.HelpPoint.X = 0.0;
        dimObject1_3.HelpPoint.Y = 0.0;
        dimObject1_3.HelpPoint.Z = 0.0;
        dimObject1_3.View        = nullNXOpen_NXObject;
        NXOpen.Sketch.DimensionGeometry dimObject2_3 = new NXOpen.Sketch.DimensionGeometry();
        dimObject2_3.Geometry    = line3;
        dimObject2_3.AssocType   = NXOpen.Sketch.AssocType.EndPoint;
        dimObject2_3.AssocValue  = 0;
        dimObject2_3.HelpPoint.X = 0.0;
        dimObject2_3.HelpPoint.Y = 0.0;
        dimObject2_3.HelpPoint.Z = 0.0;
        dimObject2_3.View        = nullNXOpen_NXObject;
        NXOpen.Point3d dimOrigin3 = new NXOpen.Point3d(9.05980694117043, heightA, 0.0);
        NXOpen.SketchDimensionalConstraint sketchDimensionalConstraint3;
        sketchDimensionalConstraint3 = theSession.ActiveSketch.CreateDimension(NXOpen.Sketch.ConstraintType.ParallelDim, dimObject1_3, dimObject2_3, dimOrigin3, expression6, NXOpen.Sketch.DimensionOption.CreateAsDriving);

        NXOpen.SketchHelpedDimensionalConstraint sketchHelpedDimensionalConstraint3 = (NXOpen.SketchHelpedDimensionalConstraint)sketchDimensionalConstraint3;
        NXOpen.Annotations.Dimension             dimension3;
        dimension3 = sketchHelpedDimensionalConstraint3.AssociatedDimension;

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId14;
        markId14 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Curve");

        theSession.SetUndoMarkVisibility(markId14, "Curve", NXOpen.Session.MarkVisibility.Visible);

        NXOpen.Point3d startPoint4 = new NXOpen.Point3d(0.0, heightB, 0.0);
        NXOpen.Point3d endPoint4   = new NXOpen.Point3d(length, heightA, 0.0);
        //NXOpen.Point3d endPoint4 = new NXOpen.Point3d(90.0, 29.9999999999998, 0.0);
        NXOpen.Line line4;
        line4 = workPart.Curves.CreateLine(startPoint4, endPoint4);

        theSession.ActiveSketch.AddGeometry(line4, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        NXOpen.Sketch.ConstraintGeometry geom1_4 = new NXOpen.Sketch.ConstraintGeometry();
        geom1_4.Geometry  = line4;
        geom1_4.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom1_4.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_4 = new NXOpen.Sketch.ConstraintGeometry();
        geom2_4.Geometry  = line3;
        geom2_4.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom2_4.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint7;
        sketchGeometricConstraint7 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_4, geom2_4);

        NXOpen.Sketch.ConstraintGeometry geom1_5 = new NXOpen.Sketch.ConstraintGeometry();
        geom1_5.Geometry  = line4;
        geom1_5.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_5.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_5 = new NXOpen.Sketch.ConstraintGeometry();
        geom2_5.Geometry  = line2;
        geom2_5.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom2_5.SplineDefiningPointIndex = 0;
        NXOpen.SketchGeometricConstraint sketchGeometricConstraint8;
        sketchGeometricConstraint8 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_5, geom2_5);

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------
        // ----------------------------------------------
        //   Menu: File->Finish Sketch
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId15;
        markId15 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Deactivate Sketch");

        theSession.ActiveSketch.Deactivate(NXOpen.Sketch.ViewReorient.False, NXOpen.Sketch.UpdateLevel.Model);

        // ----------------------------------------------
        //   Menu: Insert->Design Feature->Extrude...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId16;
        markId16 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        NXOpen.Features.Feature nullNXOpen_Features_Feature = null;

        if (!workPart.Preferences.Modeling.GetHistoryMode())
        {
            throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
        }

        NXOpen.Features.ExtrudeBuilder extrudeBuilder1;
        extrudeBuilder1 = workPart.Features.CreateExtrudeBuilder(nullNXOpen_Features_Feature);

        NXOpen.Section section1;
        section1 = workPart.Sections.CreateSection(0.0095, 0.01, 0.5);

        extrudeBuilder1.Section = section1;

        extrudeBuilder1.AllowSelfIntersectingSection(true);

        NXOpen.Unit unit2;
        unit2 = extrudeBuilder1.Draft.FrontDraftAngle.Units;

        NXOpen.Expression expression8;
        expression8 = workPart.Expressions.CreateSystemExpressionWithUnits("2.00", unit2);

        extrudeBuilder1.DistanceTolerance = 0.01;

        extrudeBuilder1.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;

        NXOpen.Body[] targetBodies1   = new NXOpen.Body[1];
        NXOpen.Body   nullNXOpen_Body = null;
        targetBodies1[0] = nullNXOpen_Body;
        extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies1);

        extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = "0";

        extrudeBuilder1.Limits.EndExtend.Value.RightHandSide = "25";

        extrudeBuilder1.Offset.StartOffset.RightHandSide = "0";

        extrudeBuilder1.Offset.EndOffset.RightHandSide = "5";

        extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = "0";

        extrudeBuilder1.Limits.EndExtend.Value.RightHandSide = thickness_string;

        extrudeBuilder1.Draft.FrontDraftAngle.RightHandSide = "2";

        extrudeBuilder1.Draft.BackDraftAngle.RightHandSide = "2";

        extrudeBuilder1.Offset.StartOffset.RightHandSide = "0";

        extrudeBuilder1.Offset.EndOffset.RightHandSide = "5";

        NXOpen.GeometricUtilities.SmartVolumeProfileBuilder smartVolumeProfileBuilder1;
        smartVolumeProfileBuilder1 = extrudeBuilder1.SmartVolumeProfile;

        smartVolumeProfileBuilder1.OpenProfileSmartVolumeOption = false;

        smartVolumeProfileBuilder1.CloseProfileRule = NXOpen.GeometricUtilities.SmartVolumeProfileBuilder.CloseProfileRuleType.Fci;

        theSession.SetUndoMarkName(markId16, "Extrude Dialog");

        section1.DistanceTolerance = 0.01;

        section1.ChainingTolerance = 0.0095;

        section1.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);

        NXOpen.Session.UndoMarkId markId17;
        markId17 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");

        NXOpen.Session.UndoMarkId markId18;
        markId18 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);

        NXOpen.Features.Feature[]     features1      = new NXOpen.Features.Feature[1];
        NXOpen.Features.SketchFeature sketchFeature1 = (NXOpen.Features.SketchFeature)feature1;
        features1[0] = sketchFeature1;
        NXOpen.CurveFeatureRule curveFeatureRule1;
        curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1);

        section1.AllowSelfIntersection(true);

        NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
        rules1[0] = curveFeatureRule1;
        NXOpen.Point3d helpPoint1 = new NXOpen.Point3d(53.8762063337749, 42.0412645554082, 0.0);
        section1.AddToSection(rules1, line4, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1, NXOpen.Section.Mode.Create, false);

        theSession.DeleteUndoMark(markId18, null);

        NXOpen.Direction direction1;
        direction1 = workPart.Directions.CreateDirection(sketch1, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling);

        extrudeBuilder1.Direction = direction1;

        theSession.DeleteUndoMark(markId17, null);

        NXOpen.Session.UndoMarkId markId19;
        markId19 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Extrude");

        theSession.DeleteUndoMark(markId19, null);

        NXOpen.Session.UndoMarkId markId20;
        markId20 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Extrude");

        extrudeBuilder1.ParentFeatureInternal = false;

        NXOpen.Features.Feature feature2;
        feature2 = extrudeBuilder1.CommitFeature();

        theSession.DeleteUndoMark(markId20, null);

        theSession.SetUndoMarkName(markId16, "Extrude");

        NXOpen.Expression expression9  = extrudeBuilder1.Limits.StartExtend.Value;
        NXOpen.Expression expression10 = extrudeBuilder1.Limits.EndExtend.Value;
        extrudeBuilder1.Destroy();

        workPart.Expressions.Delete(expression8);

        // ----------------------------------------------
        //   Menu: File->Save
        // ----------------------------------------------
        NXOpen.PartSaveStatus partSaveStatus1;
        partSaveStatus1 = workPart.Save(NXOpen.BasePart.SaveComponents.True, NXOpen.BasePart.CloseAfterSave.False);

        partSaveStatus1.Dispose();
        // ----------------------------------------------
        //   Menu: File->Export->IGES...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId21;
        markId21 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        NXOpen.IgesCreator igesCreator1;
        igesCreator1 = theSession.DexManager.CreateIgesCreator();

        igesCreator1.ExportModelData = true;

        igesCreator1.ExportDrawings = true;

        igesCreator1.MapTabCylToBSurf = true;

        igesCreator1.BcurveTol = 0.0508;

        igesCreator1.IdenticalPointResolution = 0.001;

        igesCreator1.MaxThreeDMdlSpace = 10000.0;

        igesCreator1.ObjectTypes.Curves = true;

        igesCreator1.ObjectTypes.Surfaces = true;

        igesCreator1.ObjectTypes.Annotations = true;

        igesCreator1.ObjectTypes.Structures = true;

        igesCreator1.ObjectTypes.Solids = true;

        igesCreator1.OutputFile = part_name_igs;

        igesCreator1.SettingsFile = "C:\\Program Files\\Siemens\\NX 10.0\\iges\\igesexport.def";

        igesCreator1.MaxLineThickness = 2.0;

        igesCreator1.SysDefmaxThreeDMdlSpace = true;

        igesCreator1.SysDefidenticalPointResolution = true;

        igesCreator1.InputFile = part_name_prt;

        igesCreator1.OutputFile = part_name_igs;

        theSession.SetUndoMarkName(markId21, "Export to IGES Options Dialog");

        igesCreator1.OutputFile = part_name_igs;

        NXOpen.Session.UndoMarkId markId22;
        markId22 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Export to IGES Options");

        theSession.DeleteUndoMark(markId22, null);

        NXOpen.Session.UndoMarkId markId23;
        markId23 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Export to IGES Options");

        igesCreator1.FileSaveFlag = false;

        igesCreator1.LayerMask = "1-256";

        igesCreator1.DrawingList = "";

        igesCreator1.ViewList = "Top,Front,Right,Back,Bottom,Left,Isometric,Trimetric,User Defined";

        NXOpen.NXObject nXObject3;
        nXObject3 = igesCreator1.Commit();

        theSession.DeleteUndoMark(markId23, null);

        theSession.SetUndoMarkName(markId21, "Export to IGES Options");

        igesCreator1.Destroy();

        // ----------------------------------------------
        //   Menu: Tools->Journal->Stop Recording
        // ----------------------------------------------

        Console.WriteLine("Finishing NX Golden Cantilever Journal");
    }
Exemplo n.º 4
0
    public void ToolSketch(Part workPart, Session theSession)
    {
        string com;

        try
        {
            //CordSystemAndGeometry Class object
            CordSystemAndGeometry geomObj = new CordSystemAndGeometry();

            //ReadFile Class object
            ReadFile data = new ReadFile();
            data.ReadData();

            // Definition of cradle center point
            //Point ptCradleCenter = geomObj.Point3DCreation(workPart, 0, 0, 0);
            Point3d ptCradleCenter = new Point3d(0, 0, 0);

            //Definition of cradle Csys
            // Point ptX = geomObj.Point3DCreation(workPart, 10, 0, 0);
            // Point ptY = geomObj.Point3DCreation(workPart, 0, 10, 0);
            Point3d ptX = new Point3d(10, 0, 0);
            Point3d ptY = new Point3d(0, 10, 0);
            NXOpen.Features.DatumCsys csysCradle = geomObj.CsysCreation(workPart, ptCradleCenter, ptX, ptY);

            //Definition of Cradle Angle sign
            // Hand of spiral
            // -- LEFT: -Q
            // -- RIGHT: +Q
            if (data.kierunekLinii == 0)
            {
                data.q = -data.q;
            }
            else if (data.kierunekLinii != 1 && data.kierunekLinii != 0)
            {
                throw new Exception("Niepoprawne dane dotyczace Pochylenia Linii Zeba");
            }
            if (data.q == 0)
            {
                throw new Exception("Niepoprawne dane dotyczace Ustawienia Katowego Glowicy");
            }

            // Taken Q to calculations:
            com = "Q przyjete do obliczen: " + data.q.ToString();
            data.PrintComToLog(theSession, com);

            //Changing polar to cartesian cordinates
            double H = data.u * Math.Cos(data.q * (Math.PI / 180));
            double V = data.u * Math.Sin(data.q * (Math.PI / 180));

            //------ Cutter sketch creation ------

            //Total tooth depth
            double mat = data.hae + data.hfe;
            //Starting points and line
            Point3d pGlo1 = new Point3d(ptCradleCenter.X - data.wys, ptCradleCenter.Y + H, ptCradleCenter.Z + V);
            Point3d pGlo2 = geomObj.Point3DPolar(workPart, pGlo1, -mat, 0);
            Line    lGlo1 = geomObj.UnAssLines(workPart, pGlo1, pGlo2);

            //cutter outline
            Point3d pGlo8  = geomObj.Point3DPolar(workPart, pGlo2, data.d0 / 2, -90);
            Point3d pGlo10 = geomObj.Point3DPolar(workPart, pGlo8, data.wys + mat, 0);
            Point3d pGlo9  = geomObj.Point3DPolar(workPart, pGlo10, data.w2 / 2, -90);
            Point3d pGlo5  = pGlo9;
            Point3d pGlo4  = geomObj.Point3DPolar(workPart, pGlo5, data.wys / Math.Cos(data.alf2wk * Math.PI / 180), 180 + data.alf2wk);
            Point3d pGlo3  = geomObj.Point3DPolar(workPart, pGlo4, mat, 180);
            Point3d pGlo6  = geomObj.Point3DPolar(workPart, pGlo9, data.w2 / 2, 90);
            Point3d pGlo7  = geomObj.Point3DPolar(workPart, pGlo6, data.wys / Math.Cos(data.alf2wp * Math.PI / 180), 180 - data.alf2wp);
            Line    lGlo2  = geomObj.UnAssLines(workPart, pGlo2, pGlo3);
            Line    lGlo3  = geomObj.UnAssLines(workPart, pGlo4, pGlo3);
            Line    lGlo4  = geomObj.UnAssLines(workPart, pGlo5, pGlo4);
            Line    lGlo5  = geomObj.UnAssLines(workPart, pGlo5, pGlo6);
            Line    lGlo6  = geomObj.UnAssLines(workPart, pGlo6, pGlo7);
            Line    lGlo7  = geomObj.UnAssLines(workPart, pGlo7, pGlo1);

            Point3d pointt = new Point3d(0, 0, 0);
            //Point pointInput = workPart.Points.CreatePoint(pointt);
            Point3d pointt2 = new Point3d(0, 20, 0);
            //Point pointInput2 = workPart.Points.CreatePoint(pointt2);

            Curve linia1 = workPart.Curves.CreateLine(pointt, pointt2);
            linia1.SetVisibility(SmartObject.VisibilityOption.Visible);

            //Sketch def
            //Axis normal do sketch plane
            Point3d    helpPointN = new Point3d(0, 0, 1);
            DatumAxis  axisNor    = geomObj.DatumAxisCreation(workPart, ptCradleCenter, helpPointN);
            DatumPlane plane      = geomObj.DatumPlaneCreation(workPart, pGlo2, axisNor);

            //Axis perpendicular to the sketch plane
            Point3d   helpPointP = new Point3d(1, 0, 0);
            DatumAxis axisPer    = geomObj.DatumAxisCreation(workPart, ptCradleCenter, helpPointP);
            Sketch    sketchTool = geomObj.SketchCreation(workPart, theSession, pGlo2, axisPer, plane, csysCradle);

            //Attach geometry to the sketch
            sketchTool.AddGeometry(lGlo2);
            sketchTool.AddGeometry(lGlo3);
            sketchTool.AddGeometry(lGlo4);
            sketchTool.AddGeometry(lGlo5);
            sketchTool.AddGeometry(lGlo6);
            sketchTool.AddGeometry(lGlo7);
            sketchTool.Update();

            //Cutter radius creation
            //Concave side
            Point3d helpPoint1 = geomObj.Point3dOnCurve(workPart, "0.5", lGlo5);
            Point3d helpPoint2 = geomObj.Point3dOnCurve(workPart, "0.5", lGlo4);
            Arc     r02wk      = geomObj.FilletOnSketch(theSession, lGlo5, lGlo4, helpPoint1, helpPoint2, data.r02wk);
            //Convex side
            helpPoint1 = geomObj.Point3dOnCurve(workPart, "0.5", lGlo5);
            helpPoint2 = geomObj.Point3dOnCurve(workPart, "0.5", lGlo6);
            Arc r02wp = geomObj.FilletOnSketch(theSession, lGlo5, lGlo6, helpPoint1, helpPoint2, data.r02wp);
            sketchTool.Update();

            //Creation a solid cutter
            //Axis def
            Vector3d vectorCutterAxis = new Vector3d(1, 0, 0);
            Axis     axisCutter       = geomObj.AxisCreation(workPart, pGlo1, vectorCutterAxis);
            Body     cutter           = geomObj.Revolve(workPart, axisCutter, sketchTool, lGlo6, pGlo1, 0, 360);
        }
        catch (Exception ex) { MessageBox.Show(ex.ToString()); }
    }
Exemplo n.º 5
0
    public Body BlankGeometryCreation(Part workPart, Session theSession)
    {
        try
        {
            //CordSystemAndGeometry Class object
            CordSystemAndGeometry geomObj = new CordSystemAndGeometry();

            //ReadFile Class object
            ReadFile data = new ReadFile();
            data.ReadData();

            //Creating a pitch cone
            Point3d pOto1 = new Point3d(0, 0, data.A);
            Point3d pOto2 = geomObj.Point3DPolar(workPart, pOto1, data.re, 90);
            Line    lOto1 = geomObj.UnAssLines(workPart, pOto1, pOto2);

            //Creating a symmetry line
            Point3d pOto90 = geomObj.Point3DPolar(workPart, pOto1, data.re, (90 - data.del));
            Line    lOto90 = geomObj.UnAssLines(workPart, pOto1, pOto90);

            //Toe line
            Point3d pOto91 = geomObj.Point3DPolar(workPart, pOto1, (data.re - data.B), 90);
            Point3d pOto92 = geomObj.Point3DPolar(workPart, pOto91, (data.hae + data.hfe), 0);
            Point3d pOto93 = geomObj.Point3DPolar(workPart, pOto91, (data.hae + data.hfe), 180);
            Line    lOto94 = geomObj.UnAssLines(workPart, pOto92, pOto93);

            //Heel line
            Point3d pOto95 = geomObj.Point3DPolar(workPart, pOto2, (data.hae + data.hfe), 0);
            Point3d pOto96 = geomObj.Point3DPolar(workPart, pOto2, (data.hae + data.hfe), 180);
            Line    lOto95 = geomObj.UnAssLines(workPart, pOto95, pOto96);

            //Lwa point
            Point3d pOto100 = geomObj.Point3DPolar(workPart, pOto1, -data.lwa, (90 - data.del));

            //Lwf point
            Point3d pOto101 = geomObj.Point3DPolar(workPart, pOto1, -data.lwf, (90 - data.del));

            //Addendum line
            Point3d pOto102 = geomObj.Point3DPolar(workPart, pOto100, data.re + data.B, 90 - data.del + data.delA);
            Line    lOto102 = geomObj.UnAssLines(workPart, pOto100, pOto102);

            //Dedendum line
            Point3d pOto103 = geomObj.Point3DPolar(workPart, pOto101, data.re + data.B, 90 - data.del + data.delF);
            Line    lOto103 = geomObj.UnAssLines(workPart, pOto101, pOto103);

            //---Sketch----
            //Toe
            Point3d pOto104 = geomObj.Point3dByIntersection(workPart, lOto94, lOto102);
            Point3d pOto105 = geomObj.Point3dByIntersection(workPart, lOto94, lOto103);
            Line    lOto104 = geomObj.UnAssLines(workPart, pOto104, pOto105);

            //Heel
            Point3d pOto106 = geomObj.Point3dByIntersection(workPart, lOto95, lOto102);
            Point3d pOto107 = geomObj.Point3dByIntersection(workPart, lOto95, lOto103);
            Line    lOto106 = geomObj.UnAssLines(workPart, pOto106, pOto107);

            //Addendum line
            Line lOto120 = geomObj.UnAssLines(workPart, pOto104, pOto106);

            //Closing line Toe side
            Point3d pOto108 = geomObj.Point3DPolar(workPart, pOto105, data.re, -data.del);
            Line    lOto108 = geomObj.UnAssLines(workPart, pOto105, pOto108);
            Point3d pOto110 = geomObj.Point3dByIntersection(workPart, lOto90, lOto108);
            Line    lOto112 = geomObj.UnAssLines(workPart, pOto110, pOto105);

            //Closing line Heel side
            Point3d pOto109 = geomObj.Point3DPolar(workPart, pOto107, data.re, -data.del);
            Line    lOto109 = geomObj.UnAssLines(workPart, pOto107, pOto109);
            Point3d pOto111 = geomObj.Point3dByIntersection(workPart, lOto90, lOto109);
            Line    lOto113 = geomObj.UnAssLines(workPart, pOto107, pOto111);

            //Sketch
            Point3d ptX            = new Point3d(10, 0, 0);
            Point3d ptY            = new Point3d(0, 10, 0);
            Point3d ptZ            = new Point3d(0, 0, 10);
            Point3d ptCradleCenter = new Point3d(0, 0, 0);
            NXOpen.Features.DatumCsys csysCradle = geomObj.CsysCreation(workPart, ptCradleCenter, ptX, ptY);
            DatumAxis  datumAxisNor   = geomObj.DatumAxisCreation(workPart, ptCradleCenter, ptZ);
            DatumAxis  datumAxisHoriz = geomObj.DatumAxisCreation(workPart, pOto1, pOto90);
            DatumPlane datumPlane     = geomObj.DatumPlaneCreation(workPart, pOto1, datumAxisNor);
            Sketch     sketchBlank    = geomObj.SketchCreation(workPart, theSession, pOto1, datumAxisHoriz, datumPlane, csysCradle);
            sketchBlank.AddGeometry(lOto104);
            sketchBlank.AddGeometry(lOto106);
            sketchBlank.AddGeometry(lOto120);
            sketchBlank.AddGeometry(lOto112);
            sketchBlank.AddGeometry(lOto113);

            //Axis for body revolution
            Axis axisBodyRev = geomObj.AxisCreation(workPart, pOto1, lOto90);

            //Blank creation
            Body blank = geomObj.Revolve(workPart, axisBodyRev, sketchBlank, lOto104, pOto104, 0, 360);

            //Rotation of Blank to have dedendum linie parallel to the cutter plane
            //Axis of rotation - Cradle axis Z
            Line lineZ   = geomObj.UnAssLines(workPart, ptCradleCenter, ptZ);
            Axis axisZ   = geomObj.AxisCreation(workPart, ptCradleCenter, lineZ);
            Body bodyRot = geomObj.RotationBodyAboutAxis(workPart, blank, axisZ, data.del - data.del2);


            // Moving the Blank by XP
            Line      dedendumLine = geomObj.UnAssLines(workPart, pOto105, pOto107);
            Direction directionXB  = workPart.Directions.CreateDirection(dedendumLine, Sense.Forward, SmartObject.UpdateOption.WithinModeling);
            Body      bodyXP       = geomObj.MoveBodyAlongVector(workPart, bodyRot, directionXB, data.xp);

            // Moving the Blank by XB
            Line      xLine      = geomObj.UnAssLines(workPart, ptCradleCenter, ptX);
            Direction directionX = workPart.Directions.CreateDirection(xLine, Sense.Forward, SmartObject.UpdateOption.WithinModeling);
            Body      bodyXB     = geomObj.MoveBodyAlongVector(workPart, bodyXP, directionX, data.xb);

            bodyBlank = bodyXB;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
        return(bodyBlank);
    }
Exemplo n.º 6
0
    public static void Main(string[] args)
    {
        NXOpen.Session theSession = NXOpen.Session.GetSession();
        // ----------------------------------------------
        //   Menu: File->New...
        // ----------------------------------------------

        //Variable Declaration
        double a = double.Parse(args[0]);
        double G = 1.618;
        double b = G * a;
        double L = 10;
        double t = double.Parse(args[1]);


        NXOpen.FileNew fileNew1;
        fileNew1 = theSession.Parts.FileNew();

        fileNew1.TemplateFileName = "model-plain-1-mm-template.prt";

        fileNew1.UseBlankTemplate = false;

        fileNew1.ApplicationName = "ModelTemplate";

        fileNew1.Units = NXOpen.Part.Units.Millimeters;

        fileNew1.RelationType = "";

        fileNew1.UsesMasterModel = "No";

        fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item;

        fileNew1.TemplatePresentationName = "Model";

        fileNew1.ItemType = "";

        fileNew1.Specialization = "";

        fileNew1.SetCanCreateAltrep(false);

        fileNew1.NewFileName = "J:\\ME 578 Systems\\Midterm\\MidtermProject\\GoldBeam.prt";

        fileNew1.MasterFileName = "";

        fileNew1.MakeDisplayedPart = true;

        NXOpen.NXObject nXObject1;
        nXObject1 = fileNew1.Commit();

        NXOpen.Part workPart    = theSession.Parts.Work;
        NXOpen.Part displayPart = theSession.Parts.Display;

        fileNew1.Destroy();

        theSession.ApplicationSwitchImmediate("UG_APP_MODELING");

        // ----------------------------------------------
        //   Menu: Insert->Sketch...
        // ----------------------------------------------

        NXOpen.Sketch nullNXOpen_Sketch = null;
        NXOpen.SketchInPlaceBuilder sketchInPlaceBuilder1;
        sketchInPlaceBuilder1 = workPart.Sketches.CreateNewSketchInPlaceBuilder(nullNXOpen_Sketch);

        NXOpen.Unit       unit1 = (NXOpen.Unit)workPart.UnitCollection.FindObject("MilliMeter");
        NXOpen.Expression expression1;
        expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

        NXOpen.Expression expression2;
        expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

        NXOpen.SketchAlongPathBuilder sketchAlongPathBuilder1;
        sketchAlongPathBuilder1 = workPart.Sketches.CreateSketchAlongPathBuilder(nullNXOpen_Sketch);

        sketchAlongPathBuilder1.PlaneLocation.Expression.RightHandSide = "0";

        NXOpen.DatumPlane datumPlane1 = (NXOpen.DatumPlane)workPart.Datums.FindObject("DATUM_CSYS(0) YZ plane");
        NXOpen.Point3d    point1      = new NXOpen.Point3d(0, 0, 0);
        sketchInPlaceBuilder1.PlaneOrFace.SetValue(datumPlane1, workPart.ModelingViews.WorkView, point1);

        NXOpen.Features.DatumCsys datumCsys1 = (NXOpen.Features.DatumCsys)workPart.Features.FindObject("DATUM_CSYS(0)");
        NXOpen.Point point2 = (NXOpen.Point)datumCsys1.FindObject("POINT 1");
        sketchInPlaceBuilder1.SketchOrigin = point2;

        sketchInPlaceBuilder1.PlaneOrFace.Value = null;

        sketchInPlaceBuilder1.PlaneOrFace.Value = datumPlane1;

        NXOpen.DatumAxis datumAxis1 = (NXOpen.DatumAxis)workPart.Datums.FindObject("DATUM_CSYS(0) X axis");
        sketchInPlaceBuilder1.Axis.Value = datumAxis1;

        theSession.Preferences.Sketch.CreateInferredConstraints = true;

        theSession.Preferences.Sketch.ContinuousAutoDimensioning = true;

        theSession.Preferences.Sketch.DimensionLabel = NXOpen.Preferences.SketchPreferences.DimensionLabelType.Expression;

        theSession.Preferences.Sketch.TextSizeFixed = true;

        theSession.Preferences.Sketch.FixedTextSize = 3.0;

        theSession.Preferences.Sketch.ConstraintSymbolSize = 3.0;

        theSession.Preferences.Sketch.DisplayObjectColor = false;

        theSession.Preferences.Sketch.DisplayObjectName = true;

        NXOpen.NXObject nXObject2;
        nXObject2 = sketchInPlaceBuilder1.Commit();

        NXOpen.Sketch           sketch1 = (NXOpen.Sketch)nXObject2;
        NXOpen.Features.Feature feature1;
        feature1 = sketch1.Feature;

        sketch1.Activate(NXOpen.Sketch.ViewReorient.True);

        sketchInPlaceBuilder1.Destroy();

        sketchAlongPathBuilder1.Destroy();

        try
        {
            // Expression is still in use.
            workPart.Expressions.Delete(expression2);
        }
        catch (NXException ex)
        {
            ex.AssertErrorCode(1050029);
        }

        try
        {
            // Expression is still in use.
            workPart.Expressions.Delete(expression1);
        }
        catch (NXException ex)
        {
            ex.AssertErrorCode(1050029);
        }

        // ----------------------------------------------
        //   Menu: Insert->Sketch Curve->Line...
        // ----------------------------------------------
        NXOpen.Point3d startPoint1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
        NXOpen.Point3d endPoint1   = new NXOpen.Point3d(0, b, 0.0);
        NXOpen.Line    line1;
        line1 = workPart.Curves.CreateLine(startPoint1, endPoint1);

        theSession.ActiveSketch.AddGeometry(line1, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        //

        NXOpen.Point3d startPoint2 = new NXOpen.Point3d(0.0, b, 0.0);
        NXOpen.Point3d endPoint2   = new NXOpen.Point3d(L, a, 0.0);
        NXOpen.Line    line2;
        line2 = workPart.Curves.CreateLine(startPoint2, endPoint2);

        theSession.ActiveSketch.AddGeometry(line2, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------

        NXOpen.Point3d startPoint3 = new NXOpen.Point3d(L, a, 0.0);
        NXOpen.Point3d endPoint3   = new NXOpen.Point3d(L, 0.0, 0.0);
        NXOpen.Line    line3;
        line3 = workPart.Curves.CreateLine(startPoint3, endPoint3);

        theSession.ActiveSketch.AddGeometry(line3, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------
        NXOpen.Point3d startPoint4 = new NXOpen.Point3d(L, 0.0, 0.0);
        NXOpen.Point3d endPoint4   = new NXOpen.Point3d(0.0, 0.0, 0.0);
        NXOpen.Line    line4;
        line4 = workPart.Curves.CreateLine(startPoint4, endPoint4);

        theSession.ActiveSketch.AddGeometry(line4, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        // ----------------------------------------------
        //   Dialog Begin Line
        // ----------------------------------------------
        // ----------------------------------------------
        //   Menu: File->Finish Sketch
        // ----------------------------------------------
        theSession.ActiveSketch.Deactivate(NXOpen.Sketch.ViewReorient.False, NXOpen.Sketch.UpdateLevel.Model);

        // ----------------------------------------------
        //   Menu: Insert->Design Feature->Extrude...
        // ----------------------------------------------

        NXOpen.Features.Feature nullNXOpen_Features_Feature = null;

        if (!workPart.Preferences.Modeling.GetHistoryMode())
        {
            throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
        }

        NXOpen.Features.ExtrudeBuilder extrudeBuilder1;
        extrudeBuilder1 = workPart.Features.CreateExtrudeBuilder(nullNXOpen_Features_Feature);

        NXOpen.Section section1;
        section1 = workPart.Sections.CreateSection(0.0095, 0.01, 0.5);

        extrudeBuilder1.Section = section1;

        extrudeBuilder1.AllowSelfIntersectingSection(true);

        NXOpen.Unit unit2;
        unit2 = extrudeBuilder1.Draft.FrontDraftAngle.Units;

        NXOpen.Expression expression7;
        expression7 = workPart.Expressions.CreateSystemExpressionWithUnits("2.00", unit2);

        extrudeBuilder1.DistanceTolerance = 0.01;

        extrudeBuilder1.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;

        NXOpen.Body[] targetBodies1   = new NXOpen.Body[1];
        NXOpen.Body   nullNXOpen_Body = null;
        targetBodies1[0] = nullNXOpen_Body;
        extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies1);

        extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = "0";

        extrudeBuilder1.Limits.EndExtend.Value.RightHandSide = t.ToString();

        extrudeBuilder1.Offset.StartOffset.RightHandSide = "0";

        extrudeBuilder1.Offset.EndOffset.RightHandSide = "5";


        NXOpen.GeometricUtilities.SmartVolumeProfileBuilder smartVolumeProfileBuilder1;
        smartVolumeProfileBuilder1 = extrudeBuilder1.SmartVolumeProfile;

        smartVolumeProfileBuilder1.OpenProfileSmartVolumeOption = false;

        smartVolumeProfileBuilder1.CloseProfileRule = NXOpen.GeometricUtilities.SmartVolumeProfileBuilder.CloseProfileRuleType.Fci;

        section1.DistanceTolerance = 0.01;

        section1.ChainingTolerance = 0.0095;

        section1.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);

        NXOpen.Features.Feature[]     features1      = new NXOpen.Features.Feature[1];
        NXOpen.Features.SketchFeature sketchFeature1 = (NXOpen.Features.SketchFeature)feature1;
        features1[0] = sketchFeature1;
        NXOpen.CurveFeatureRule curveFeatureRule1;
        curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1);

        section1.AllowSelfIntersection(true);

        NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
        rules1[0] = curveFeatureRule1;
        NXOpen.Point3d helpPoint1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
        section1.AddToSection(rules1, null, null, null, helpPoint1, NXOpen.Section.Mode.Create, false);

        NXOpen.Direction direction1;
        direction1 = workPart.Directions.CreateDirection(sketch1, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling);

        extrudeBuilder1.Direction = direction1;

        extrudeBuilder1.ParentFeatureInternal = false;

        NXOpen.Features.Feature feature2;
        feature2 = extrudeBuilder1.CommitFeature();

        NXOpen.Expression expression8 = extrudeBuilder1.Limits.StartExtend.Value;
        NXOpen.Expression expression9 = extrudeBuilder1.Limits.EndExtend.Value;
        extrudeBuilder1.Destroy();

        workPart.Expressions.Delete(expression7);

        // ----------------------------------------------
        //   Menu: Tools->Journal->Stop Recording
        // ----------------------------------------------
        // ----------------------------------------------
        //   Menu: File->Export->IGES...
        // ----------------------------------------------

        NXOpen.IgesCreator igesCreator1;
        igesCreator1 = theSession.DexManager.CreateIgesCreator();

        igesCreator1.ExportModelData = true;

        igesCreator1.ExportDrawings = true;

        igesCreator1.MapTabCylToBSurf = true;

        igesCreator1.BcurveTol = 0.0508;

        igesCreator1.IdenticalPointResolution = 0.001;

        igesCreator1.MaxThreeDMdlSpace = 10000.0;

        igesCreator1.ObjectTypes.Curves = true;

        igesCreator1.ObjectTypes.Surfaces = true;

        igesCreator1.ObjectTypes.Annotations = true;

        igesCreator1.ObjectTypes.Structures = true;

        igesCreator1.ObjectTypes.Solids = true;

        igesCreator1.SettingsFile = "C:\\Program Files\\Siemens\\NX 10.0\\iges\\igesexport.def";

        igesCreator1.MaxLineThickness = 2.0;

        igesCreator1.SysDefmaxThreeDMdlSpace = true;

        igesCreator1.SysDefidenticalPointResolution = true;

        igesCreator1.InputFile = "J:\\ME 578 Systems\\Midterm\\MidtermProject\\GoldBeam.igs";

        igesCreator1.OutputFile = "J:\\ME 578 Systems\\Midterm\\MidtermProject\\GoldBeam.igs";

        igesCreator1.FileSaveFlag = false;

        igesCreator1.LayerMask = "1-256";

        igesCreator1.DrawingList = "";

        NXOpen.TaggedObject[] objects1 = new NXOpen.TaggedObject[0];
        igesCreator1.SetDrawingArray(objects1);

        NXOpen.NXObject nXObject20;
        nXObject20 = igesCreator1.Commit();

        igesCreator1.Destroy();

        while (!System.IO.File.Exists("J:\\ME 578 Systems\\Midterm\\MidtermProject\\GoldBeam.igs"))
        {
            System.Threading.Thread.Sleep(10);
        }
    }
Exemplo n.º 7
0
    public Sketch SketchCreation(Part workPart, Session theSession, Point3d point3d, DatumAxis axis, DatumPlane plane, NXOpen.Features.DatumCsys Csys)
    {
        Sketch nullSketch = null;
        SketchInPlaceBuilder sketchInPlaceBuilder1;

        sketchInPlaceBuilder1 = workPart.Sketches.CreateNewSketchInPlaceBuilder(nullSketch);

        SketchAlongPathBuilder sketchAlongPathBuilder1;

        sketchAlongPathBuilder1 = workPart.Sketches.CreateSketchAlongPathBuilder(nullSketch);

        Point point = workPart.Points.CreatePoint(point3d);

        sketchInPlaceBuilder1.SketchOrigin = point;

        sketchInPlaceBuilder1.PlaneOrFace.Value = plane;

        sketchInPlaceBuilder1.Axis.Value = axis;

        NXObject nXObject1;

        nXObject1 = sketchInPlaceBuilder1.Commit();

        Sketch sketch1 = (Sketch)nXObject1;

        NXOpen.Features.Feature feature1;
        feature1 = sketch1.Feature;

        sketch1.Activate(NXOpen.Sketch.ViewReorient.False);

        sketchInPlaceBuilder1.Destroy();

        sketchAlongPathBuilder1.Destroy();

        return(sketch1);
    }
Exemplo n.º 8
0
    public static void Main(string[] args)
    {
        Console.WriteLine("Starting NX Journal");

        //Declare Part Variables
        //Convert Strings to doubles from the args
        double length    = System.Convert.ToDouble(args[0]);
        double width     = System.Convert.ToDouble(args[1]);
        double height    = System.Convert.ToDouble(args[2]);
        string part_name = args[3];

        //Measurements need to be converted from m to mm
        length = 1000 * length;
        width  = 1000 * width;
        height = 1000 * height;


        //Convert necessary values to string.
        string length_string = System.Convert.ToString(length);
        string width_string  = System.Convert.ToString(width);
        string height_string = System.Convert.ToString(height);


        Session theSession = Session.GetSession();

        // ----------------------------------------------
        //   Menu: File->New...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId1;
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        FileNew fileNew1;

        fileNew1 = theSession.Parts.FileNew();

        theSession.SetUndoMarkName(markId1, "New Dialog");

        NXOpen.Session.UndoMarkId markId2;
        markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "New");

        theSession.DeleteUndoMark(markId2, null);

        NXOpen.Session.UndoMarkId markId3;
        markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "New");

        fileNew1.TemplateFileName = "model-plain-1-mm-template.prt";

        fileNew1.ApplicationName = "ModelTemplate";

        fileNew1.Units = NXOpen.Part.Units.Millimeters;

        fileNew1.RelationType = "";

        fileNew1.UsesMasterModel = "No";

        fileNew1.TemplateType = FileNewTemplateType.Item;

        fileNew1.NewFileName = part_name;

        fileNew1.MasterFileName = "";

        fileNew1.UseBlankTemplate = false;

        fileNew1.MakeDisplayedPart = true;

        NXObject nXObject1;

        nXObject1 = fileNew1.Commit();

        Part workPart    = theSession.Parts.Work;
        Part displayPart = theSession.Parts.Display;

        theSession.DeleteUndoMark(markId3, null);

        fileNew1.Destroy();

        NXOpen.Session.UndoMarkId markId4;
        markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Enter Modeling");

        // ----------------------------------------------
        //   Menu: Insert->Sketch...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId5;
        markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        Sketch nullSketch = null;
        SketchInPlaceBuilder sketchInPlaceBuilder1;

        sketchInPlaceBuilder1 = workPart.Sketches.CreateNewSketchInPlaceBuilder(nullSketch);

        Unit       unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter");
        Expression expression1;

        expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

        Expression expression2;

        expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

        SketchAlongPathBuilder sketchAlongPathBuilder1;

        sketchAlongPathBuilder1 = workPart.Sketches.CreateSketchAlongPathBuilder(nullSketch);

        sketchAlongPathBuilder1.PlaneLocation.Expression.RightHandSide = "0";

        theSession.SetUndoMarkName(markId5, "Create Sketch Dialog");

        DatumPlane datumPlane1 = (DatumPlane)workPart.Datums.FindObject("DATUM_CSYS(0) XY plane");
        Point3d    point1      = new Point3d(26.3626531592029, 1.06581410364015e-014, 30.438226401797);

        sketchInPlaceBuilder1.PlaneOrFace.SetValue(datumPlane1, workPart.ModelingViews.WorkView, point1);

        NXOpen.Features.DatumCsys datumCsys1 = (NXOpen.Features.DatumCsys)workPart.Features.FindObject("DATUM_CSYS(0)");
        Point point2 = (Point)datumCsys1.FindObject("POINT 1");

        sketchInPlaceBuilder1.SketchOrigin = point2;

        sketchInPlaceBuilder1.PlaneOrFace.Value = null;

        sketchInPlaceBuilder1.PlaneOrFace.Value = datumPlane1;

        sketchInPlaceBuilder1.ReversePlaneNormal = true;

        DatumAxis datumAxis1 = (DatumAxis)workPart.Datums.FindObject("DATUM_CSYS(0) X axis");

        sketchInPlaceBuilder1.Axis.Value = datumAxis1;

        NXOpen.Session.UndoMarkId markId6;
        markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Create Sketch");

        theSession.DeleteUndoMark(markId6, null);

        NXOpen.Session.UndoMarkId markId7;
        markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Create Sketch");

        theSession.Preferences.Sketch.CreateInferredConstraints = true;

        theSession.Preferences.Sketch.ContinuousAutoDimensioning = true;

        theSession.Preferences.Sketch.DimensionLabel = NXOpen.Preferences.SketchPreferences.DimensionLabelType.Expression;

        theSession.Preferences.Sketch.TextSizeFixed = true;

        theSession.Preferences.Sketch.FixedTextSize = 3.0;

        theSession.Preferences.Sketch.ConstraintSymbolSize = 3.0;

        theSession.Preferences.Sketch.DisplayObjectColor = false;

        theSession.Preferences.Sketch.DisplayObjectName = true;

        NXObject nXObject2;

        nXObject2 = sketchInPlaceBuilder1.Commit();

        Sketch sketch1 = (Sketch)nXObject2;

        NXOpen.Features.Feature feature1;
        feature1 = sketch1.Feature;

        NXOpen.Session.UndoMarkId markId8;
        markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "update");

        int nErrs1;

        nErrs1 = theSession.UpdateManager.DoUpdate(markId8);

        sketch1.Activate(NXOpen.Sketch.ViewReorient.True);

        theSession.DeleteUndoMark(markId7, null);

        theSession.SetUndoMarkName(markId5, "Create Sketch");

        sketchInPlaceBuilder1.Destroy();

        sketchAlongPathBuilder1.Destroy();

        try
        {
            // Expression is still in use.
            workPart.Expressions.Delete(expression2);
        }
        catch (NXException ex)
        {
            ex.AssertErrorCode(1050029);
        }

        try
        {
            // Expression is still in use.
            workPart.Expressions.Delete(expression1);
        }
        catch (NXException ex)
        {
            ex.AssertErrorCode(1050029);
        }

        // ----------------------------------------------
        //   Menu: Insert->Sketch Curve->Rectangle...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId9;
        markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Profile short list");

        NXOpen.Session.UndoMarkId markId10;
        markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Create Rectangle");

        Expression expression3;

        expression3 = workPart.Expressions.CreateSystemExpression(width_string);

        theSession.SetUndoMarkVisibility(markId10, "Create Rectangle", NXOpen.Session.MarkVisibility.Visible);

        // ----------------------------------------------
        // Creating rectangle using By 2 Points method
        // ----------------------------------------------
        Point3d startPoint1 = new Point3d(0.0, 0.0, 0.0);
        Point3d endPoint1   = new Point3d(width, 0.0, 0.0);
        Line    line1;

        line1 = workPart.Curves.CreateLine(startPoint1, endPoint1);

        Point3d startPoint2 = new Point3d(width, 0.0, 0.0);
        Point3d endPoint2   = new Point3d(width, 0.0, height);
        Line    line2;

        line2 = workPart.Curves.CreateLine(startPoint2, endPoint2);

        Point3d startPoint3 = new Point3d(width, 0.0, height);
        Point3d endPoint3   = new Point3d(0.0, 0.0, height);
        Line    line3;

        line3 = workPart.Curves.CreateLine(startPoint3, endPoint3);

        Point3d startPoint4 = new Point3d(0.0, 0.0, height);
        Point3d endPoint4   = new Point3d(0.0, 0.0, 0.0);
        Line    line4;

        line4 = workPart.Curves.CreateLine(startPoint4, endPoint4);

        theSession.ActiveSketch.AddGeometry(line1, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        theSession.ActiveSketch.AddGeometry(line2, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        theSession.ActiveSketch.AddGeometry(line3, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        theSession.ActiveSketch.AddGeometry(line4, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        NXOpen.Sketch.ConstraintGeometry geom1_1;
        geom1_1.Geometry  = line1;
        geom1_1.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_1.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_1;
        geom2_1.Geometry  = line2;
        geom2_1.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_1.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint1;

        sketchGeometricConstraint1 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_1, geom2_1);

        NXOpen.Sketch.ConstraintGeometry geom1_2;
        geom1_2.Geometry  = line2;
        geom1_2.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_2.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_2;
        geom2_2.Geometry  = line3;
        geom2_2.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_2.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint2;

        sketchGeometricConstraint2 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_2, geom2_2);

        NXOpen.Sketch.ConstraintGeometry geom1_3;
        geom1_3.Geometry  = line3;
        geom1_3.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_3.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_3;
        geom2_3.Geometry  = line4;
        geom2_3.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_3.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint3;

        sketchGeometricConstraint3 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_3, geom2_3);

        NXOpen.Sketch.ConstraintGeometry geom1_4;
        geom1_4.Geometry  = line4;
        geom1_4.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_4.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_4;
        geom2_4.Geometry  = line1;
        geom2_4.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_4.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint4;

        sketchGeometricConstraint4 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_4, geom2_4);

        NXOpen.Sketch.ConstraintGeometry geom1;
        geom1.Geometry  = line1;
        geom1.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom1.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint5;

        sketchGeometricConstraint5 = theSession.ActiveSketch.CreateHorizontalConstraint(geom1);

        NXOpen.Sketch.ConstraintGeometry conGeom1_1;
        conGeom1_1.Geometry  = line1;
        conGeom1_1.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom1_1.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry conGeom2_1;
        conGeom2_1.Geometry  = line2;
        conGeom2_1.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom2_1.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint6;

        sketchGeometricConstraint6 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_1, conGeom2_1);

        NXOpen.Sketch.ConstraintGeometry conGeom1_2;
        conGeom1_2.Geometry  = line2;
        conGeom1_2.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom1_2.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry conGeom2_2;
        conGeom2_2.Geometry  = line3;
        conGeom2_2.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom2_2.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint7;

        sketchGeometricConstraint7 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_2, conGeom2_2);

        NXOpen.Sketch.ConstraintGeometry conGeom1_3;
        conGeom1_3.Geometry  = line3;
        conGeom1_3.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom1_3.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry conGeom2_3;
        conGeom2_3.Geometry  = line4;
        conGeom2_3.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom2_3.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint8;

        sketchGeometricConstraint8 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_3, conGeom2_3);

        NXOpen.Sketch.ConstraintGeometry conGeom1_4;
        conGeom1_4.Geometry  = line4;
        conGeom1_4.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom1_4.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry conGeom2_4;
        conGeom2_4.Geometry  = line1;
        conGeom2_4.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom2_4.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint9;

        sketchGeometricConstraint9 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_4, conGeom2_4);

        NXOpen.Sketch.ConstraintGeometry geom1_5;
        geom1_5.Geometry  = line1;
        geom1_5.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom1_5.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_5;
        geom2_5.Geometry  = point2;
        geom2_5.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom2_5.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint10;

        sketchGeometricConstraint10 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_5, geom2_5);

        NXOpen.Sketch.DimensionGeometry dimObject1_1;
        dimObject1_1.Geometry    = line3;
        dimObject1_1.AssocType   = NXOpen.Sketch.AssocType.StartPoint;
        dimObject1_1.AssocValue  = 0;
        dimObject1_1.HelpPoint.X = 0.0;
        dimObject1_1.HelpPoint.Y = 0.0;
        dimObject1_1.HelpPoint.Z = 0.0;
        NXObject nullNXObject = null;

        dimObject1_1.View = nullNXObject;
        NXOpen.Sketch.DimensionGeometry dimObject2_1;
        dimObject2_1.Geometry    = line3;
        dimObject2_1.AssocType   = NXOpen.Sketch.AssocType.EndPoint;
        dimObject2_1.AssocValue  = 0;
        dimObject2_1.HelpPoint.X = 0.0;
        dimObject2_1.HelpPoint.Y = 0.0;
        dimObject2_1.HelpPoint.Z = 0.0;
        dimObject2_1.View        = nullNXObject;
        Point3d dimOrigin1 = new Point3d(25.0, 0.0, 149.651881900218);
        SketchDimensionalConstraint sketchDimensionalConstraint1;

        sketchDimensionalConstraint1 = theSession.ActiveSketch.CreateDimension(NXOpen.Sketch.ConstraintType.ParallelDim, dimObject1_1, dimObject2_1, dimOrigin1, expression3, NXOpen.Sketch.DimensionOption.CreateAsDriving);

        SketchHelpedDimensionalConstraint sketchHelpedDimensionalConstraint1 = (SketchHelpedDimensionalConstraint)sketchDimensionalConstraint1;

        NXOpen.Annotations.Dimension dimension1;
        dimension1 = sketchHelpedDimensionalConstraint1.AssociatedDimension;

        NXOpen.Sketch.DimensionGeometry dimObject1_2;
        dimObject1_2.Geometry    = line2;
        dimObject1_2.AssocType   = NXOpen.Sketch.AssocType.StartPoint;
        dimObject1_2.AssocValue  = 0;
        dimObject1_2.HelpPoint.X = 0.0;
        dimObject1_2.HelpPoint.Y = 0.0;
        dimObject1_2.HelpPoint.Z = 0.0;
        dimObject1_2.View        = nullNXObject;
        NXOpen.Sketch.DimensionGeometry dimObject2_2;
        dimObject2_2.Geometry    = line2;
        dimObject2_2.AssocType   = NXOpen.Sketch.AssocType.EndPoint;
        dimObject2_2.AssocValue  = 0;
        dimObject2_2.HelpPoint.X = 0.0;
        dimObject2_2.HelpPoint.Y = 0.0;
        dimObject2_2.HelpPoint.Z = 0.0;
        dimObject2_2.View        = nullNXObject;
        Point3d    dimOrigin2     = new Point3d(74.651881900218, 0.0, 62.5);
        Expression nullExpression = null;
        SketchDimensionalConstraint sketchDimensionalConstraint2;

        sketchDimensionalConstraint2 = theSession.ActiveSketch.CreateDimension(NXOpen.Sketch.ConstraintType.ParallelDim, dimObject1_2, dimObject2_2, dimOrigin2, nullExpression, NXOpen.Sketch.DimensionOption.CreateAsAutomatic);

        SketchHelpedDimensionalConstraint sketchHelpedDimensionalConstraint2 = (SketchHelpedDimensionalConstraint)sketchDimensionalConstraint2;

        NXOpen.Annotations.Dimension dimension2;
        dimension2 = sketchHelpedDimensionalConstraint2.AssociatedDimension;

        Expression expression4;

        expression4 = sketchHelpedDimensionalConstraint2.AssociatedExpression;

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        SmartObject[] geoms1 = new SmartObject[4];
        geoms1[0] = line1;
        geoms1[1] = line2;
        geoms1[2] = line3;
        geoms1[3] = line4;
        theSession.ActiveSketch.UpdateConstraintDisplay(geoms1);

        SmartObject[] geoms2 = new SmartObject[4];
        geoms2[0] = line1;
        geoms2[1] = line2;
        geoms2[2] = line3;
        geoms2[3] = line4;
        theSession.ActiveSketch.UpdateDimensionDisplay(geoms2);

        // ----------------------------------------------
        //   Menu: File->Finish Sketch
        // ----------------------------------------------
        theSession.ActiveSketch.Deactivate(NXOpen.Sketch.ViewReorient.False, NXOpen.Sketch.UpdateLevel.Model);

        // ----------------------------------------------
        //   Menu: Insert->Design Feature->Extrude...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId11;
        markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        NXOpen.Features.Feature nullFeatures_Feature = null;

        if (!workPart.Preferences.Modeling.GetHistoryMode())
        {
            throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
        }

        NXOpen.Features.ExtrudeBuilder extrudeBuilder1;
        extrudeBuilder1 = workPart.Features.CreateExtrudeBuilder(nullFeatures_Feature);

        Section section1;

        section1 = workPart.Sections.CreateSection(0.0095, 0.01, 0.5);

        extrudeBuilder1.Section = section1;

        extrudeBuilder1.AllowSelfIntersectingSection(true);

        Unit unit2;

        unit2 = extrudeBuilder1.Draft.FrontDraftAngle.Units;

        Expression expression5;

        expression5 = workPart.Expressions.CreateSystemExpressionWithUnits("2.00", unit2);

        extrudeBuilder1.DistanceTolerance = 0.01;

        extrudeBuilder1.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;

        Body[] targetBodies1 = new Body[1];
        Body   nullBody      = null;

        targetBodies1[0] = nullBody;
        extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies1);

        extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = "0";

        extrudeBuilder1.Limits.EndExtend.Value.RightHandSide = "25";

        extrudeBuilder1.Offset.StartOffset.RightHandSide = "0";

        extrudeBuilder1.Offset.EndOffset.RightHandSide = "5";

        extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = "0";

        extrudeBuilder1.Limits.EndExtend.Value.RightHandSide = length_string;

        extrudeBuilder1.Draft.FrontDraftAngle.RightHandSide = "2";

        extrudeBuilder1.Draft.BackDraftAngle.RightHandSide = "2";

        extrudeBuilder1.Offset.StartOffset.RightHandSide = "0";

        extrudeBuilder1.Offset.EndOffset.RightHandSide = "5";

        NXOpen.GeometricUtilities.SmartVolumeProfileBuilder smartVolumeProfileBuilder1;
        smartVolumeProfileBuilder1 = extrudeBuilder1.SmartVolumeProfile;

        smartVolumeProfileBuilder1.OpenProfileSmartVolumeOption = false;

        smartVolumeProfileBuilder1.CloseProfileRule = NXOpen.GeometricUtilities.SmartVolumeProfileBuilder.CloseProfileRuleType.Fci;

        theSession.SetUndoMarkName(markId11, "Extrude Dialog");

        section1.DistanceTolerance = 0.01;

        section1.ChainingTolerance = 0.0095;

        section1.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);

        NXOpen.Session.UndoMarkId markId12;
        markId12 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");

        NXOpen.Session.UndoMarkId markId13;
        markId13 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);

        NXOpen.Features.Feature[]     features1      = new NXOpen.Features.Feature[1];
        NXOpen.Features.SketchFeature sketchFeature1 = (NXOpen.Features.SketchFeature)feature1;
        features1[0] = sketchFeature1;
        CurveFeatureRule curveFeatureRule1;

        curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1);

        section1.AllowSelfIntersection(true);

        SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
        rules1[0] = curveFeatureRule1;
        Point3d helpPoint1 = new Point3d(23.553389477581, 0.0, height);

        section1.AddToSection(rules1, line3, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);

        theSession.DeleteUndoMark(markId13, null);

        Direction direction1;

        direction1 = workPart.Directions.CreateDirection(sketch1, Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling);

        extrudeBuilder1.Direction = direction1;

        theSession.DeleteUndoMark(markId12, null);

        NXOpen.Session.UndoMarkId markId14;
        markId14 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Extrude");

        theSession.DeleteUndoMark(markId14, null);

        NXOpen.Session.UndoMarkId markId15;
        markId15 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Extrude");

        extrudeBuilder1.ParentFeatureInternal = false;

        NXOpen.Features.Feature feature2;
        feature2 = extrudeBuilder1.CommitFeature();

        theSession.DeleteUndoMark(markId15, null);

        theSession.SetUndoMarkName(markId11, "Extrude");

        Expression expression6 = extrudeBuilder1.Limits.StartExtend.Value;
        Expression expression7 = extrudeBuilder1.Limits.EndExtend.Value;

        extrudeBuilder1.Destroy();

        workPart.Expressions.Delete(expression5);

        // ----------------------------------------------
        //   Menu: Analysis->Measure Bodies...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId16;
        markId16 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        MeasureBodyBuilder measureBodyBuilder1;

        measureBodyBuilder1 = workPart.MeasureManager.CreateMeasureBodyBuilder(nullNXObject);

        theSession.SetUndoMarkName(markId16, "Measure Bodies Dialog");

        Body[] bodies1 = new Body[1];
        Body   body1   = (Body)workPart.Bodies.FindObject("EXTRUDE(2)");

        bodies1[0] = body1;
        BodyDumbRule bodyDumbRule1;

        bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies1, true);

        SelectionIntentRule[] rules2 = new SelectionIntentRule[1];
        rules2[0] = bodyDumbRule1;
        measureBodyBuilder1.BodyCollector.ReplaceRules(rules2, false);

        NXOpen.Session.UndoMarkId markId17;
        markId17 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Measure Bodies");

        theSession.DeleteUndoMark(markId17, null);

        NXOpen.Session.UndoMarkId markId18;
        markId18 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Measure Bodies");

        theSession.DeleteUndoMark(markId18, null);

        theSession.SetUndoMarkName(markId16, "Measure Bodies");

        measureBodyBuilder1.Destroy();


        MeasureBodies measureBodies1 = workPart.MeasureManager.NewMassProperties(workPart.UnitCollection.ToArray(), 1.0, bodies1);
        //Console.WriteLine(measureBodies1.Volume);

        // ----------------------------------------------
        //   Menu: File->Save
        // ----------------------------------------------
        PartSaveStatus partSaveStatus1;

        partSaveStatus1 = workPart.Save(NXOpen.BasePart.SaveComponents.True, NXOpen.BasePart.CloseAfterSave.False);

        partSaveStatus1.Dispose();
        // ----------------------------------------------
        //   Menu: Tools->Journal->Stop Recording
        // ----------------------------------------------


        Console.WriteLine("Finishing NX Journal. Part Saved.");

        //Write output file with dimensions of beam in current directory
        File.WriteAllText("Optimum_beam_dimensions.txt",
                          "Volume of Optimal Beam = " + ((measureBodies1.Volume) / 1000000000) + "m^3\r\nLength = 2m" +
                          "\r\nWidth = " + (width / 1000) + "m\r\nHeight = " + (height / 1000) + "m");
        Console.WriteLine("Beam dimensions written to file.");
    }