Exemplo n.º 1
1
 public form1(NXOpen.Annotations.Dimension fengbihuan,NXOpen.Annotations.Dimension[] zeng,NXOpen.Annotations.Dimension[] jian)
 {
     InitializeComponent();
         fengbi = fengbihuan;
         zenghuan = zeng;
         jianhuan = jian;
 }
        /// <summary>
        /// 电极竖直标注
        /// </summary>
        /// <param name="topView"></param>
        /// <param name="originPt"></param>
        /// <param name="scale"></param>
        private void EleProViewDimension(DraftingView topView, double scale, Point3d originPt)
        {
            string err = "";

            int[]       pre   = model.Info.AllInfo.Preparetion.Preparation;
            List <Edge> xEdge = new List <Edge>();
            Point       centerPt;

            model.GetEdge(out xEdge, out centerPt);
            // Point3d originPt = topView.GetDrawingReferencePoint();
            Point3d dimPt = new Point3d(originPt.X - (pre[1] * scale / 2 + 10), originPt.Y, 0);

            if (xEdge.Count == 0 || centerPt == null)
            {
                return;
            }
            try
            {
                NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionVertical(topView, dimPt, xEdge[0], centerPt, ref err);
                if (dim != null)
                {
                    Basic.DrawingUtils.SetDimensionPrecision(dim, 3);
                }
            }
            catch (NXException ex)
            {
                ClassItem.WriteLogFile(model.AssembleName + "电极视图竖直标注错误!" + ex.Message);
            }
        }
Exemplo n.º 3
0
    public void drawdim(double inupdou, double indowndou, NXOpen.Annotations.Dimension fengbi, System.Drawing.Point pt1, System.Drawing.Point pt2)   //这个drawdim是用来在多工序间进行校核的时候
    {
        Graphics drawstr = panel1.CreateGraphics();

        double[] fengbiinfo = null;
        fengbiinfo = thepubfun.getspec(fengbi);
        decimal fengbiinfo1 = 0;
        decimal fengbiinfo2 = 0;

        fengbiinfo1 = Convert.ToDecimal(inupdou) - Convert.ToDecimal(fengbiinfo[0]);
        fengbiinfo2 = Convert.ToDecimal(indowndou) - Convert.ToDecimal(fengbiinfo[0]);


        //fengbiinfo[1] = fengbiinfo1;
        //fengbiinfo[2] = fengbiinfo2;
        System.Drawing.Point strpoint = new System.Drawing.Point();
        strpoint.X = Convert.ToInt32((pt1.X + pt2.X) / 2.2);
        strpoint.Y = (pt1.Y - 20);
        drawstr.DrawString(fengbiinfo[0].ToString(), new Font("Verdana", 10), new SolidBrush(Color.Black), strpoint);
        System.Drawing.Point upstrpoint = new System.Drawing.Point();
        upstrpoint.X = strpoint.X + 25;
        upstrpoint.Y = strpoint.Y;
        drawstr.DrawString(fengbiinfo1.ToString(), new Font("Verdana", 5), new SolidBrush(Color.Black), upstrpoint);
        System.Drawing.Point downstrpoint = new System.Drawing.Point();
        downstrpoint.X = strpoint.X + 22;
        downstrpoint.Y = strpoint.Y + 10;
        drawstr.DrawString(fengbiinfo2.ToString(), new Font("Verdana", 5), new SolidBrush(Color.Black), downstrpoint);
    }
Exemplo n.º 4
0
        private void EleTopDimension(DraftingView topView, Point3d originPt, double scale, Face face)
        {
            int[]       pre   = draInfo.DraModel.Eles[0].EleInfo.Preparation;
            List <Edge> xEdge = new List <Edge>();
            List <Edge> yEdge = new List <Edge>();
            string      err   = "";
            Point3d     pt1   = new Point3d(originPt.X - (pre[0] * scale / 2 + 10), originPt.Y, 0);
            Point3d     pt2   = new Point3d(originPt.X, originPt.Y - (pre[1] * scale / 2 + 10), 0);

            this.draInfo.GetEdge(face, out xEdge, out yEdge);
            if (xEdge.Count == 0 && yEdge.Count == 0)
            {
                return;
            }
            NXOpen.Annotations.Dimension dim1 = Basic.DrawingUtils.DimensionVertical(topView, pt1, xEdge[0], xEdge[1], ref err);
            if (dim1 != null)
            {
                Basic.DrawingUtils.SetDimensionPrecision(dim1, 0);
            }
            NXOpen.Annotations.Dimension dim2 = Basic.DrawingUtils.DimensionHorizontal(topView, pt2, yEdge[0], yEdge[1], ref err);
            if (dim2 != null)
            {
                Basic.DrawingUtils.SetDimensionPrecision(dim2, 0);
            }
        }
