Пример #1
0
 //应用回调
 private void Apply()
 {
     try
     {
         NXFun.SetHighlight(oldhighlight, false);
         Session.UndoMarkId undomark = Program.theSession.SetUndoMark(Session.MarkVisibility.Visible, "打标号");
         foreach (DimInfor listitem in LabelDimList)
         {
             if (listitem.isLabel == "是")
             {
                 if (listitem.is_herited)  //PMIdimention
                 {
                     NXOpen.Annotations.BalloonNote balloon = NXFun.FindObjectByAttr <NXOpen.Annotations.BalloonNote>("GUID", listitem.guid);
                     if (balloon == null)
                     {
                         //没找到 添加
                         NXFun.SetDisplayState(1);
                         NXOpen.Annotations.BalloonNote balloonnote = NXFun.AddBalloonNote((NXOpen.Annotations.Annotation)listitem.dim, listitem.id.ToString(), listitem);
                         NXFun.SetDisplayState(2);
                         //找到二维继承的BalloonNote并设置大小。
                         NXOpen.Annotations.PmiAttribute[] bns = Session.GetSession().Parts.Work.PmiManager.PmiAttributes.ToArray();
                         foreach (NXOpen.Annotations.PmiAttribute pmi in bns)
                         {
                             NXOpen.Annotations.Lettering Lettering = balloonnote.GetLetteringPreferences().GetDimensionText();
                             if (NXFun.GetInheritParent(pmi).Equals(balloonnote) && !pmi.Equals(balloonnote))
                             {
                                 NXFun.EditBalloonNoteSize((NXOpen.Annotations.BalloonNote)pmi, Lettering);
                             }
                         }
                     }
                     else
                     {
                         //找到 改写
                         NXFun.EditBalloonNote(balloon, listitem.id.ToString(), listitem);
                     }
                     NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel);
                     NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id);
                 }
                 else               //普通dimention
                 {
                     //找到IdSymbol 并改写 否则添加
                     NXOpen.Annotations.IdSymbol idsymbol = NXFun.FindObjectByAttr <NXOpen.Annotations.IdSymbol>("GUID", listitem.guid);
                     if (idsymbol == null)
                     {
                         //没找到 添加
                         NXFun.AddIdSymbol((NXOpen.Annotations.Annotation)listitem.dim, listitem.id.ToString(), listitem);
                     }
                     else
                     {
                         //找到 改写
                         NXFun.EditIdSymbol(idsymbol, listitem.id.ToString(), listitem);
                     }
                     NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel);
                     NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id);
                 }
             }
             else if (listitem.isLabel == "否")
             {
                 if (listitem.is_herited)  //PMIdimention
                 {
                     NXOpen.Annotations.BalloonNote balloon = NXFun.FindObjectByAttr <NXOpen.Annotations.BalloonNote>("GUID", listitem.guid);
                     if (balloon != null)
                     {
                         NXFun.DeleteBalloonNoteByAttr("GUID", listitem.guid);
                     }
                     NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel);
                     NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id);
                 }
                 else               //普通dimention
                 {
                     //找到IdSymbol 并改写 否则添加
                     NXOpen.Annotations.IdSymbol idsymbol = NXFun.FindObjectByAttr <NXOpen.Annotations.IdSymbol>("GUID", listitem.guid);
                     if (idsymbol != null)
                     {
                         NXFun.DeleteIdSymbolByAttr("GUID", listitem.guid);
                     }
                     NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel);
                     NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id);
                 }
             }
         }
         foreach (DimInfor listitem in LabelFcfList)
         {
             string num = "J<C0.5>" + listitem.id.ToString() + "<C>";
             if (listitem.isLabel == "是")
             {
                 if (listitem.is_herited)  //Fcf
                 {
                     NXOpen.Annotations.BalloonNote balloon = NXFun.FindObjectByAttr <NXOpen.Annotations.BalloonNote>("GUID", listitem.guid);
                     if (balloon == null)
                     {
                         //没找到 添加
                         NXFun.SetDisplayState(1);
                         NXOpen.Annotations.BalloonNote balloonnote = NXFun.AddBalloonNote((NXOpen.Annotations.Annotation)listitem.dim, num, listitem);
                         NXFun.SetDisplayState(2);
                         //找到二维继承的BalloonNote并设置大小。
                         NXOpen.Annotations.PmiAttribute[] bns = Session.GetSession().Parts.Work.PmiManager.PmiAttributes.ToArray();
                         foreach (NXOpen.Annotations.PmiAttribute pmi in bns)
                         {
                             NXOpen.Annotations.Lettering Lettering = balloonnote.GetLetteringPreferences().GetDimensionText();
                             if (NXFun.GetInheritParent(pmi).Equals(balloonnote) && !pmi.Equals(balloonnote))
                             {
                                 NXFun.EditBalloonNoteSize((NXOpen.Annotations.BalloonNote)pmi, Lettering);
                             }
                         }
                     }
                     else
                     {
                         //找到 改写
                         NXFun.EditBalloonNote(balloon, num, listitem);
                     }
                     NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel);
                     NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id);
                 }
                 else               //普通DraftingFcf
                 {
                     //找到IdSymbol 并改写 否则添加
                     NXOpen.Annotations.IdSymbol idsymbol = NXFun.FindObjectByAttr <NXOpen.Annotations.IdSymbol>("GUID", listitem.guid);
                     if (idsymbol == null)
                     {
                         //没找到 添加
                         NXFun.AddIdSymbol((NXOpen.Annotations.Annotation)listitem.dim, num, listitem);
                     }
                     else
                     {
                         //找到 改写
                         NXFun.EditIdSymbol(idsymbol, num, listitem);
                     }
                     NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel);
                     NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id);
                 }
             }
             else if (listitem.isLabel == "否")
             {
                 if (listitem.is_herited)  //Fcf
                 {
                     NXOpen.Annotations.BalloonNote balloon = NXFun.FindObjectByAttr <NXOpen.Annotations.BalloonNote>("GUID", listitem.guid);
                     if (balloon != null)
                     {
                         NXFun.DeleteBalloonNoteByAttr("GUID", listitem.guid);
                     }
                     NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel);
                     NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id);
                 }
                 else               //DraftingFcf
                 {
                     //找到IdSymbol 并改写 否则添加
                     NXOpen.Annotations.IdSymbol idsymbol = NXFun.FindObjectByAttr <NXOpen.Annotations.IdSymbol>("GUID", listitem.guid);
                     if (idsymbol != null)
                     {
                         NXFun.DeleteIdSymbolByAttr("GUID", listitem.guid);
                     }
                     NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel);
                     NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id);
                 }
             }
         }
         Program.theSession.UpdateManager.DoUpdate(undomark);
     }
     catch (System.Exception ex)
     {
         UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
     }
 }
