/// <summary> /// 面上任意一点做射线 /// </summary> /// <param name="face"></param> /// <param name="vec"></param> /// <returns></returns> public static int AskTraceARayForFaceData(Face face, Vector3d vec) { UFSession theUFSession = UFSession.GetUFSession(); Tag[] bodyTag = { face.GetBody().Tag }; UFModl.RayHitPointInfo[] info; Point3d originPt = GetFacePoint(face); double[] origin = { originPt.X, originPt.Y, originPt.Z }; double[] dir = { vec.X, vec.Y, vec.Z }; double[] mat = new double[16]; theUFSession.Mtx4.Identity(mat); int res = 0; int count = 0; theUFSession.Modl.TraceARay(1, bodyTag, origin, dir, mat, 0, out res, out info); foreach (UFModl.RayHitPointInfo ray in info) { Point3d temp = new Point3d(ray.hit_point[0], ray.hit_point[1], ray.hit_point[2]); double dis = UMathUtils.GetDis(originPt, temp); if (ray.hit_face != face.Tag && !UMathUtils.IsEqual(dis, 0)) { int statusPt = 0; theUFSession.Modl.AskPointContainment(ray.hit_point, face.Tag, out statusPt); if (statusPt != 3) { count++; } } } return(count); }
/// <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); }