Exemplo n.º 5
0
 public form1(NXOpen.Annotations.Dimension fengbihuan, NXOpen.Annotations.Dimension[] zeng, NXOpen.Annotations.Dimension[] jian)
 {
     InitializeComponent();
     fengbi   = fengbihuan;
     zenghuan = zeng;
     jianhuan = jian;
 }
        /// <summary>
        /// 设置尺寸颜色
        /// </summary>
        /// <param name="dim"></param>
        private void SetDimColor(NXOpen.Annotations.Dimension dim)
        {
            Part workPart = Session.GetSession().Parts.Work;

            NXOpen.Annotations.LinearDimensionBuilder linearDimensionBuilder1;
            linearDimensionBuilder1 = workPart.Dimensions.CreateLinearDimensionBuilder(dim);

            linearDimensionBuilder1.Style.LineArrowStyle.SecondArrowheadColor = workPart.Colors.Find("Magenta");

            linearDimensionBuilder1.Style.LineArrowStyle.FirstExtensionLineColor = workPart.Colors.Find("Magenta");

            linearDimensionBuilder1.Style.LineArrowStyle.SecondExtensionLineColor = workPart.Colors.Find("Magenta");

            linearDimensionBuilder1.Style.LineArrowStyle.FirstArrowheadColor = workPart.Colors.Find("Magenta");

            linearDimensionBuilder1.Style.LineArrowStyle.FirstArrowLineColor = workPart.Colors.Find("Magenta");

            linearDimensionBuilder1.Style.LineArrowStyle.SecondArrowLineColor = workPart.Colors.Find("Magenta");

            linearDimensionBuilder1.Style.LetteringStyle.DimensionTextColor = workPart.Colors.Find("Magenta");

            linearDimensionBuilder1.Style.LetteringStyle.AppendedTextColor = workPart.Colors.Find("Magenta");

            linearDimensionBuilder1.Style.LetteringStyle.ToleranceTextColor = workPart.Colors.Find("Magenta");

            NXOpen.NXObject nXObject1;
            nXObject1 = linearDimensionBuilder1.Commit();
            linearDimensionBuilder1.Destroy();
        }
Exemplo n.º 7
0
 public form1(NXOpen.Annotations.Dimension[] zeng, NXOpen.Annotations.Dimension[] jian, NXOpen.Annotations.Dimension fengbihuan, string up, string down)
 {
     InitializeComponent();
     zenghuan = zeng;
     jianhuan = jian;
     inup     = up;
     indown   = down;
     fengbi   = fengbihuan;
 }
Exemplo n.º 8
0
 public form1(NXOpen.Annotations.Dimension[] zeng, NXOpen.Annotations.Dimension[] jian, NXOpen.Annotations.Dimension fengbihuan, double up, double down)
 {
     InitializeComponent();
     zenghuan  = zeng;
     jianhuan  = jian;
     inupdou   = up;
     indowndou = down;
     fengbi    = fengbihuan;
 }
Exemplo n.º 9
0
 public form1(NXOpen.Annotations.Dimension[] zeng, NXOpen.Annotations.Dimension[] jian, NXOpen.Annotations.Dimension fengbihuan, double up, double down)
 {
     InitializeComponent();
         zenghuan = zeng;
         jianhuan = jian;
         inupdou = up;
         indowndou = down;
         fengbi = fengbihuan;
 }
Exemplo n.º 10
0
 public form1(NXOpen.Annotations.Dimension[] zeng, NXOpen.Annotations.Dimension[] jian,NXOpen.Annotations.Dimension fengbihuan,string up,string down)
 {
     InitializeComponent();
         zenghuan = zeng;
         jianhuan = jian;
         inup = up;
         indown = down;
         fengbi = fengbihuan;
 }
