Esempio n. 1
0
        /// <summary>
        /// 按点到点移动工件
        /// </summary>
        /// <param name="startPt"></param>
        /// <param name="endPt"></param>
        /// <param name="objs"></param>
        /// <returns></returns>
        public static NXObject MoveObjectOfPointToPoint(Point3d startPt, Point3d endPt, params NXObject[] objs)
        {
            Vector3d direction = UMathUtils.GetVector(endPt, startPt);
            double   value     = UMathUtils.GetDis(startPt, endPt);
            Part     workPart  = Session.GetSession().Parts.Work;

            NXOpen.Features.MoveObject        nullMoveObject    = null;
            NXOpen.Features.MoveObjectBuilder moveObjectBuilder = workPart.BaseFeatures.CreateMoveObjectBuilder(nullMoveObject);
            bool added = moveObjectBuilder.ObjectToMoveObject.Add(objs);

            moveObjectBuilder.TransformMotion.Option = NXOpen.GeometricUtilities.ModlMotion.Options.Distance;
            Direction distance = workPart.Directions.CreateDirection(startPt, direction, SmartObject.UpdateOption.WithinModeling);

            moveObjectBuilder.TransformMotion.DistanceVector      = distance;
            moveObjectBuilder.TransformMotion.DistanceValue.Value = value;
            try
            {
                return(moveObjectBuilder.Commit());
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("Basic.MoveObject.MoveObjectOfCsys:错误:" + ex.Message);
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// 绕轴旋转
        /// </summary>
        /// <param name="direction"></param>
        /// <param name="value"></param>
        /// <param name="objs"></param>
        /// <returns></returns>
        public static NXObject MoveObjectOfRotate(Vector3d direction, double value, params NXObject[] objs)
        {
            Part workPart = Session.GetSession().Parts.Work;

            NXOpen.Features.MoveObject nullMoveObject = null;
            Point nullNXOpen_Point = null;

            NXOpen.Features.MoveObjectBuilder moveObjectBuilder = workPart.BaseFeatures.CreateMoveObjectBuilder(nullMoveObject);
            bool added = moveObjectBuilder.ObjectToMoveObject.Add(objs);

            moveObjectBuilder.TransformMotion.Option = NXOpen.GeometricUtilities.ModlMotion.Options.Angle;
            Direction distance = workPart.Directions.CreateDirection(new Point3d(0, 0, 0), direction, SmartObject.UpdateOption.WithinModeling);
            Axis      axis     = workPart.Axes.CreateAxis(nullNXOpen_Point, distance, SmartObject.UpdateOption.WithinModeling);

            moveObjectBuilder.TransformMotion.DistanceVector = distance;
            moveObjectBuilder.TransformMotion.AngularAxis    = axis;
            moveObjectBuilder.TransformMotion.Angle.Value    = value;
            try
            {
                return(moveObjectBuilder.Commit());
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("Basic.MoveObject.MoveObjectOfCsys:错误:" + ex.Message);
            }
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// 按坐标到坐标移动工件
        /// </summary>
        /// <param name="csys"></param>
        /// <param name="objs"></param>
        /// <returns></returns>
        public static NXObject MoveObjectOfCsys(CoordinateSystem csys, params NXObject[] objs)
        {
            Matrix4 mat = new Matrix4();

            mat.Identity();
            // Point3d originAbs = new Point3d(0, 0, 0);
            Part workPart = Session.GetSession().Parts.Work;
            // CoordinateSystem abs = workPart.CoordinateSystems.CreateCoordinateSystem(originAbs, mat.GetMatrix3(), false);
            CoordinateSystem abs = BoundingBoxUtils.CreateCoordinateSystem(mat, mat.GetInversMatrix());

            NXOpen.Features.MoveObject        nullMoveObject    = null;
            NXOpen.Features.MoveObjectBuilder moveObjectBuilder = workPart.BaseFeatures.CreateMoveObjectBuilder(nullMoveObject);
            bool added = moveObjectBuilder.ObjectToMoveObject.Add(objs);

            moveObjectBuilder.TransformMotion.Option   = NXOpen.GeometricUtilities.ModlMotion.Options.CsysToCsys;
            moveObjectBuilder.TransformMotion.FromCsys = csys;
            moveObjectBuilder.TransformMotion.ToCsys   = abs;
            moveObjectBuilder.Associative = true;
            moveObjectBuilder.MoveParents = false;
            try
            {
                return(moveObjectBuilder.Commit());
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("Basic.MoveObject.MoveObjectOfCsys:错误:" + ex.Message);
                throw ex;
            }
            finally
            {
                moveObjectBuilder.Destroy();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 按坐标到坐标移动工件
        /// </summary>
        /// <param name="csys"></param>
        /// <param name="objs"></param>
        /// <returns></returns>
        public static NXObject MoveObjectOfCsys(CoordinateSystem csys, params NXObject[] objs)
        {
            Matrix4 mat = new Matrix4();

            mat.Identity();
            Point3d          originAbs = new Point3d(0, 0, 0);
            Part             workPart  = Session.GetSession().Parts.Work;
            CoordinateSystem abs       = workPart.CoordinateSystems.CreateCoordinateSystem(originAbs, mat.GetMatrix3(), false);

            NXOpen.Features.MoveObject        nullMoveObject    = null;
            NXOpen.Features.MoveObjectBuilder moveObjectBuilder = workPart.BaseFeatures.CreateMoveObjectBuilder(nullMoveObject);
            bool added = moveObjectBuilder.ObjectToMoveObject.Add(objs);

            moveObjectBuilder.TransformMotion.Option   = NXOpen.GeometricUtilities.ModlMotion.Options.CsysToCsys;
            moveObjectBuilder.TransformMotion.FromCsys = csys;
            moveObjectBuilder.TransformMotion.ToCsys   = abs;
            try
            {
                return(moveObjectBuilder.Commit());
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("Basic.MoveObject.MoveObjectOfCsys:错误:" + ex.Message);
            }
            return(null);
        }
Esempio n. 5
0
    public Body RotationBodyAboutAxis(Part workPart, Body body, Axis axisOfRotation, double angleOfRotation)
    {
        System.Globalization.CultureInfo USculture = new System.Globalization.CultureInfo("en-US");

        NXOpen.Features.MoveObject        nullFeatures_MoveObject = null;
        NXOpen.Features.MoveObjectBuilder moveObjectBuilder11;
        moveObjectBuilder11 = workPart.BaseFeatures.CreateMoveObjectBuilder(nullFeatures_MoveObject);
        NXOpen.GeometricUtilities.OrientXpressBuilder orientXpressBuilder2;
        orientXpressBuilder2             = moveObjectBuilder11.TransformMotion.OrientXpress;
        orientXpressBuilder2.AxisOption  = NXOpen.GeometricUtilities.OrientXpressBuilder.Axis.Passive;
        orientXpressBuilder2.PlaneOption = NXOpen.GeometricUtilities.OrientXpressBuilder.Plane.Passive;
        Point3d manipulatororigin1;

        manipulatororigin1 = moveObjectBuilder11.TransformMotion.ManipulatorOrigin;
        Matrix3x3 manipulatormatrix1;

        manipulatormatrix1 = moveObjectBuilder11.TransformMotion.ManipulatorMatrix;
        moveObjectBuilder11.TransformMotion.Option = NXOpen.GeometricUtilities.ModlMotion.Options.Angle;
        bool added1 = moveObjectBuilder11.ObjectToMoveObject.Add(body);

        moveObjectBuilder11.TransformMotion.AngularAxis = axisOfRotation;
        moveObjectBuilder11.TransformMotion.DistanceValue.RightHandSide = "10";
        moveObjectBuilder11.TransformMotion.Angle.RightHandSide         = angleOfRotation.ToString(USculture);

        NXObject movedpinion1;

        movedpinion1 = moveObjectBuilder11.Commit();
        NXObject[] outBodies = moveObjectBuilder11.GetCommittedObjects();
        moveObjectBuilder11.Destroy();

        Body bodyOut = (Body)outBodies[0];

        return(bodyOut);
    }
Esempio n. 6
0
    public Body MoveBodyAlongVector(Part workPart, Body body, Direction direction, double distance)
    {
        System.Globalization.CultureInfo USculture = new System.Globalization.CultureInfo("en-US");

        NXOpen.Features.MoveObject        nullFeatures_MoveObject = null;
        NXOpen.Features.MoveObjectBuilder moveObjectBuilder1;
        moveObjectBuilder1 = workPart.BaseFeatures.CreateMoveObjectBuilder(nullFeatures_MoveObject);

        moveObjectBuilder1.TransformMotion.DistanceAngle.OrientXpress.AxisOption = NXOpen.GeometricUtilities.OrientXpressBuilder.Axis.Passive;

        moveObjectBuilder1.TransformMotion.DistanceAngle.OrientXpress.PlaneOption = NXOpen.GeometricUtilities.OrientXpressBuilder.Plane.Passive;

        moveObjectBuilder1.TransformMotion.OrientXpress.AxisOption = NXOpen.GeometricUtilities.OrientXpressBuilder.Axis.Passive;

        moveObjectBuilder1.TransformMotion.OrientXpress.PlaneOption = NXOpen.GeometricUtilities.OrientXpressBuilder.Plane.Passive;

        Point3d manipulatororigin1;

        manipulatororigin1 = moveObjectBuilder1.TransformMotion.ManipulatorOrigin;

        Matrix3x3 manipulatormatrix1;

        manipulatormatrix1 = moveObjectBuilder1.TransformMotion.ManipulatorMatrix;

        moveObjectBuilder1.TransformMotion.Option = NXOpen.GeometricUtilities.ModlMotion.Options.Distance;

        moveObjectBuilder1.TransformMotion.DistanceVector = direction;

        bool added1 = moveObjectBuilder1.ObjectToMoveObject.Add(body);

        moveObjectBuilder1.TransformMotion.DistanceValue.RightHandSide = distance.ToString(USculture);

        NXObject nXObject1;

        nXObject1 = moveObjectBuilder1.Commit();

        NXObject[] objects1;
        objects1 = moveObjectBuilder1.GetCommittedObjects();

        Body bodyOut = (Body)objects1[0];

        return(bodyOut);
    }
Esempio n. 7
0
 /// <summary>
 /// 获取特征
 /// </summary>
 /// <param name="model"></param>
 /// <param name="ext"></param>
 /// <param name="move"></param>
 /// <param name="patt"></param>
 private void GetFeature(out NXOpen.Features.ExtractFace ext, out NXOpen.Features.MoveObject move, out NXOpen.Features.PatternGeometry patt)
 {
     ext  = null;
     move = null;
     patt = null;
     foreach (NXOpen.Features.Feature ft in eleModel.PartTag.Features.ToArray())
     {
         if (ft.FeatureType.Equals("LINKED_BODY", StringComparison.CurrentCultureIgnoreCase))
         {
             ext = ft as NXOpen.Features.ExtractFace;
         }
         if (ft.FeatureType.Equals("Pattern Geometry", StringComparison.CurrentCultureIgnoreCase))
         {
             patt = ft as NXOpen.Features.PatternGeometry;
         }
         if (ft.FeatureType.Equals("MOVE_OBJECT", StringComparison.CurrentCultureIgnoreCase))
         {
             move = ft as NXOpen.Features.MoveObject;
         }
     }
 }
Esempio n. 8
0
        // <summary>
        /// 按x,y,z 移动工件
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="moveX"></param>
        /// <param name="moveY"></param>
        /// <param name="moveZ"></param>
        /// <returns></returns>
        public static NXObject CreateMoveObjToXYZ(string moveX, string moveY, string moveZ, NXOpen.Features.MoveObject moveFeater = null, params NXObject[] objs)
        {
            Part workPart = Session.GetSession().Parts.Work;

            NXOpen.Features.MoveObjectBuilder moveObjectBuilder1;
            moveObjectBuilder1 = workPart.BaseFeatures.CreateMoveObjectBuilder(moveFeater);

            moveObjectBuilder1.TransformMotion.Option = NXOpen.GeometricUtilities.ModlMotion.Options.DeltaXyz; //增量xyz
            moveObjectBuilder1.TransformMotion.AlongCurveAngle.AlongCurve.IsPercentUsed = true;
            moveObjectBuilder1.TransformMotion.DeltaEnum = NXOpen.GeometricUtilities.ModlMotion.Delta.ReferenceAcsWorkPart;

            moveObjectBuilder1.TransformMotion.DeltaXc.RightHandSide = moveX; //x增量

            moveObjectBuilder1.TransformMotion.DeltaYc.RightHandSide = moveY; //y增量

            moveObjectBuilder1.TransformMotion.DeltaZc.RightHandSide = moveZ; //增量
            moveObjectBuilder1.MoveParents = false;
            moveObjectBuilder1.Associative = true;
            bool added1;

            added1 = moveObjectBuilder1.ObjectToMoveObject.Add(objs);
            NXOpen.NXObject nXObject1 = null;
            try
            {
                nXObject1 = moveObjectBuilder1.Commit();
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("MoveObject:CreateMoveObjToXYZ:      " + ex.Message);
            }
            finally
            {
                moveObjectBuilder1.Destroy();
            }
            return(nXObject1);
        }
Esempio n. 9
0
    public static void Main(string[] args)
    {
        Session theSession  = Session.GetSession();
        Part    workPart    = theSession.Parts.Work;
        Part    displayPart = theSession.Parts.Display;

        // ----------------------------------------------
        //   菜单:编辑->移动对象...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId1;
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "开始");

        NXOpen.Features.MoveObject nullFeatures_MoveObject = 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.MoveObjectBuilder moveObjectBuilder1;
        moveObjectBuilder1 = workPart.BaseFeatures.CreateMoveObjectBuilder(nullFeatures_MoveObject);

        moveObjectBuilder1.TransformMotion.DistanceAngle.OrientXpress.AxisOption = NXOpen.GeometricUtilities.OrientXpressBuilder.Axis.Passive;

        moveObjectBuilder1.TransformMotion.DistanceAngle.OrientXpress.PlaneOption = NXOpen.GeometricUtilities.OrientXpressBuilder.Plane.Passive;

        moveObjectBuilder1.TransformMotion.AlongCurveAngle.AlongCurve.IsPercentUsed = true;

        moveObjectBuilder1.TransformMotion.AlongCurveAngle.AlongCurve.Expression.RightHandSide = "0";

        moveObjectBuilder1.TransformMotion.AlongCurveAngle.AlongCurve.Expression.RightHandSide = "0";

        moveObjectBuilder1.TransformMotion.OrientXpress.AxisOption = NXOpen.GeometricUtilities.OrientXpressBuilder.Axis.Passive;

        moveObjectBuilder1.TransformMotion.OrientXpress.PlaneOption = NXOpen.GeometricUtilities.OrientXpressBuilder.Plane.Passive;

        moveObjectBuilder1.TransformMotion.Option = NXOpen.GeometricUtilities.ModlMotion.Options.Angle;

        moveObjectBuilder1.TransformMotion.DistanceValue.RightHandSide = "90";

        moveObjectBuilder1.TransformMotion.DistanceBetweenPointsDistance.RightHandSide = "0";

        moveObjectBuilder1.TransformMotion.RadialDistance.RightHandSide = "0";

        moveObjectBuilder1.TransformMotion.Angle.RightHandSide = "30";

        moveObjectBuilder1.TransformMotion.DistanceAngle.Distance.RightHandSide = "0";

        moveObjectBuilder1.TransformMotion.DistanceAngle.Angle.RightHandSide = "0";

        moveObjectBuilder1.TransformMotion.DeltaEnum = NXOpen.GeometricUtilities.ModlMotion.Delta.ReferenceWcsWorkPart;

        moveObjectBuilder1.TransformMotion.DeltaXc.RightHandSide = "0";

        moveObjectBuilder1.TransformMotion.DeltaYc.RightHandSide = "0";

        moveObjectBuilder1.TransformMotion.DeltaZc.RightHandSide = "0";

        moveObjectBuilder1.TransformMotion.AlongCurveAngle.AlongCurve.Expression.RightHandSide = "0";

        moveObjectBuilder1.TransformMotion.AlongCurveAngle.AlongCurveAngle.RightHandSide = "0";

        moveObjectBuilder1.Layer = 201;

        theSession.SetUndoMarkName(markId1, "移动对象 对话框");

        Point3d   origin1 = new Point3d(0.0, -200.0, 0.0);
        Vector3d  vector1 = new Vector3d(0.0, 1.0, 0.0);
        Direction direction1;

        direction1 = workPart.Directions.CreateDirection(origin1, vector1, NXOpen.SmartObject.UpdateOption.WithinModeling);

        Point nullPoint = null;
        Axis  axis1;

        axis1 = workPart.Axes.CreateAxis(nullPoint, direction1, NXOpen.SmartObject.UpdateOption.WithinModeling);

        moveObjectBuilder1.TransformMotion.AngularAxis = axis1;

        moveObjectBuilder1.TransformMotion.AngularAxis = axis1;

        Line line1 = (Line)workPart.Lines.FindObject("HANDLE R-35944");
        bool added1;

        added1 = moveObjectBuilder1.ObjectToMoveObject.Add(line1);

        moveObjectBuilder1.TransformMotion.Option = NXOpen.GeometricUtilities.ModlMotion.Options.CsysToCsys;

        Xform xform1;

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

        CartesianCoordinateSystem cartesianCoordinateSystem1;

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

        moveObjectBuilder1.TransformMotion.FromCsys = cartesianCoordinateSystem1;

        Point3d  origin2     = new Point3d(0.0, 0.0, 0.0);
        Vector3d xDirection1 = new Vector3d(1.0, 0.0, 0.0);
        Vector3d yDirection1 = new Vector3d(0.0, 1.0, 0.0);
        Xform    xform2;

        xform2 = workPart.Xforms.CreateXform(origin2, xDirection1, yDirection1, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0);

        CartesianCoordinateSystem cartesianCoordinateSystem2;

        cartesianCoordinateSystem2 = workPart.CoordinateSystems.CreateCoordinateSystem(xform2, NXOpen.SmartObject.UpdateOption.WithinModeling);

        moveObjectBuilder1.TransformMotion.ToCsys = cartesianCoordinateSystem2;

        NXOpen.Session.UndoMarkId markId2;
        markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "移动对象");

        theSession.DeleteUndoMark(markId2, null);

        NXOpen.Session.UndoMarkId markId3;
        markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "移动对象");

        theSession.UndoToMarkWithStatus(markId3, null);

        theSession.DeleteUndoMark(markId3, null);

        moveObjectBuilder1.MoveObjectResult = NXOpen.Features.MoveObjectBuilder.MoveObjectResultOptions.CopyOriginal;

        NXOpen.Session.UndoMarkId markId4;
        markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "移动对象");

        theSession.DeleteUndoMark(markId4, null);

        NXOpen.Session.UndoMarkId markId5;
        markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "移动对象");

        NXObject nXObject1;

        nXObject1 = moveObjectBuilder1.Commit();

        NXObject[] objects1;
        objects1 = moveObjectBuilder1.GetCommittedObjects();

        theSession.DeleteUndoMark(markId5, null);

        theSession.SetUndoMarkName(markId1, "移动对象");

        moveObjectBuilder1.Destroy();

        // ----------------------------------------------
        //   菜单:工具->操作记录->停止录制
        // ----------------------------------------------
    }