C# NX二次开发_创建圆柱体并进行编辑

 NXOpen.Part workPart = theSession.Parts.Work;

            NXOpen.NXObject nXObject1 = null;

            do
            {
                NXOpen.Features.CylinderBuilder cylinderBuilder1 = workPart.Features.CreateCylinderBuilder(null);

                cylinderBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;


                NXOpen.Point3d origin1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
                NXOpen.Vector3d vector1 = new NXOpen.Vector3d(1.0, 0.0, 0.0);
                NXOpen.Direction direction1 = workPart.Directions.CreateDirection(origin1, vector1, NXOpen.SmartObject.UpdateOption.WithinModeling);

                cylinderBuilder1.Axis.Direction = direction1;
                cylinderBuilder1.Axis.Point = workPart.Points.CreatePoint(origin1);

                cylinderBuilder1.Diameter.RightHandSide = "50";

                cylinderBuilder1.Height.RightHandSide = "100";

                nXObject1 = cylinderBuilder1.CommitFeature();

                //if (nXObject1 == null)
                //{
                //    nXObject1 = cylinderBuilder1.GetCommittedObjects();
                //}

                cylinderBuilder1.Destroy();
                
            } while (false);

            theUI.NXMessageBox.Show("sd", NXOpen.NXMessageBox.DialogType.Information, "创建成功,下面开始编辑");

            NXOpen.Features.Feature feature = nXObject1 as NXOpen.Features.Feature;//前面是 命名空间,后面的是方法 as是强制类型转换
            
            if (feature != null)
            {

                NXOpen.Features.CylinderBuilder cylinderBuilder1 = workPart.Features.CreateCylinderBuilder(feature);

                cylinderBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;


                NXOpen.Point3d origin1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
                NXOpen.Vector3d vector1 = new NXOpen.Vector3d(0.0, 1.0, 0.0);
                NXOpen.Direction direction1 = workPart.Directions.CreateDirection(origin1, vector1, NXOpen.SmartObject.UpdateOption.WithinModeling);

                cylinderBuilder1.Axis.Direction = direction1;
                cylinderBuilder1.Axis.Point = workPart.Points.CreatePoint(origin1);

                cylinderBuilder1.Diameter.RightHandSide = "100";

                cylinderBuilder1.Height.RightHandSide = "50";

                nXObject1 = cylinderBuilder1.CommitFeature();

                cylinderBuilder1.Destroy();

                theSession.UpdateManager.InterpartDelay = false;

                workPart.Features.SetEditWithRollbackFeature(null);


            }

            NXOpen.UF.UFSession.GetUFSession().Modl.Update();

 

你可能感兴趣的:(NX二次开发)