Exemplo n.º 11
0
        private void ProViewDimension(DraftingView topView, Point3d originPt, double scale, Point workPoint, List <Point> elePoint)
        {
            string  err   = "";
            Point3d dimPt = new Point3d(originPt.X - (this.draInfo.DisPt.X * scale + 10), originPt.Y + (this.draInfo.DisPt.X * scale), 0);

            NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionVertical(topView, dimPt, workPoint, elePoint[0], ref err);
            if (dim != null)
            {
                Basic.DrawingUtils.AppendedTextDim(dim, "EDM SETTING");
                SetDimColor(dim);
            }
        }
Exemplo n.º 12
0
        private void TopDimension(DraftingView topView, Point3d originPt, double scale, Point workPoint, List <Point> elePoint)
        {
            string err = "";

            Matrix4 mat = this.draInfo.DraModel.Work.WorkMatr;

            PointSort(ref elePoint, mat, "X");
            for (int i = 0; i < elePoint.Count; i++)
            {
                Point3d dimPt = new Point3d(originPt.X + 10.0, originPt.Y + this.draInfo.DisPt.Y * scale + (10 * (i + 1)), 0);
                NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionHorizontal(topView, dimPt, workPoint, elePoint[i], ref err);
                if (dim != null)
                {
                    Basic.DrawingUtils.AppendedTextDim(dim, "EDM SETTING");
                    SetDimColor(dim);
                }
                //Point3d temp = (elePoint[i].Prototype as Point).Coordinates;
                //if (temp.X != 0)
                //{
                //    double crude = -(this.draInfo.DraModel.Eles[0].EleInfo.CrudeInter);
                //    double fine = -(this.draInfo.DraModel.Eles[0].EleInfo.FineInter);
                //    if (crude != 0 && fine != 0)
                //        Basic.DrawingUtils.ToleranceDim(dim, NXOpen.Annotations.ToleranceType.BilateralTwoLines, fine, crude);
                //    if (crude != 0 && fine == 0)
                //        Basic.DrawingUtils.ToleranceDim(dim, NXOpen.Annotations.ToleranceType.BilateralTwoLines, 0, crude);
                //    if (crude == 0 && fine != 0)
                //        Basic.DrawingUtils.ToleranceDim(dim, NXOpen.Annotations.ToleranceType.BilateralTwoLines, 0, fine);
                //}
            }
            PointSort(ref elePoint, mat, "Y");
            for (int i = 0; i < elePoint.Count; i++)
            {
                Point3d dimPt = new Point3d(originPt.X - (this.draInfo.DisPt.X * scale + 8 * (i + 1)), originPt.Y + 10, 0);
                NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionVertical(topView, dimPt, workPoint, elePoint[i], ref err);
                if (dim != null)
                {
                    Basic.DrawingUtils.AppendedTextDim(dim, "EDM SETTING");
                    SetDimColor(dim);
                }
                //Point3d temp = (elePoint[i].Prototype as Point).Coordinates;
                //if (temp.Y != 0)
                //{
                //    double crude = -(this.draInfo.DraModel.Eles[0].EleInfo.CrudeInter);
                //    double fine = -(this.draInfo.DraModel.Eles[0].EleInfo.FineInter);
                //    if (crude != 0 && fine != 0)
                //        Basic.DrawingUtils.ToleranceDim(dim, NXOpen.Annotations.ToleranceType.BilateralTwoLines, fine, crude);
                //    if (crude != 0 && fine == 0)
                //        Basic.DrawingUtils.ToleranceDim(dim, NXOpen.Annotations.ToleranceType.BilateralTwoLines, 0, crude);
                //    if (crude == 0 && fine != 0)
                //        Basic.DrawingUtils.ToleranceDim(dim, NXOpen.Annotations.ToleranceType.BilateralTwoLines, 0, fine);
                //}
            }
        }
