Ejemplo n.º 1
0
        /// <summary>
        /// center align
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            if (swApp == null)
            {
                return;
            }
            double[] bodyBox = new double[6];

            PartDoc swPart = (PartDoc)swModel;

            object[] bodyArr = null;
            bodyArr = swPart.GetBodies2((int)swBodyType_e.swAllBodies, false);
            Body2 swBody = (Body2)bodyArr[0];

            bodyBox = swBody.GetBodyBox();
            double x1, y1, z1, x2, y2, z2;

            x1 = bodyBox[0];
            y1 = bodyBox[1];
            z1 = bodyBox[2];
            x2 = bodyBox[3];
            y2 = bodyBox[4];
            z2 = bodyBox[5];

            double xCenter, yCenter, xMove, yMove, zMove;

            xCenter = (x1 + x2) / 2;
            yCenter = (y1 + y2) / 2;
            xMove   = xCenter * -1;
            yMove   = yCenter * -1;
            if (z1 > z2)
            {
                zMove = z1;
            }
            else
            {
                zMove = -z2;
            }

            SelectionMgr swSelMgr  = default(SelectionMgr);
            SelectData   swSelData = default(SelectData);

            swSelMgr       = (SelectionMgr)swModel.SelectionManager;
            swSelData      = (SelectData)swSelMgr.CreateSelectData();
            swSelData.Mark = 1;
            bool bRet = swBody.Select2(true, swSelData);

            FeatureManager ftMgr = default(FeatureManager);

            ftMgr = swModel.FeatureManager;
            Feature ftMoveCopy = ftMgr.InsertMoveCopyBody2(xMove, yMove, zMove, 0, 0, 0, 0, 0, 0, 0, false, 1);

            double xSize, ySize, zSize;

            xSize = Math.Round(Math.Abs(x1 * 1000 - x2 * 1000), 6);
            ySize = Math.Round(Math.Abs(y1 * 1000 - y2 * 1000), 6);
            zSize = Math.Round(Math.Abs(z1 * 1000 - z2 * 1000), 6);
            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(INFOPATH, true))
            {
                string strInfo = PARTNAME + ","
                                 + xSize.ToString() + "," + ySize.ToString() + "," + zSize.ToString();
                sw.WriteLine(strInfo);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// xy align
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            if (swApp == null)
            {
                return;
            }
            PartDoc swPart = (PartDoc)swModel;

            //モデルを選択して移動/コピーフィーチャーを挿入
            SelectionMgr swSelMgr  = default(SelectionMgr);
            SelectData   swSelData = default(SelectData);
            Body2        swBody    = default(Body2);

            swSelMgr  = (SelectionMgr)swModel.SelectionManager;
            swSelData = (SelectData)swSelMgr.CreateSelectData();


            FeatureManager ftMgr = default(FeatureManager);

            ftMgr = swModel.FeatureManager;
            double transX, transY, transZ, transD, rotPX, rotPY, rotPZ, rotAX, rotAY, rotAZ;

            transX = 0;
            transY = 0;
            transZ = 0;
            transD = 0;
            rotPX  = 0;
            rotPY  = 0;
            rotPZ  = 0;
            rotAX  = 0;
            rotAY  = 0;
            rotAZ  = 0;
            int numCopies = 1;

            //選択面の法線ベクトルを取得
            Face2 swFace = default(Face2);

            double[] faceNormalVector = new double[3];

            //ここで面を選択しておくと、選択面がXY平面と水平になるように回転する。
            try
            {
                swFace = swSelMgr.GetSelectedObject6(1, -1);
            }catch
            {
                MessageBox.Show("select y face");
                return;
            }
            if (swFace == null)
            {
                MessageBox.Show("select y face");
                return;
            }
            faceNormalVector = swFace.Normal;

            double zComp = Math.Round(faceNormalVector[2], 6);

            if (zComp != 0)
            {
                //error
                MessageBox.Show("Select faces parallel to Z axis");
                return;
            }
            double[] xyV = new double[2];
            xyV[0] = Math.Round(faceNormalVector[0], 6);
            xyV[1] = Math.Round(faceNormalVector[1], 6);
            double[] yUnitV = new double[2] {
                0, 1
            };

            double xyAngle = GetAngle(xyV, yUnitV);

            rotAZ = xyAngle * Math.PI / 180;

            object[] bodyArr = null;
            bodyArr = swPart.GetBodies2((int)swBodyType_e.swAllBodies, false);

            swBody         = (Body2)bodyArr[0];
            swSelData.Mark = 1;
            bool bRet = swBody.Select2(true, swSelData);

            Feature ftMoveCopy = ftMgr.InsertMoveCopyBody2(transX, transY, transZ, transD,
                                                           rotPX, rotPY, rotPZ, rotAZ, rotAY, rotAX, false, numCopies);
        }