Exemplo n.º 1
0
    public Body Revolve(Part workPart, Axis axisRotation, Sketch sketch, Line lineSketch, Point3d point3dSketch, double degStart, double degEnd)
    {
        //RevolveBulidier
        NXOpen.Features.Feature        nullFeature1    = null;
        NXOpen.Features.RevolveBuilder revolveBuilder1 = workPart.Features.CreateRevolveBuilder(nullFeature1);

        //Section
        Section section1 = workPart.Sections.CreateSection(0.02, 0.02, 0.02);

        revolveBuilder1.Section    = section1;
        revolveBuilder1.Axis       = axisRotation;
        revolveBuilder1.Tolerance  = 0.02;
        section1.DistanceTolerance = 0.02;
        section1.ChainingTolerance = 0.02;

        //Line assignment
        NXOpen.Features.Feature[]     features1      = new NXOpen.Features.Feature[1];
        NXOpen.Features.SketchFeature sketchFeature1 = (NXOpen.Features.SketchFeature)sketch.Feature;
        features1[0] = sketchFeature1;

        CurveFeatureRule curveFeatureRule1;

        curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1);

        section1.AllowSelfIntersection(true);

        SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
        rules1[0] = curveFeatureRule1;
        NXObject nullNXObject = null;

        //Selection
        section1.AddToSection(rules1, lineSketch, nullNXObject, nullNXObject, point3dSketch, NXOpen.Section.Mode.Create, false);

        revolveBuilder1.Axis = axisRotation;

        //Sheet Body selection
        revolveBuilder1.FeatureOptions.BodyType = NXOpen.GeometricUtilities.FeatureOptions.BodyStyle.Sheet;
        revolveBuilder1.Section = section1;

        //Ustawienia
        revolveBuilder1.Limits.StartExtend.Value.RightHandSide = degStart.ToString();
        revolveBuilder1.Limits.EndExtend.Value.RightHandSide   = degEnd.ToString();
        revolveBuilder1.ParentFeatureInternal = false;

        NXObject feature_revolve1 = revolveBuilder1.CommitFeature();

        NXOpen.Features.BodyFeature bodyFeature1 = (NXOpen.Features.BodyFeature)feature_revolve1;
        Body[] body = bodyFeature1.GetBodies();
        return(body[0]);
    }
Exemplo n.º 2
0
    //------------------------------------------------------------------------------
    //Callback Name: apply_cb
    //------------------------------------------------------------------------------
    public int apply_cb()
    {
        int errorCode = 0;

        NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1 = null;

        try
        {
            Part workPart = theSession.Parts.Work;

            //Get the values from UI Blocks
            PropertyList blockHeightProps = blockHeight.GetProperties();
            double       theHeight        = blockHeightProps.GetDouble("Value");
            blockHeightProps.Dispose();
            blockHeightProps = null;

            PropertyList blockWidthProps = blockWidth.GetProperties();
            double       theWidth        = blockWidthProps.GetDouble("Value");
            blockWidthProps.Dispose();
            blockWidthProps = null;

            PropertyList blockLengthProps = blockLength.GetProperties();
            double       theLength        = blockLengthProps.GetDouble("Value");
            blockLengthProps.Dispose();
            blockLengthProps = null;

            PropertyList blockOriginProps = blockOrigin.GetProperties();
            Point3d      originPoint      = blockOriginProps.GetPoint("Point");
            blockOriginProps.Dispose();
            blockOriginProps = null;

            PropertyList blockColorProps = blockColor.GetProperties();
            int[]        color           = blockColorProps.GetIntegerVector("Value");
            blockColorProps.Dispose();
            blockColorProps = null;

            //Create the NX block
            NXOpen.Features.Feature nullFeatures_Feature = null;
            blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature);

            blockFeatureBuilder1.SetOriginAndLengths(originPoint, theLength.ToString(), theHeight.ToString(), theWidth.ToString());

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


            // Get the body from Feature
            NXOpen.Features.BodyFeature bodyFeat = (NXOpen.Features.BodyFeature)feature1;
            Body[] bodies = new Body[1];
            bodies = bodyFeat.GetBodies();
            // Apply the color to feature body
            DisplayModification displayModification1 = theSession.DisplayManager.NewDisplayModification();
            displayModification1.ApplyToAllFaces = true;
            displayModification1.NewColor        = color[0];
            DisplayableObject[] objects1 = new DisplayableObject[1];
            objects1[0] = bodies[0];
            displayModification1.Apply(objects1);
            displayModification1.Dispose();
        }
        catch (Exception ex)
        {
            //---- Enter your exception handling code here -----
            errorCode = 1;
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.Message);
        }
        finally
        {
            if (blockFeatureBuilder1 != null)
            {
                blockFeatureBuilder1.Destroy();
                blockFeatureBuilder1 = null;
            }
        }
        return(errorCode);
    }