private void TreeViewJointtreeAfterSelect(object sender, TreeViewEventArgs e)
        {
            Font fontRegular = new Font(treeViewJointTree.Font, FontStyle.Regular);
            Font fontBold    = new Font(treeViewJointTree.Font, FontStyle.Bold);

            if (previouslySelectedNode != null && !previouslySelectedNode.IsBaseNode)
            {
                SaveJointDataFromPropertyBoxes(previouslySelectedNode.Link.Joint);
            }
            if (previouslySelectedNode != null)
            {
                previouslySelectedNode.NodeFont = fontRegular;
            }
            LinkNode node = (LinkNode)e.Node;

            ActiveSWModel.ClearSelection2(true);
            SelectionMgr manager = ActiveSWModel.SelectionManager;

            SelectData data = manager.CreateSelectData();

            data.Mark = -1;
            foreach (Component2 component in node.Link.SWComponents)
            {
                component.Select4(true, data, false);
            }
            node.NodeFont = fontBold;
            node.Text     = node.Text;
            FillJointPropertyBoxes(node.Link.Joint);
            previouslySelectedNode = node;
        }
Пример #2
0
        //Selects components from a list.
        public static void selectComponents(ModelDoc2 model, List <Component2> components, bool clearSelection = true, int mark = -1)
        {
            if (clearSelection)
            {
                model.ClearSelection2(true);
            }
            SelectionMgr manager = model.SelectionManager;
            SelectData   data    = manager.CreateSelectData();

            data.Mark = mark;
            foreach (Component2 component in components)
            {
                component.Select4(true, data, false);
            }
        }
Пример #3
0
        //Selects the components of a link. Helps highlight when the associated node is
        // selected from the tree
        public static void SelectComponents(ModelDoc2 model, Link Link, bool clearSelection, int mark = -1)
        {
            if (clearSelection)
            {
                model.ClearSelection2(true);
            }
            SelectionMgr manager = model.SelectionManager;
            SelectData   data    = manager.CreateSelectData();

            data.Mark = mark;
            SelectComponents(model, Link.SWComponents, false);
            foreach (Link child in Link.Children)
            {
                SelectComponents(model, child, false, mark);
            }
        }
Пример #4
0
        public Feature[] AddTMPBasePlaneFromSelectFace()
        {
            Feature[] tempFeatures = new Feature[2];
            //连接到Solidworks

            ModelDoc2 swModel = (ModelDoc2)iSwApp.ActiveDoc;

            //设定标注尺寸时 不输入值
            iSwApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate, false);

            // Get the pre-selected planar face
            Face2        swSelFace = default(Face2);
            SelectionMgr swSelMgr  = (SelectionMgr)swModel.SelectionManager;

            //获取选择数据
            SelectData swSelData = default(SelectData);

            swSelData = swSelMgr.CreateSelectData();

            swSelFace = (Face2)swSelMgr.GetSelectedObject6(1, 1);

            //var ps = swSelFace.GetTessTriStrips(false);

            //获取屏幕鼠标选择的那个点
            var mousePoint = (double[])swSelMgr.GetSelectionPoint2(1, 1);

            List <Edge> thisFaceEdgeList = GetSelectFaceEdgeList(swSelFace);

            swModel.ViewZoomtofit2();

            Entity swSelFaceEntity = (Entity)swSelFace;

            string skFirstName = "";

            tempFeatures[0] = DrawnSketchOnFace(swModel, mousePoint, thisFaceEdgeList, swSelFaceEntity, out skFirstName);

            var t = (double[])swSelFace.Normal;

            swModel.ClearSelection2(true);

            swSelFaceEntity.Select4(false, swSelData);

            return(tempFeatures);
        }
