Esempio n. 1
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. 2
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. 3
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. 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);
            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();
            }
        }