private void BollToPoint_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
            ReadType         = 2;
            Selection SelectArc = null;

            CATIA_Class.GetSelect(CatDocument, ref SelectArc, this);
            if (SelectArc == null || SelectArc.Count2 == 0)
            {
                return;
            }
            int ERR = 0;

            object[] PointCoord = new object[] { -99, -99, -99 };
            for (int i = 1; i <= SelectArc.Count2; i++)
            {
                HybridShapeFactory PartHyb         = (HybridShapeFactory)PartID.HybridShapeFactory;
                SPAWorkbench       TheSPAWorkbench = (SPAWorkbench)CatDocument.GetWorkbench("SPAWorkbench");
                Reference          referenceObject = SelectArc.Item(i).Reference;
                Measurable         TheMeasurable   = TheSPAWorkbench.GetMeasurable(referenceObject);
                TheMeasurable.GetPoint(PointCoord);     //读取选择的曲面坐标
                var TName = referenceObject.get_Name(); //读取选择的曲面名称
                HybridShapePointCoord NewPoint = PartHyb.AddNewPointCoord(Convert.ToDouble(PointCoord[0]), Convert.ToDouble(PointCoord[1]), Convert.ToDouble(PointCoord[2]));
                if (KeepName.Checked)
                {
                    NewPoint.set_Name(TName);
                }
                else
                {
                    NewPoint.set_Name("Rx_" + i);
                }
                HybridBodies Hybs = PartID.HybridBodies;
                HybridBody   Hyb  = null;
                try
                {
                    Hyb = Hybs.Item("几何图形集.1");
                }
                catch (Exception)
                {
                    Hyb = Hybs.Item("Geometrical Set.1");
                }
                Hyb.AppendHybridShape(NewPoint);
                PartID.InWorkObject = NewPoint;
                try
                {
                    PartID.Update();
                }
                catch (Exception)
                {
                    ERR += 1;
                }
            }
            if (ERR > 0)
            {
                MessageBox.Show("共计:" + ERR + "个点创建新参考点失败!");
            }
        }
Example #2
0
        enum RxHoleType { PinHole, NSmoothHole, ISmoothHole, ThreadHole }//PinHole销孔  NormarlSmoothHole 光孔 Inner SmoothHole 沉头孔  ThreadHole 螺纹孔

        /// <summary>
        /// 新增孔
        /// </summary>
        /// <param name="UserSelected">用户选择的3个参考</param>
        /// <param name="tform">父级窗体</param>
        /// <param name="AbortHole">是否对装配零件直接打孔</param>
        public void CreateNwThroughtHole(Reference[] UserSelected, Form tform, bool AbortHole, object[] UserSelectedValue)
        {
            object[] HolePoint = new object[3];
            Edge     ed1       = (Edge)UserSelected[0];
            Edge     ed2       = (Edge)UserSelected[1];

            if (CatActiveDoc == null)
            {
                InitCatEnv(tform);
            }
            SPAWorkbench TheSPAWorkbench = (SPAWorkbench)CatActiveDoc.GetWorkbench("SPAWorkbench");
            Measurable   LengthA         = TheSPAWorkbench.GetMeasurable(ed1);
            Measurable   LengthB         = TheSPAWorkbench.GetMeasurable(ed2);
            Edge         LengthEdge      = LengthA.Length >= LengthB.Length ? ed1 : ed2; //获取长边
            Edge         WeightEdge      = LengthA.Length <= LengthB.Length ? ed1 : ed2; //获取短边
            double       Weight          = LengthA.Length <= LengthB.Length ? LengthA.Length : LengthB.Length;
            double       Length          = LengthA.Length >= LengthB.Length ? LengthA.Length : LengthB.Length;
            double       JianDis         = 0;

            if (Length <= 45)
            {
                JianDis = 12.5;
            }
            else if (Length <= 60 && Length > 45)
            {
                JianDis = 15;
            }
            else if (Length > 60)
            {
                JianDis = 15;
            }
            GetProductByFace GPB          = new GetProductByFace();
            Part             Spart        = GPB.GetPart((Face)UserSelected[2]);
            ShapeFactory     shapeFactory = (ShapeFactory)Spart.ShapeFactory;
            Hole             Nwhole       = shapeFactory.AddNewHoleWith2Constraints(Convert.ToDouble(HolePoint[0]), Convert.ToDouble(HolePoint[1]), Convert.ToDouble(HolePoint[2]), UserSelected[0], UserSelected[1], UserSelected[2], 50);//创建过孔

            RxSetHoleType(Nwhole, 10, Weight / 2, 9, RxHoleType.NSmoothHole);
            Spart.Update();
            Hole NwPinHole = shapeFactory.AddNewHoleWith2Constraints(Convert.ToDouble(HolePoint[0]) + 5, Convert.ToDouble(HolePoint[1]) + 5, Convert.ToDouble(HolePoint[2]), UserSelected[0], UserSelected[1], UserSelected[2], 50);//创建销孔

            RxSetHoleType(NwPinHole, 10, Weight / 2 + JianDis, 8, RxHoleType.PinHole);
            Spart.Update();
            if (Length <= 60)
            {
                RectPattern RPhole = shapeFactory.AddNewRectPattern(Nwhole, 2, 1, JianDis * 2, 20, 1, 1, LengthEdge, WeightEdge, true, true, 0); //阵列过孔
                RPhole.FirstRectangularPatternParameters  = CatRectangularPatternParameters.catInstancesandSpacing;
                RPhole.SecondRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing;
                Spart.Update();
            }
            else
            {
                RectPattern RPhole = shapeFactory.AddNewRectPattern(Nwhole, 2, 1, JianDis * 2, 20, 1, 1, LengthEdge, WeightEdge, true, true, 0); //阵列过孔
                RPhole.FirstRectangularPatternParameters  = CatRectangularPatternParameters.catInstancesandSpacing;
                RPhole.SecondRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing;

                RectPattern RPinhole = shapeFactory.AddNewRectPattern(NwPinHole, 2, 1, JianDis * 2, 20, 1, 1, LengthEdge, WeightEdge, true, true, 0); //阵列过孔
                RPinhole.FirstRectangularPatternParameters  = CatRectangularPatternParameters.catInstancesandSpacing;
                RPinhole.SecondRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing;
                Spart.Update();
            }
            if (AbortHole)
            {
                CreateThreadHole(Spart, UserSelected, UserSelectedValue, WeightEdge, LengthEdge, Weight, Length, JianDis);
            }
        }