예제 #1
0
        // Opens a Solidworks part, given a part TreeNode
        private bool OpenSketchFromNode(TreeNode sketchNode)
        {
            // Get custom SketchNodeInfo object from this node
            SketchNodeInfo sNodeInfo = (SketchNodeInfo)sketchNode.Tag;

            if (sNodeInfo == null)
            {
                ShowNonFatalError("Sketch node is missing SketchNodeInfo tag");
                return(false);
            }

            // Get the sketch feature from SketchNodeInfo
            string sketchName = sNodeInfo.SketchName;

            if (sketchName == null)
            {
                ShowNonFatalError("SketchNodeInfo is missing a Sketch Feature variable");
                return(false);
            }

            // Opens the part from sketch's parent node (if not already open)
            if (!OpenPartFromNode(sketchNode.Parent))
            {
                ShowNonFatalError("Failed to open part from sketch node's parent node");
                return(false);
            }

            // Clear all previous selections in part
            currentModel.ClearSelection2(true);

            // Open "Edit Sketch" and make sketch Normal-To (ctrl+8 shortcut)
            OpenSketchNormalToByName(sketchName);

            return(false);
        }
예제 #2
0
        // Adds child Sketch nodes to treeView1 node, given a TreeNode
        private void AddSketchesToPartNode(TreeNode partNode)
        {
            PartNodeInfo pNodeInfo = (PartNodeInfo)partNode.Tag;   // Retrieve the custom NodeInfo class from the node's Tag object

            ModelDoc2 currentModel = default(ModelDoc2);

            currentModel = GetSolidworksModelFromFile(pNodeInfo.FilePath);

            List <Feature> listOfSketches = new List <Feature>();

            listOfSketches = EnumerateSketchesInSolidworksPart(currentModel);

            if (listOfSketches == null)
            {
                ShowNonFatalError("Failed to get sketches from part '" + pNodeInfo.FileName + "'");
                return;
            }

            var sketchNode = new TreeNode();

            for (int i = 0; i < listOfSketches.Count; i++)
            {
                SketchNodeInfo sNodeInfo = new SketchNodeInfo(pNodeInfo, listOfSketches[i], i); // A custom class (ie. NodeInfo) to track the heirarchy of the Nodes
                sketchNode     = new TreeNode(sNodeInfo.Name);                                  // Make the Node title the file's name
                sketchNode.Tag = sNodeInfo;
                partNode.Nodes.Add(sketchNode);                                                 // Add this child file node under the student folder node
            }
        }