Пример #5
0
        //Selects the components of a link. Helps highlight when the associated node is selected from the tree
        public static void selectComponents(ModelDoc2 model, link Link, bool clearSelection, int mark = -1)
        {
            if (clearSelection)
            {
                model.ClearSelection2(true);
            }
            SelectionMgr manager = model.SelectionManager;
            SelectData   data    = manager.CreateSelectData();

            data.Mark = mark;
            if (Link.SWComponent != null)
            {
                Link.SWComponent.Select4(true, data, false);
            }
            else
            {
                selectComponents(model, Link.SWcomponents, false);
            }
            foreach (link child in Link.Children)
            {
                selectComponents(model, child, false, mark);
            }
        }
        private void treeView_linkProperties_AfterSelect(object sender, TreeViewEventArgs e)
        {
            Font fontRegular = new Font(treeView_jointtree.Font, FontStyle.Regular);
            Font fontBold    = new Font(treeView_jointtree.Font, FontStyle.Bold);

            if (previouslySelectedNode != null)
            {
                saveLinkDataFromPropertyBoxes(previouslySelectedNode.Link);
                previouslySelectedNode.NodeFont = fontRegular;
            }
            LinkNode node = (LinkNode)e.Node;

            node.NodeFont = fontBold;
            node.Text     = node.Text;
            ActiveSWModel.ClearSelection2(true);
            SelectionMgr manager = ActiveSWModel.SelectionManager;



            SelectData data = manager.CreateSelectData();

            data.Mark = -1;
            if (node.Link.SWComponent != null)
            {
                node.Link.SWComponent.Select4(false, data, false);
            }
            else
            {
                foreach (Component2 component in node.Link.SWcomponents)
                {
                    component.Select4(true, data, false);
                }
            }
            fillLinkPropertyBoxes(node.Link);
            treeView_linkProperties.Focus();
            previouslySelectedNode = node;
        }
Пример #7
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);
            }
        }
Пример #8
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);
        }