Пример #2
0
    public void SetDimensionTolerance(NXOpen.Annotations.Dimension dimension, double upper, double lower)
    {
        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, "Start");
        NXOpen.Annotations.Value lowerToleranceMm1;
        lowerToleranceMm1.ItemValue = lower;
        Expression nullExpression = null;

        lowerToleranceMm1.ValueExpression = nullExpression;
        lowerToleranceMm1.ValuePrecision  = 3;
        NXOpen.Annotations.Value upperToleranceMm1;
        upperToleranceMm1.ItemValue       = upper;
        upperToleranceMm1.ValueExpression = nullExpression;
        upperToleranceMm1.ValuePrecision  = 3;
        Object tol  = ReflectFun(dimension, "GetTolerance");
        Type   type = tol.GetType();

        if (type.Name == "LinearTolerance")
        {
            ReflectFun(tol, "SetLowerToleranceMm", lowerToleranceMm1);
            ReflectFun(tol, "SetUpperToleranceMm", upperToleranceMm1);
        }
        else
        {
            ReflectFun(tol, "SetLowerToleranceDegrees", lowerToleranceMm1);
            ReflectFun(tol, "SetUpperToleranceDegrees", upperToleranceMm1);
        }
        //设置公差类型
        if (upper + lower == 0)
        {
            ReflectSetProperty(tol, "ToleranceType", NXOpen.Annotations.ToleranceType.BilateralOneLine);
        }
        else if (lower == 0)
        {
            ReflectSetProperty(tol, "ToleranceType", NXOpen.Annotations.ToleranceType.UnilateralAbove);
        }
        else if (upper == 0)
        {
            ReflectSetProperty(tol, "ToleranceType", NXOpen.Annotations.ToleranceType.UnilateralBelow);
        }
        else
        {
            ReflectSetProperty(tol, "ToleranceType", NXOpen.Annotations.ToleranceType.BilateralTwoLines);
        }
        ReflectFun(dimension, "SetTolerance", tol);

        //设置公差的显示大小
        NXOpen.Annotations.LetteringPreferences letteringPreferences1;
        letteringPreferences1 = dimension.GetLetteringPreferences();
        NXOpen.Annotations.Lettering toleranceText1 = letteringPreferences1.GetDimensionText();
        if (upper + lower != 0)
        {
            toleranceText1.Size = 0.57 * toleranceText1.Size;
        }
        letteringPreferences1.SetToleranceText(toleranceText1);
        dimension.SetLetteringPreferences(letteringPreferences1);
        int nErrs2 = theSession.UpdateManager.DoUpdate(markId1);
    }