Exemplo n.º 13
0
    public bool countcircle(NXOpen.Annotations.Dimension fengbi, NXOpen.Annotations.Dimension[] zeng, NXOpen.Annotations.Dimension[] jian, out double a, out double b) //这个函数是进行尺寸链校核计算的主方法
    {
        double zengmax = 0;                                                                                                                                            //所有增环的最大尺寸之和
        double zengmin = 0;                                                                                                                                            //所有增环的最小尺寸之和
        double jianmax = 0;                                                                                                                                            //所有减环的最大尺寸之和
        double jianmin = 0;                                                                                                                                            //所有减环的最小尺寸之和
        double clsmax  = 0;                                                                                                                                            //封闭环最大尺寸
        double clsmin  = 0;                                                                                                                                            //封闭环最小尺寸

        a = 0;                                                                                                                                                         //最大上公差
        b = 0;                                                                                                                                                         //最小下公差
        double aclsmax = 0;                                                                                                                                            //所有 增环最大尺寸减去所有减环最小极限尺寸
        double aclsmin = 0;                                                                                                                                            //所有增环最小尺寸减去所有减环最大尺寸

        foreach (NXOpen.Annotations.Dimension zenghuan in zeng)
        {
            zengmax = getspec(zenghuan)[0] + getspec(zenghuan)[1] + zengmax;
            zengmin = getspec(zenghuan)[0] + getspec(zenghuan)[2] + zengmin;
        }
        foreach (NXOpen.Annotations.Dimension jianhuan in jian)
        {
            jianmax = getspec(jianhuan)[0] + getspec(jianhuan)[1] + jianmax;
            jianmin = getspec(jianhuan)[0] + getspec(jianhuan)[2] + jianmin;
        }

        clsmax  = getspec(fengbi)[0] + getspec(fengbi)[1];
        clsmin  = getspec(fengbi)[0] + getspec(fengbi)[2];
        aclsmax = zengmax - jianmin;
        aclsmin = zengmin - jianmax;

        decimal aa = Convert.ToDecimal(aclsmax) - Convert.ToDecimal(getspec(fengbi)[0]);
        decimal bb = Convert.ToDecimal(aclsmin) - Convert.ToDecimal(getspec(fengbi)[0]);

        a = Convert.ToDouble(aa);
        b = Convert.ToDouble(bb);
        if (aclsmax >= clsmax && aclsmin <= clsmin)
        {
            return(true);
        }
        else
        {
            return(false);
        }
        //if (b <= 0)
        //{
        //    return false;
        //}
        //else
        //{
        //    return true;
        //}
    }
Exemplo n.º 14
0
    public void drawfengbi(NXOpen.Annotations.Dimension fengbi)
    {
        double[] fengbiinfo = null;
        fengbiinfo = thepubfun.getspec(fengbi);
        q          = Convert.ToInt32((fengbiinfo[0] + 100));
        System.Drawing.Point pt1    = new System.Drawing.Point(100, 50);
        System.Drawing.Point pt2    = new System.Drawing.Point(q, 50);
        Graphics             drawfb = panel1.CreateGraphics();

        drawfb.DrawLine(thepen, pt1, pt2);
        drawduanxian(pt1, pt2);
        drawdim(fengbi, pt1, pt2);
    }
Exemplo n.º 15
0
    //------------------------------------------------------------------------------
    //Callback Name: apply_cb
    //------------------------------------------------------------------------------
    public int apply_cb()
    {
        int errorCode = 0;

        try
        {
            firstpt = point0.GetProperties().GetTaggedObjectVector("SelectedObjects");
            secpt   = point01.GetProperties().GetTaggedObjectVector("SelectedObjects");
            Point    a      = Tag2NXObject <Point>(firstpt[0].Tag);
            Point    b      = Tag2NXObject <Point>(secpt[0].Tag);
            NXObject axisyo = shank(a, b);
            double[] real3d;
            NXOpen.Features.DatumAxisFeature axisreal = (NXOpen.Features.DatumAxisFeature)axisyo;
            DatumAxis axisreal1 = axisreal.DatumAxis;
            Point3d   stpt;  //轴的起点
            Point3d   endpt; //轴的终点
            stpt  = a.Coordinates;
            endpt = b.Coordinates;
            // axisreal1.GetEndPoints(out stpt, out endpt);
            hideit(axisreal1);
            real3d = angle(axisreal1);
            thepmi = selection0.GetProperties().GetTaggedObjectVector("SelectedObjects");
            NXObject last = Tag2NXObject <NXObject>(thepmi[0].Tag);
            NXOpen.Annotations.Dimension lastdimn = (NXOpen.Annotations.Dimension)last;
            double m     = lastdimn.ComputedSize;
            double cosx  = Math.Cos(ConvertDegreesToRadians(real3d[0]));
            double cosy  = Math.Cos(ConvertDegreesToRadians(real3d[1]));
            double cosz  = Math.Cos(ConvertDegreesToRadians(real3d[2]));
            double cosxx = cosx * m;
            double cosyy = cosy * m;
            double coszz = cosz * m;
            last.SetAttribute("X", cosxx);
            last.SetAttribute("Y", cosyy);
            last.SetAttribute("Z", coszz);
            last.SetAttribute("START-X", stpt.X);
            last.SetAttribute("START-Y", stpt.Y);
            last.SetAttribute("START-Z", stpt.Z);
            last.SetAttribute("END-X", endpt.X);
            last.SetAttribute("END-Y", endpt.Y);
            last.SetAttribute("END-Z", endpt.Z);

            //---- Enter your callback code here -----
        }
        catch (Exception ex)
        {
            //---- Enter your exception handling code here -----
            errorCode = 1;
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
        }
        return(errorCode);
    }
