Exemplo n.º 1
0
        // Pre
        public override void TranslateC2T(MECMOD.Shape cShape)
        {
            PARTITF.Hole hole = (PARTITF.Hole)cShape;

            double diameter     = 0.0;
            double depth        = 0.0;
            double bottomAngle  = 180.0;
            double headDiameter = 0.0;
            double headAngle    = 0.0;
            double headDepth    = 0.0;

            object[] org = new object[3];
            hole.GetOrigin(org);

            diameter = hole.Diameter.Value;
            depth    = hole.BottomLimit.Dimension.Value;

            if (hole.BottomType == PARTITF.CatHoleBottomType.catVHoleBottom)
            {
                bottomAngle = hole.BottomAngle.Value;
            }

            if (hole.Type == PARTITF.CatHoleType.catCounterboredHole)
            {
                headDiameter = hole.HeadDiameter.Value;
                headDepth    = hole.HeadDepth.Value;

                PartManager.tFeatures.AddNewSolidHoleCounterboredFeature(hole.get_Name(), GetTargetFace(hole), (double)org[0], (double)org[1], (double)org[2], headDiameter / 2, headDepth, diameter / 2, depth - headDepth, bottomAngle);
            }
            else if (hole.Type == PARTITF.CatHoleType.catCountersunkHole)
            {
                headDepth = hole.HeadDepth.Value;
                headAngle = hole.HeadAngle.Value;

                headDiameter = diameter + 2 * Math.Tan(headAngle / 2 * Math.PI / 180) * headDepth;

                PartManager.tFeatures.AddNewSolidHoleCountersunkFeature(hole.get_Name(), GetTargetFace(hole), (double)org[0], (double)org[1], (double)org[2], diameter / 2, depth, headDiameter / 2, headAngle, bottomAngle);
            }
            else if (hole.Type == PARTITF.CatHoleType.catSimpleHole)
            {
                PartManager.tFeatures.AddNewSolidHoleSimpleFeature(hole.get_Name(), GetTargetFace(hole), (double)org[0], (double)org[1], (double)org[2], diameter / 2, depth);
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            DRAFTINGITF.DrawingDocument DrwDoc  = null;
            DRAFTINGITF.DrawingView     DrwView = null;

            try
            {
                DrwDoc = (DRAFTINGITF.DrawingDocument)catia.ActiveDocument;
            }
            catch (Exception)
            {
                MessageBox.Show("please open a DrawingDocument");
                return;
            }

            DRAFTINGITF.DrawingRoot DrwRoot = DrwDoc.DrawingRoot;

            try
            {
                DrwView = DrwRoot.ActiveSheet.Views.Item(DrwRoot.ActiveSheet.Views.Count);
            }
            catch (Exception)
            {
                MessageBox.Show("sheet가 없습니다.");
                return;
            }
            DRAFTINGITF.DrawingViewGenerativeBehavior DrwGenBeh = DrwView.GenerativeBehavior;

            double X1, Y1, Z1, X2, Y2, Z2;

            DrwGenBeh.GetProjectionPlane(out X1, out Y1, out Z1, out X2, out Y2, out Z2);

            ProductStructureTypeLib.Product Prd    = (ProductStructureTypeLib.Product)DrwGenBeh.Document;
            MECMOD.PartDocument             PrtDoc = (MECMOD.PartDocument)Prd.ReferenceProduct.Parent;
            MECMOD.Part Prt = PrtDoc.Part;

            MECMOD.Body   Bdy  = Prt.MainBody;
            MECMOD.Shapes Shps = Bdy.Shapes;

            PARTITF.Hole tHole = (PARTITF.Hole)Shps.GetItem("Hole.1");
            object[]     opt   = new object[3];
            tHole.GetOrigin(opt);
            //radiuse
            //tHole.

            //3D 위치 값
            // double X = -37.935, Y = 96.8, Z = 104.207;
            double X = (double)opt[0];
            double Y = (double)opt[1];
            double Z = (double)opt[2];

            //결과 값
            double COS_ALPHA = 0, VW_H = 0, VW_V = 0;

            //계산과정
            COS_ALPHA = (X * X1 + Y * Y1 + Z * Z1) / ((Math.Pow(X1, 2) + Math.Pow(Y1, 2) + Math.Pow(Z1, 2)) * Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)));
            VW_H      = Math.Sqrt(X * X + Y * Y + Z * Z) * COS_ALPHA;

            COS_ALPHA = (X * X2 + Y * Y2 + Z * Z2) / ((Math.Pow(X2, 2) + Math.Pow(Y2, 2) + Math.Pow(Z2, 2)) * Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)));
            VW_V      = Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)) * COS_ALPHA;

            //create the point
            MECMOD.Factory2D fac = DrwView.Factory2D;
            fac.CreatePoint(VW_H, VW_V);

            //add a text (20정도 뛰어보자)

            DRAFTINGITF.DrawingText txt = DrwView.Texts.Add("Hole( " + (int)X + " , " + (int)Y + " , " + (int)Z + " )", VW_H + 20, VW_V - 20);
            // DRAFTINGITF.DrawingText txt = DrwView.Texts.Add(("( {0} , {1} , {2} )"X,Y,Z), VW_H + 20, VW_V - 20);
            txt.SetFontSize(0, 0, 12);

            DRAFTINGITF.DrawingLeader FDleadr = txt.Leaders.Add(VW_H, VW_V);

            //update the drawing document.
            DrwDoc.Update();
        }