// Open "Edit Sketch" and make sketch Normal-To (ctrl+8 shortcut) given the Feature private bool OpenSketchNormalToByName(string sketchName) { // Exit out of any opened sketches if (currentModel.SketchManager.ActiveSketch != null) { currentModel.InsertSketch2(true); } ModelDocExtension swModelDocExt = default(ModelDocExtension); swModelDocExt = currentModel.Extension; bool selected = swModelDocExt.SelectByID2(sketchName, "SKETCH", 0, 0, 0, false, 0, null, 0); if (!selected) { ShowNonFatalError("Failed to select sketch '" + sketchName + "'"); return(false); } // Open sketch for editing ("Edit Sketch" in Solidworks UI) currentModel.EditSketchOrSingleSketchFeature(); // Run the 'Normal-To' view command if (RunNormalToSketchCommand() != 0) { return(false); } return(true); }
// (UNUSED, for future reference) Loops through all sketches in a given ModelDoc2 model public void iterate_each_sketch_in_model(ModelDoc2 thisModel) { Console.WriteLine("Iterating through all sketches in this model..."); if (thisModel == null) { Console.WriteLine("** Error: thisModel is NULL! Something's wrong..."); } Feature currentFeature = default(Feature); int numParentFeatures = 0; int numSketches = 0; currentFeature = thisModel.IFirstFeature(); List <Feature> listOfSketches = new List <Feature>(); // Loop through all features in 'thisModel' while (currentFeature != null) { numParentFeatures++; if (currentFeature.GetTypeName2() == "ProfileFeature") // If child is type Sketch { // Gather properties of sketch Console.WriteLine("Iterating through parentFeature" + numParentFeatures + " ('" + currentFeature.Name + "') in this model..."); GetConstrainedStatus(currentFeature); // Clear all previous selections thisModel.ClearSelection2(true); // Select the current sketch (we verified this feature is a sketch) if (currentFeature.Select2(false, 0)) { Console.WriteLine("Successfully selected Sketch ('" + currentFeature.Name + "')"); listOfSketches.Add(currentFeature); } else { Console.WriteLine(" ** ERROR: Failed to select Sketch ('" + currentFeature.Name + "')"); break; } // Edit the (previously selected) sketch Console.WriteLine(" Editing sketch......"); thisModel.EditSketchOrSingleSketchFeature(); // Run the 'Normal-To' view command RunNormalToSketchCommand(); // Exit out of "Edit Sketch" and rebuild thisModel.InsertSketch2(true); } currentFeature = currentFeature.GetNextFeature(); if (currentFeature == null) { Console.WriteLine("Failed to get next feature! (GetNextFeature() is NULL)"); } } Console.WriteLine("Got " + numSketches + " sketches from this model"); }