Cancel
Showing results for 
Search instead for 
Did you mean: 

Hole in Extruded Polygon

Builder
Builder

Hello Guys,

Here is a code, First it creates polygon, extrude it and make hole in it.

SO Problem is that I am not able to shift it in X direction.(Ex X=50mm)

 


using System;
using NXOpen;
using NXOpen.Features;


public class NXJournal
{
public static void Main(string[] args)
{
NXOpen.Session theSession = NXOpen.Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
NXOpen.Part displayPart = theSession.Parts.Display;
// ----------------------------------------------
// Menu: Insert->Sketch Curve->Polygon...
// ----------------------------------------------

NXOpen.SketchPolygon nullNXOpen_SketchPolygon = null;
NXOpen.SketchPolygonBuilder sketchPolygonBuilder1;
sketchPolygonBuilder1 = workPart.Sketches.CreateSketchPolygonBuilder(nullNXOpen_SketchPolygon);

sketchPolygonBuilder1.RadiusDimension.RightHandSide = "70";

sketchPolygonBuilder1.LengthDimension.RightHandSide = "100";

sketchPolygonBuilder1.RotationDimension.RightHandSide = "90";


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

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

NXOpen.DatumPlane datumPlane1 = (NXOpen.DatumPlane)workPart.Datums.FindObject("DATUM_CSYS(0) YZ plane");
NXOpen.Features.DatumCsys datumCsys1 = (NXOpen.Features.DatumCsys)workPart.Features.FindObject("DATUM_CSYS(0)");

Point3d origin1 = new Point3d(0, 0, 0);
Point point1;
point1 = workPart.Points.CreatePoint(origin1);
// NXOpen.Point point1 = (NXOpen.Point)datumCsys1.FindObject("POINT 1");
NXOpen.Xform xform1;
xform1 = workPart.Xforms.CreateXformByPlaneXDirPoint(datumPlane1, direction1, point1, NXOpen.SmartObject.UpdateOption.WithinModeling, 0.625, false, false);

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

NXOpen.Features.Feature nullNXOpen_Features_Feature = null;
NXOpen.Features.DatumCsysBuilder datumCsysBuilder1;
datumCsysBuilder1 = workPart.Features.CreateDatumCsysBuilder(nullNXOpen_Features_Feature);

datumCsysBuilder1.Csys = cartesianCoordinateSystem1;

datumCsysBuilder1.DisplayScaleFactor = 1.25;

NXOpen.Features.Feature feature1;
feature1 = datumCsysBuilder1.CommitFeature();

datumCsysBuilder1.Destroy();

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

sketchInPlaceBuilder1.Csystem = cartesianCoordinateSystem1;

sketchInPlaceBuilder1.PlaneOption = NXOpen.Sketch.PlaneOption.Inferred;

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

sketchInPlaceBuilder1.Destroy();

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

NXOpen.Features.DatumCsys datumCsys2 = (NXOpen.Features.DatumCsys)feature1;
// NXOpen.Point point2 = (NXOpen.Point)datumCsys2.FindObject("POINT 1");
Point3d origin2 = new Point3d(0.0, 0, 0);
Point point2;
point2 = workPart.Points.CreatePoint(origin2);
NXOpen.Xform nullNXOpen_Xform = null;
NXOpen.Point point3;
point3 = workPart.Points.CreatePoint(point2, nullNXOpen_Xform, NXOpen.SmartObject.UpdateOption.WithinModeling);

sketchPolygonBuilder1.CenterPoint = point3;
point3.RemoveParameters();

NXOpen.Point3d coordinates1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
point3.SetCoordinates(coordinates1);

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

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

theSession.ActiveSketch.Update();

sketchPolygonBuilder1.Destroy();

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

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

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

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

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

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

extrudeBuilder1.Section = section1;

extrudeBuilder1.AllowSelfIntersectingSection(true);


NXOpen.Features.Feature[] features1 = new NXOpen.Features.Feature[1];

features1[0] = sketch2.Feature;
NXOpen.CurveFeatureRule curveFeatureRule1;
curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1);

section1.AllowSelfIntersection(true);

NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
rules1[0] = curveFeatureRule1;


NXObject[] geoms = sketch2.GetAllGeometry();
NXObject nx=geoms[0];
NXOpen.NXObject nullNXOpen_NXObject = null;
NXOpen.Point3d helpPoint1 = new NXOpen.Point3d(0,0,0);

section1.AddToSection(rules1, nx, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1, NXOpen.Section.Mode.Create, false);

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

extrudeBuilder1.Direction = direction2;

extrudeBuilder1.ParentFeatureInternal = false;

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

 

NXOpen.Features.HolePackageBuilder holePackageBuilder1 = workPart.Features.CreateHolePackageBuilder(null);
holePackageBuilder1.Type = NXOpen.Features.HolePackageBuilder.Types.GeneralHole;
holePackageBuilder1.GeneralSimpleHoleDiameter.RightHandSide = "50";
holePackageBuilder1.HoleDepthLimitOption = NXOpen.Features.HolePackageBuilder.HoleDepthLimitOptions.ThroughBody;

holePackageBuilder1.Tolerance = 0.01;
holePackageBuilder1.HolePosition.DistanceTolerance = 0.01;

NXOpen.Body[] targetBodies3 = new NXOpen.Body[1];


NXOpen.Features.BodyFeature Cyl = (NXOpen.Features.BodyFeature)feature2;
// NXOpen.Features.Cylinder Cyl = (NXOpen.Features.Cylinder)cylinder1;
targetBodies3[0] = Cyl.GetBodies()[0];

holePackageBuilder1.BooleanOperation.SetTargetBodies(targetBodies3);
holePackageBuilder1.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Subtract;


Point3d origin3 = new Point3d(100, 0, 0);
Point point21;
point21 = workPart.Points.CreatePoint(origin3);
NXOpen.Point[] points2 = new NXOpen.Point[1];
points2[0] = point21;

NXOpen.CurveDumbRule curveDumbRule1;
curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumbFromPoints(points2);

holePackageBuilder1.HolePosition.AllowSelfIntersection(true);

NXOpen.SelectionIntentRule[] rules2 = new NXOpen.SelectionIntentRule[1];
rules2[0] = curveDumbRule1;


NXObject nullNXObject = null;
Point3d helpPoint2 = new Point3d(0.0, 0.0, 0.0);
holePackageBuilder1.HolePosition.AddToSection(rules2, nullNXObject, nullNXObject, nullNXObject, helpPoint2, NXOpen.Section.Mode.Create, false);


NXObject hole = holePackageBuilder1.Commit();
holePackageBuilder1.Destroy();

}
public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; }
}

2 REPLIES 2
Highlighted

Re: Hole in Extruded Polygon

Experimenter
Experimenter

@Krishna11 

 

If I undertand, you want to change the X coordinate of you hole.

Close to the end of your code is this line: Point3d origin3 = new Point3d(100, 0, 0)

Haven't tested but it seems the coordinates of the point. Try to change 100 to 50

Re: Hole in Extruded Polygon

Builder
Builder
Hello Sir,
That point has been used in a code for locating hole point on the face of the cylinder.

The above problem, that is shifting of polygon, could it be possible by modifying/removing above some of find object method()?