Exemplo n.º 16
0
    public double[] getspec(NXOpen.Annotations.Dimension dim)//返回一个尺寸的名义值和上下公差,第一个值是名义值,第二个是上公差,第三个是下公差
    {
        string[] a;
        string[] b;
        double   maindim = 0;
        double   low     = 0;
        double   up      = 0;

        double[] final = { 0, 0, 0 };

        maindim = GetDimensionValue(dim);
        GetTolerance(dim, out up, out low);
        final[0] = maindim;
        final[1] = up;
        final[2] = low;
        return(final);
    }
Exemplo n.º 17
0
    public string[] getspec(NXOpen.Annotations.Dimension dim)    //返回一个尺寸的名义值和上下公差,第一个值是名义值,第二个是上公差,第三个是下公差
    {
        string[] a;
        string[] b;
        string   maindim = null;
        double   low     = 0;
        double   up      = 0;

        string[] final = { "", "", "" };

        maindim = GetDimensionValue(dim);
        GetTolerance(dim, out up, out low);
        final[0] = maindim;
        final[1] = up.ToString();
        final[2] = low.ToString();
        return(final);
    }
Exemplo n.º 18
0
    public double[] getspec(NXOpen.Annotations.Dimension dim)//返回一个尺寸的名义值和上下公差,第一个值是名义值,第二个是上公差,第三个是下公差
    {
        string[] a;
        string[] b;
        double   maindim = 0;
        double   low     = 0;
        double   up      = 0;

        double[] final = { 0, 0, 0 };
        dim.GetDimensionText(out a, out b);
        maindim  = double.Parse(a[0]);
        up       = dim.UpperMetricToleranceValue;
        low      = dim.LowerMetricToleranceValue;
        final[0] = maindim;
        final[1] = up;
        final[2] = low;
        return(final);
    }
Exemplo n.º 19
0
    public void drawdim(NXOpen.Annotations.Dimension dim, System.Drawing.Point pt1, System.Drawing.Point pt2)    //这个是正常的画线函数
    {
        Graphics drawstr = panel1.CreateGraphics();

        double[] info = thepubfun.getspec(dim);

        System.Drawing.Point strpoint = new System.Drawing.Point();
        strpoint.X = Convert.ToInt32((pt1.X + pt2.X) / 2.2);
        strpoint.Y = (pt1.Y - 20);
        drawstr.DrawString(info[0].ToString(), new Font("Verdana", 10), new SolidBrush(Color.Black), strpoint);
        System.Drawing.Point upstrpoint = new System.Drawing.Point();
        upstrpoint.X = strpoint.X + 25;
        upstrpoint.Y = strpoint.Y;
        drawstr.DrawString(info[1].ToString(), new Font("Verdana", 5), new SolidBrush(Color.Black), upstrpoint);
        System.Drawing.Point downstrpoint = new System.Drawing.Point();
        downstrpoint.X = strpoint.X + 22;
        downstrpoint.Y = strpoint.Y + 10;
        drawstr.DrawString(info[2].ToString(), new Font("Verdana", 5), new SolidBrush(Color.Black), downstrpoint);
    }
