public DatumAxis DatumAxisCreation(Part workPart, Point3d first3d, Point3d second3d) { //Tworzenie "buildera dla osi Y". NXOpen.Features.Feature nullFeatures_Feature = null; NXOpen.Features.DatumAxisBuilder datumAxisBuilder; datumAxisBuilder = workPart.Features.CreateDatumAxisBuilder(nullFeatures_Feature); datumAxisBuilder.IsAssociative = true; datumAxisBuilder.Type = NXOpen.Features.DatumAxisBuilder.Types.TwoPoints; datumAxisBuilder.ResizedEndDistance = 0.0; Point first = workPart.Points.CreatePoint(first3d); Point second = workPart.Points.CreatePoint(second3d); datumAxisBuilder.Point1 = first; datumAxisBuilder.Point2 = second; NXObject vector = datumAxisBuilder.Commit(); string journalName = vector.JournalIdentifier.ToString(); DatumAxis datumAxis = (DatumAxis)workPart.Datums.FindObject(journalName); datumAxisBuilder.Destroy(); return(datumAxis); }
//------------------------------------------------------------------------------ //Callback Name: apply_cb //------------------------------------------------------------------------------ public int apply_cb() { int errorCode = 0; try { firstpt = point0.GetProperties().GetTaggedObjectVector("SelectedObjects"); secpt = point01.GetProperties().GetTaggedObjectVector("SelectedObjects"); Point a = Tag2NXObject <Point>(firstpt[0].Tag); Point b = Tag2NXObject <Point>(secpt[0].Tag); NXObject axisyo = shank(a, b); double[] real3d; NXOpen.Features.DatumAxisFeature axisreal = (NXOpen.Features.DatumAxisFeature)axisyo; DatumAxis axisreal1 = axisreal.DatumAxis; Point3d stpt; //轴的起点 Point3d endpt; //轴的终点 stpt = a.Coordinates; endpt = b.Coordinates; // axisreal1.GetEndPoints(out stpt, out endpt); hideit(axisreal1); real3d = angle(axisreal1); thepmi = selection0.GetProperties().GetTaggedObjectVector("SelectedObjects"); NXObject last = Tag2NXObject <NXObject>(thepmi[0].Tag); NXOpen.Annotations.Dimension lastdimn = (NXOpen.Annotations.Dimension)last; double m = lastdimn.ComputedSize; double cosx = Math.Cos(ConvertDegreesToRadians(real3d[0])); double cosy = Math.Cos(ConvertDegreesToRadians(real3d[1])); double cosz = Math.Cos(ConvertDegreesToRadians(real3d[2])); double cosxx = cosx * m; double cosyy = cosy * m; double coszz = cosz * m; last.SetAttribute("X", cosxx); last.SetAttribute("Y", cosyy); last.SetAttribute("Z", coszz); last.SetAttribute("START-X", stpt.X); last.SetAttribute("START-Y", stpt.Y); last.SetAttribute("START-Z", stpt.Z); last.SetAttribute("END-X", endpt.X); last.SetAttribute("END-Y", endpt.Y); last.SetAttribute("END-Z", endpt.Z); //---- Enter your callback code here ----- } catch (Exception ex) { //---- Enter your exception handling code here ----- errorCode = 1; theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return(errorCode); }
public double[] angle(DatumAxis axis) { double[] angle3d = { 0, 0, 0 }; Part workPart = theSession.Parts.Work; NXObject nullNXObject = null; MeasureAngleBuilder bbuilder; bbuilder = workPart.MeasureManager.CreateMeasureAngleBuilder(nullNXObject); DatumAxis a = (DatumAxis)axis; bbuilder.Object1.Value = a; DatumAxis b = (DatumAxis)workPart.Datums.FindObject("DATUM_CSYS(0) X axis"); bbuilder.Object2.Value = b; // NXObject f = bbuilder.Commit(); Unit nullUnit = null; MeasureAngle measureAngle1; measureAngle1 = workPart.MeasureManager.NewAngle(nullUnit, a, NXOpen.MeasureManager.EndpointType.StartPoint, b, NXOpen.MeasureManager.EndpointType.StartPoint, true, false); double deg = measureAngle1.Value; DatumAxis b1 = (DatumAxis)workPart.Datums.FindObject("DATUM_CSYS(0) Y axis"); DatumAxis b2 = (DatumAxis)workPart.Datums.FindObject("DATUM_CSYS(0) Z axis"); bbuilder.Object2.Value = b1; Unit nullUnit1 = null; MeasureAngle measureAngle2; measureAngle2 = workPart.MeasureManager.NewAngle(nullUnit1, a, NXOpen.MeasureManager.EndpointType.StartPoint, b1, NXOpen.MeasureManager.EndpointType.StartPoint, true, false); double deg1 = measureAngle2.Value; bbuilder.Object2.Value = b2; Unit nullUnit11 = null; MeasureAngle measureAngle3; measureAngle3 = workPart.MeasureManager.NewAngle(nullUnit11, a, NXOpen.MeasureManager.EndpointType.StartPoint, b2, NXOpen.MeasureManager.EndpointType.StartPoint, true, false); double deg2 = measureAngle3.Value; angle3d[0] = deg; //deg 是相对与X轴的角度 angle3d[1] = deg1; //相对于Y angle3d[2] = deg2; //相对于Z bbuilder.Destroy(); return(angle3d); //在一个方法中返回一个数组,直接写return +数组名就可以了 }
public DatumPlane DatumPlaneCreation(Part workPart, Point3d point3d, DatumAxis axis) { NXOpen.Features.Feature nullFeatures_Feature = null; NXOpen.Features.DatumPlaneBuilder datumPlaneBuilder1; datumPlaneBuilder1 = workPart.Features.CreateDatumPlaneBuilder(nullFeatures_Feature); Plane plane1; plane1 = datumPlaneBuilder1.GetPlane(); plane1.SetMethod(NXOpen.PlaneTypes.MethodType.PointDir); Point point = workPart.Points.CreatePoint(point3d); NXObject[] geom1 = new NXObject[2]; geom1[0] = point; geom1[1] = axis; plane1.SetGeometry(geom1); plane1.SetAlternate(NXOpen.PlaneTypes.AlternateType.One); plane1.Evaluate(); bool flip1; flip1 = plane1.Flip; NXOpen.Features.Feature feature1; feature1 = datumPlaneBuilder1.CommitFeature(); NXOpen.Features.DatumPlaneFeature datumPlaneFeature1 = (NXOpen.Features.DatumPlaneFeature)feature1; DatumPlane datumPlane1; datumPlane1 = datumPlaneFeature1.DatumPlane; datumPlane1.SetReverseSection(false); datumPlaneBuilder1.Destroy(); return(datumPlane1); }
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); }
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); }
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()); } }
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); }
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."); }