Пример #9
0
        public void AddFeature(SldWorks SwApp, ModelDoc2 SwModel, Point2D P1, Point2D P2)
        {
            if (CheckUsing() == false)
            {
                return;
            }

            SwModel.ClearSelection2(true);

            object[] seating_types    = new[] { "None", "Prismatic A", "Prismatic B", "Segmented" };
            object[] operations_types = new[] { "None", "Chamfer", "Fillet" }; // array of operation names
            Helper   helper           = new Helper(SwModel, SwApp);

            FeatureManager featureManager = SwModel.FeatureManager;
            SketchManager  sketchManager  = SwModel.SketchManager;
            SelectionMgr   selectionMgr   = (SelectionMgr)SwModel.SelectionManager;
            Entity         ent            = default(Entity);
            Array          facesArray     = default(Array);
            Array          edgesArray     = default(Array);
            Feature        swFeature      = default(Feature);
            Face2          face2          = default(Face2); // neds to get edges of selected face
            double         LStage         = 0;
            double         x_center       = 0;
            double         y_center       = 0;
            double         L      = 0;
            double         W      = 0;
            bool           append = false;

            LStage   = P2.x - P1.x;                         // length of current stage
            x_center = P1.x + (LStage / 2) + seatingOffset; // center of current stage
            y_center = 0;
            L        = x_center + seatingLength / 2;
            W        = seatingWidth / 2;


            SwModel.ClearSelection2(true);

            #region                              // make prismatic A keyseat

            if (seatingType == seating_types[1]) //Prismatic A
            {
                helper.select_feature("RefPlane", 1, false, 0);
                SwModel.CreatePlaneAtOffset(P1.y, false);
                sketchManager.InsertSketch(true);

                sketchManager.CreateCenterRectangle(x_center, y_center, 0, L, W, 0);
                SwModel.FeatureManager.FeatureCut3(true, false, false, 0, 0, seatingDepth, 0,
                                                   false, false, false, false, 0, 0, false, false, false, false, false, true, true, true, true,
                                                   false, 0, 0, false); // add cut feature

                if (seatingOpearationType != operations_types[0])       // add chamfer or fillet, if none or value is 0 - pass
                {
                    swFeature  = (Feature)selectionMgr.GetSelectedObject6(1, -1);
                    facesArray = (Array)swFeature.GetFaces();
                    ent        = facesArray.GetValue(0) as Entity;
                    ent.Select4(false, null);

                    if (seatingOpearationType == operations_types[1])
                    {
                        featureManager.InsertFeatureChamfer(4, 1, seatingChamferFilletValue, helper.ToRad(45), 0, 0, 0,
                                                            0);
                    }
                    if (seatingOpearationType == operations_types[2])
                    {
                        SwModel.FeatureManager.FeatureFillet(195, seatingChamferFilletValue, 0,
                                                             0, null, null, null);
                    }

                    swFeature = selectionMgr.GetSelectedObject6(1, -1);
                    swFeature.Select2(false, 4); //create selection for pattern
                    append = true;
                }


                CreatePattern(helper, append, SwModel, swFeature, selectionMgr);
            }

            #endregion

            #region                              // make prismatic B keyseat

            if (seatingType == seating_types[2]) //Prismatic B
            {
                W = seatingWidth;                //Width

                helper.select_feature("RefPlane", 1, false, 0);
                SwModel.CreatePlaneAtOffset(P1.y, false);
                sketchManager.InsertSketch(true);
                sketchManager.CreateSketchSlot((int)swSketchSlotCreationType_e.swSketchSlotCreationType_line,
                                               (int)swSketchSlotLengthType_e.swSketchSlotLengthType_CenterCenter, W, L - seatingLength, 0, 0, L, 0,
                                               0,
                                               0, 0, 0, 1, false);
                SwModel.FeatureManager.FeatureCut3(true, false, false, 0, 0, seatingDepth, 0,
                                                   false, false, false, false, 0, 0, false, false, false, false, false, true, true, true, true,
                                                   false, 0, 0, false);

                if (seatingOpearationType != operations_types[0]) // add chamfer or fillet, if none or value is 0 - pass
                {
                    swFeature  = (Feature)selectionMgr.GetSelectedObject6(1, -1);
                    facesArray = (Array)swFeature.GetFaces();
                    ent        = facesArray.GetValue(0) as Entity;
                    ent.Select4(false, null);

                    if (seatingOpearationType == operations_types[1])
                    {
                        featureManager.InsertFeatureChamfer(4, 1,
                                                            seatingChamferFilletValue, helper.ToRad(45), 0, 0, 0, 0);
                    }
                    if (seatingOpearationType == operations_types[2])
                    {
                        SwModel.FeatureManager.FeatureFillet(195, seatingChamferFilletValue, 0,
                                                             0, null, null, null);
                    }


                    swFeature = selectionMgr.GetSelectedObject6(1, -1);
                    swFeature.Select2(false, 4); //create selection for pattern
                    append = true;
                }


                CreatePattern(helper, append, SwModel, swFeature, selectionMgr);
            }

            #endregion

            #region                              // make segmented seatkey

            if (seatingType == seating_types[3]) //Segmented
            {
                helper.select_feature("RefPlane", 0, false, 0);
                sketchManager.InsertSketch(true);
                sketchManager.Create3PointArc(L - seatingLength, P1.y, 0, L, P1.y, 0, x_center, (P1.y - seatingDepth), 0);
                sketchManager.CreateLine(L - seatingLength, P1.y, 0, L, P1.y, 0); //close sketsh
                SwModel.FeatureManager.FeatureCut3(true, false, false, 6, 0, (seatingWidth), 0,
                                                   false, false, false, false, 0, 0, false, false, false, false, false, true, true, true, true,
                                                   false, 0, 0, false); //cut from mide plane

                if (SeatingOpearationType != operations_types[0])       // add chamfer or fillet, if nono or value is 0 - pass
                {
                    // select edges for chamfering or filleting
                    swFeature  = (Feature)selectionMgr.GetSelectedObject6(1, -1);
                    facesArray = (Array)swFeature.GetFaces();
                    SelectData selectData = selectionMgr.CreateSelectData();
                    ent = facesArray.GetValue(2) as Entity;
                    ent.Select4(false, selectData);
                    face2      = selectionMgr.GetSelectedObject6(1, -1);
                    edgesArray = (Array)face2.GetEdges();
                    ent        = edgesArray.GetValue(0) as Entity;
                    ent.Select4(false, null);
                    ent = edgesArray.GetValue(2) as Entity;
                    ent.Select4(true, null);
                    // select edges for chamfering or filleting
                    //  MessageBox.Show("" + face2.GetEdgeCount());

                    if (seatingOpearationType == operations_types[1])
                    {
                        featureManager.InsertFeatureChamfer(4, 1, seatingChamferFilletValue, helper.ToRad(45), 0, 0, 0,
                                                            0);
                    }

                    if (seatingOpearationType == operations_types[2])
                    {
                        SwModel.FeatureManager.FeatureFillet(195, seatingChamferFilletValue, 0, 0, null, null, null);
                    }


                    swFeature = selectionMgr.GetSelectedObject6(1, -1);
                    swFeature.Select2(false, 4); //create selection for pattern
                    append = true;
                }

                CreatePattern(helper, append, SwModel, swFeature, selectionMgr);
            }

            #endregion

            helper.HidePlanes();
        }