Exemplo n.º 20
0
        /// <summary>
        /// 创建尺寸约束
        /// </summary>
        /// <param name="line1"></param>
        /// <param name="line2"></param>
        /// <param name="dimOrigin"></param>
        /// <param name="method"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Expression CreateDimForLine(Line line1, Line line2, double[] dimOrigin, NXOpen.Annotations.DimensionMeasurementBuilder.MeasurementMethod method, InferSnapType.SnapType type)
        {
            Part workPart = theSession.Parts.Work;

            NXOpen.Annotations.Dimension        nullNXOpen_Annotations_Dimension = null;
            NXOpen.SketchLinearDimensionBuilder sketchLinearDimensionBuilder1;
            sketchLinearDimensionBuilder1 = workPart.Sketches.CreateLinearDimensionBuilder(nullNXOpen_Annotations_Dimension);
            sketchLinearDimensionBuilder1.Origin.SetInferRelativeToGeometry(true);                                                      //如果未应用其他关联性,则在提交时推断关联几何关系
            sketchLinearDimensionBuilder1.Measurement.Method       = method;                                                            //测量方向
            sketchLinearDimensionBuilder1.Driving.DrivingMethod    = NXOpen.Annotations.DrivingValueBuilder.DrivingValueMethod.Driving; //驱动方法
            sketchLinearDimensionBuilder1.Origin.Plane.PlaneMethod = NXOpen.Annotations.PlaneBuilder.PlaneMethodType.XyPlane;           //平面类型
            NXOpen.Direction nullNXOpen_Direction = null;
            sketchLinearDimensionBuilder1.Measurement.Direction = nullNXOpen_Direction;                                                 //测量方向
            NXOpen.View nullNXOpen_View = null;
            sketchLinearDimensionBuilder1.Measurement.DirectionView = nullNXOpen_View;                                                  //测量视图
            sketchLinearDimensionBuilder1.Style.DimensionStyle.NarrowDisplayType = NXOpen.Annotations.NarrowDisplayOption.None;         //设置窄尺寸样式
            NXOpen.Point3d point2_3 = new NXOpen.Point3d(0.0, 0.0, 0.0);
            sketchLinearDimensionBuilder1.SecondAssociativity.SetValue(NXOpen.InferSnapType.SnapType.Mid, line2, workPart.ModelingViews.WorkView, line2.EndPoint, null, nullNXOpen_View, point2_3);

            NXOpen.Point3d point2_4 = new NXOpen.Point3d(0.0, 0.0, 0.0);
            sketchLinearDimensionBuilder1.FirstAssociativity.SetValue(type, line1, workPart.ModelingViews.WorkView, line1.EndPoint, null, nullNXOpen_View, point2_4);
            NXOpen.Point3d point3 = new NXOpen.Point3d(dimOrigin[0], dimOrigin[1], dimOrigin[2]);
            sketchLinearDimensionBuilder1.Origin.Origin.SetValue(null, nullNXOpen_View, point3);

            try
            {
                NXOpen.NXObject nXObject1;
                nXObject1 = sketchLinearDimensionBuilder1.Commit();
                Expression exp = sketchLinearDimensionBuilder1.Driving.ExpressionValue;
                return(exp);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("SketchUtils:CreateDimForLine:" + ex.Message);
                throw ex;
            }
            finally
            {
                sketchLinearDimensionBuilder1.Destroy();
            }
        }
Exemplo n.º 21
0
        private void EleProViewDimension(DraftingView topView, Point3d originPt, double scale, Face face, Point elePoint)
        {
            string err = "";

            int[]       pre   = draInfo.DraModel.Eles[0].EleInfo.Preparation;
            List <Edge> xEdge = new List <Edge>();
            List <Edge> yEdge = new List <Edge>();

            this.draInfo.GetEdge(face, out xEdge, out yEdge);
            Point3d dimPt = new Point3d(originPt.X, originPt.Y - (pre[1] * scale / 2 + 10), 0);

            if (xEdge.Count == 0)
            {
                return;
            }
            NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionVertical(topView, dimPt, xEdge[0], elePoint, ref err);
            if (dim != null)
            {
                Basic.DrawingUtils.SetDimensionPrecision(dim, 1);
            }
        }
        /// <summary>
        /// 设定视图竖直标注
        /// </summary>
        /// <param name="topView"></param>
        /// <param name="originPt"></param>
        /// <param name="scale"></param>
        /// <param name="workPoint"></param>
        /// <param name="elePoint"></param>
        private void ProViewDimension(DraftingView topView, double scale, Point3d originPt, Point workPoint, List <Point> elePoint)
        {
            string  err = "";
            Matrix4 mat = model.GetWorkMatr();

            // Point3d originPt = topView.GetDrawingReferencePoint();
            PointSort(ref elePoint, mat, "Z");
            double zTemmp = 0;
            int    z      = 0;

            for (int i = 0; i < elePoint.Count; i++)
            {
                Point3d zPt = elePoint[i].Coordinates;
                mat.ApplyPos(ref zPt);
                if (i == 0)
                {
                    zTemmp = zPt.Z;
                }
                if (UMathUtils.IsEqual(zTemmp, zPt.Z) && i != 0)
                {
                    continue;
                }
                Point3d dimPt = new Point3d(originPt.X - (disPt.X * scale + 8 * (z + 1)), originPt.Y + 10, 0);
                try
                {
                    NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionVertical(topView, dimPt, workPoint, elePoint[0], ref err);
                    if (dim != null)
                    {
                        Basic.DrawingUtils.AppendedTextDim(dim, "EDM SETTING");
                        SetDimColor(dim);
                    }
                    z++;
                }

                catch (NXException ex)
                {
                    ClassItem.WriteLogFile(model.AssembleName + "设定视图竖直标注错误!" + ex.Message);
                }
            }
        }
