/// <summary> /// 测量两个对象集之间的投影距离,只能是当前工作部件中的对象,可用类型为 Point, Curve, Edge, Face, Body, Datum Plane. /// </summary> /// <param name="measureManager"></param> /// <param name="objects1"></param> /// <param name="objects2"></param> /// <param name="projectVector">投影矢量</param> /// <param name="type">测量类型</param> /// <returns>投影距离值</returns> public static (bool Success, double Distance, Point3d PointOn1stObjects, Point3d PointOn2ndObjects) MeasureProjectDistance(this MeasureManager measureManager, NXObject[] objects1, NXObject[] objects2, Vector3d projectVector, MeasureManager.ProjectionType type) { try { NXOpen.Unit lengthUnit = WorkPart.UnitCollection.FindObject("MilliMeter"); Direction direction = WorkPart.Directions.CreateDirection(new Point3d(), projectVector, NXOpen.SmartObject.UpdateOption.WithinModeling); MeasureDistance minimumMeasure = measureManager.NewScDistance(lengthUnit, CreateCollector(objects1), CreateCollector(objects2), direction, type, true); Measure measureFeature = minimumMeasure.CreateFeature(); var measureLine = measureFeature.GetEntities()[0] as Line; var minimumDistance = measureLine.GetLength(); Point3d pointOn1stObjects = measureLine.StartPoint; Point3d pointOn2ndObjects = measureLine.EndPoint; measureFeature.Delete(); return(true, minimumDistance, pointOn1stObjects, pointOn2ndObjects); } catch (Exception) { return(false, 0, new Point3d(), new Point3d()); } }
/// <summary> /// 使用 NXOpen 测量两个对象之间的距离 /// </summary> /// <param name="measureManager"></param> /// <param name="object1">对象1</param> /// <param name="object2">对象2</param> /// <returns>距离值</returns> public static (bool Success, double Distance, Point3d PointOn1stObject, Point3d PointOn2ndObject) MeasureDistance(this MeasureManager measureManager, DisplayableObject object1, DisplayableObject object2) { try { NXOpen.Unit lengthUnit = WorkPart.UnitCollection.FindObject("MilliMeter"); MeasureDistance distance = measureManager.NewDistance(lengthUnit, MeasureManager.MeasureType.Minimum, true, object1, object2); var measureFeature = distance.CreateFeature(); var measureLine = measureFeature.GetEntities()[0] as Line; var minimumDistance = measureLine.GetLength(); Point3d pointOn1stObject = measureLine.StartPoint; Point3d pointOn2ndObject = measureLine.EndPoint; measureFeature.Delete(); return(true, minimumDistance, pointOn1stObject, pointOn2ndObject); } catch (Exception) { return(false, 0, new Point3d(), new Point3d()); } }