public static void GetTolerance(NXOpen.Annotations.Dimension dim, out double up, out double low) { //目前未考虑精度 try { up = 0; low = 0; Object tol = ReflectFun(dim, "GetTolerance"); NXOpen.Annotations.LinearTolerance lint = (NXOpen.Annotations.LinearTolerance)tol; NXOpen.Annotations.ToleranceType oldtype = lint.ToleranceType; // ReflectSetProperty(tol, "ToleranceType", NXOpen.Annotations.ToleranceType.BilateralTwoLines); //ReflectFun(dim, "SetTolerance", tol); Type type = tol.GetType(); NXOpen.Annotations.Value v_up = new NXOpen.Annotations.Value(); NXOpen.Annotations.Value v_low = new NXOpen.Annotations.Value(); if (type.Name == "LinearTolerance") { if (lint.ToleranceType == NXOpen.Annotations.ToleranceType.BilateralOneLine) { //v_low = (NXOpen.Annotations.Value)ReflectFun(tol, "GetLowerToleranceMm"); v_up = (NXOpen.Annotations.Value)ReflectFun(tol, "GetUpperToleranceMm"); v_low = v_up; up = v_up.ItemValue; low = v_low.ItemValue*(-1); } else if (lint.ToleranceType == NXOpen.Annotations.ToleranceType.UnilateralBelow) { up = 0; v_low = (NXOpen.Annotations.Value)ReflectFun(tol, "GetLowerToleranceMm"); low = v_low.ItemValue; } else if(lint.ToleranceType == NXOpen.Annotations.ToleranceType.UnilateralAbove) { low = 0; v_up = (NXOpen.Annotations.Value)ReflectFun(tol, "GetUpperToleranceMm"); up = v_up.ItemValue; } else if (lint.ToleranceType == NXOpen.Annotations.ToleranceType.BilateralTwoLines) { v_low = (NXOpen.Annotations.Value)ReflectFun(tol, "GetLowerToleranceMm"); v_up = (NXOpen.Annotations.Value)ReflectFun(tol, "GetUpperToleranceMm"); up = v_up.ItemValue; low = v_low.ItemValue; } } else { v_low = (NXOpen.Annotations.Value)ReflectFun(tol, "GetLowerToleranceDegrees"); v_up = (NXOpen.Annotations.Value)ReflectFun(tol, "GetUpperToleranceDegrees"); } ReflectSetProperty(tol, "ToleranceType", oldtype); ReflectFun(dim, "SetTolerance", tol); } catch (System.Exception ex) { UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Warning, ex.Message); up = 0; low = 0; } }
public static void GetTolerance(NXOpen.Annotations.Dimension dim, out double up, out double low) { //目前未考虑精度 try { up = 0; low = 0; Object tol = ReflectFun(dim, "GetTolerance"); // ReflectSetProperty(tol, "ToleranceType", NXOpen.Annotations.ToleranceType.BilateralTwoLines); //ReflectFun(dim, "SetTolerance", tol); Type type = tol.GetType(); if (type.Name == "LinearTolerance") { NXOpen.Annotations.Value v_up = new NXOpen.Annotations.Value(); NXOpen.Annotations.Value v_low = new NXOpen.Annotations.Value(); NXOpen.Annotations.LinearTolerance lint = (NXOpen.Annotations.LinearTolerance)tol; NXOpen.Annotations.ToleranceType oldtype = lint.ToleranceType; if (lint.ToleranceType == NXOpen.Annotations.ToleranceType.BilateralOneLine) { //v_low = (NXOpen.Annotations.Value)ReflectFun(tol, "GetLowerToleranceMm"); v_up = (NXOpen.Annotations.Value)ReflectFun(tol, "GetUpperToleranceMm"); v_low = v_up; up = v_up.ItemValue; low = v_low.ItemValue * (-1); } else if (lint.ToleranceType == NXOpen.Annotations.ToleranceType.UnilateralBelow) { up = 0; v_low = (NXOpen.Annotations.Value)ReflectFun(tol, "GetLowerToleranceMm"); low = v_low.ItemValue; } else if (lint.ToleranceType == NXOpen.Annotations.ToleranceType.UnilateralAbove) { low = 0; v_up = (NXOpen.Annotations.Value)ReflectFun(tol, "GetUpperToleranceMm"); up = v_up.ItemValue; } else if (lint.ToleranceType == NXOpen.Annotations.ToleranceType.BilateralTwoLines) { v_low = (NXOpen.Annotations.Value)ReflectFun(tol, "GetLowerToleranceMm"); v_up = (NXOpen.Annotations.Value)ReflectFun(tol, "GetUpperToleranceMm"); up = v_up.ItemValue; low = v_low.ItemValue; } ReflectSetProperty(tol, "ToleranceType", oldtype); ReflectFun(dim, "SetTolerance", tol); } else { NXOpen.Annotations.AngularTolerance lint = (NXOpen.Annotations.AngularTolerance)tol; NXOpen.Annotations.ToleranceType oldtype = lint.ToleranceType; NXOpen.Annotations.Value v_up = new NXOpen.Annotations.Value(); NXOpen.Annotations.Value v_low = new NXOpen.Annotations.Value(); if (lint.ToleranceType == NXOpen.Annotations.ToleranceType.BilateralOneLine) { //v_low = (NXOpen.Annotations.Value)ReflectFun(tol, "GetLowerToleranceMm"); v_up = (NXOpen.Annotations.Value)ReflectFun(tol, "GetUpperToleranceDegrees"); v_low = v_up; up = v_up.ItemValue; low = v_low.ItemValue * (-1); } else if (lint.ToleranceType == NXOpen.Annotations.ToleranceType.UnilateralBelow) { up = 0; v_low = (NXOpen.Annotations.Value)ReflectFun(tol, "GetLowerToleranceDegrees"); low = v_low.ItemValue; } else if (lint.ToleranceType == NXOpen.Annotations.ToleranceType.UnilateralAbove) { low = 0; v_up = (NXOpen.Annotations.Value)ReflectFun(tol, "GetUpperToleranceDegrees"); up = v_up.ItemValue; } else if (lint.ToleranceType == NXOpen.Annotations.ToleranceType.BilateralTwoLines) { v_low = (NXOpen.Annotations.Value)ReflectFun(tol, "GetLowerToleranceDegrees"); v_up = (NXOpen.Annotations.Value)ReflectFun(tol, "GetUpperToleranceDegrees"); up = v_up.ItemValue; low = v_low.ItemValue; } ReflectSetProperty(tol, "ToleranceType", oldtype); ReflectFun(dim, "SetTolerance", tol); } } catch (System.Exception ex) { //UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Warning, ex.Message); up = 0; low = 0; } }