Exemplo n.º 23
0
    // private static UI theUI = null;



    public static string GetDimensionValue(NXOpen.Annotations.Dimension dimension)
    {
        try
        {
            string[] mainTextLines;
            string[] dualTextLines;
            dimension.GetDimensionText(out mainTextLines, out dualTextLines);
            if (mainTextLines.Length > 0)
            {
                //这里可能包含特殊字符,从中得到连续数字
                string num = GetNumberFromString(mainTextLines[0]);
                return(num);
            }
            else
            {
                return(null);
            }
        }
        catch    /* (System.Exception ex)*/
        {
            throw new Exception("读取尺寸值失败,请手动指定尺寸值");
        }
    }
Exemplo n.º 24
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;
        }
    }
Exemplo n.º 25
0
 public void settoldown(NXOpen.Annotations.Dimension dim, double down)//这个方法用来设定一个尺寸的上下公差
 {
     //dim.UpperMetricToleranceValue = up;
     dim.LowerMetricToleranceValue = down;
 }
Exemplo n.º 26
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);
    }
        /// <summary>
        /// 设定视图水平标注
        /// </summary>
        /// <param name="topView"></param>
        /// <param name="originPt"></param>
        /// <param name="scale"></param>
        /// <param name="workPoint"></param>
        /// <param name="elePoint"></param>
        private void TopDimension(DraftingView topView, double scale, Point3d originPt, Point workPoint, List <Point> elePoint)
        {
            string err = "";

            Matrix4 mat = model.GetWorkMatr();

            // Point3d originPt = topView.GetDrawingReferencePoint();
            PointSort(ref elePoint, mat, "X");
            double xTemmp = 0;
            int    x      = 0;

            for (int i = 0; i < elePoint.Count; i++)
            {
                Point3d xPt = elePoint[i].Coordinates;
                mat.ApplyPos(ref xPt);
                if (i == 0)
                {
                    xTemmp = xPt.X;
                }
                if (UMathUtils.IsEqual(xTemmp, xPt.X) && i != 0)
                {
                    continue;
                }
                Point3d dimPt = new Point3d(originPt.X + 10.0, originPt.Y + disPt.Y * scale + (10 * (x + 1)), 0);
                try
                {
                    NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionHorizontal(topView, dimPt, workPoint, elePoint[i], ref err);
                    if (dim != null)
                    {
                        Basic.DrawingUtils.AppendedTextDim(dim, "EDM SETTING");
                        SetDimColor(dim);
                    }
                    x++;
                }
                catch (NXException ex)
                {
                    ClassItem.WriteLogFile(model.AssembleName + "设定视图水平标注错误!" + ex.Message);
                }
            }
            PointSort(ref elePoint, mat, "Y");
            double yTemmp = 0;
            int    y      = 0;

            for (int i = 0; i < elePoint.Count; i++)
            {
                Point3d yPt = elePoint[i].Coordinates;
                mat.ApplyPos(ref yPt);
                if (i == 0)
                {
                    yTemmp = yPt.Y;
                }
                if (UMathUtils.IsEqual(yTemmp, yPt.Y) && i != 0)
                {
                    continue;
                }
                Point3d dimPt = new Point3d(originPt.X - (this.disPt.X * scale + 8 * (y + 1)), originPt.Y + 10, 0);
                try
                {
                    NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionVertical(topView, dimPt, workPoint, elePoint[i], ref err);
                    if (dim != null)
                    {
                        Basic.DrawingUtils.AppendedTextDim(dim, "EDM SETTING");
                        SetDimColor(dim);
                    }
                    y++;
                }
                catch (NXException ex)
                {
                    ClassItem.WriteLogFile(model.AssembleName + "设定竖直标注错误!" + ex.Message);
                }
            }
        }