// (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"); }
///<summary> method <c>GetDrawingDocBOMTable</c> ///从SolidWorks 的Drawing文档获取到其材料明细表,一般一个文档一个,多余不获取 ///</summary> public void GetDrawingDocBOMTable(ModelDoc2 modelDoc, out BomTableAnnotation swBOMTable, out string configName, out string topFileName) { Feature feature = modelDoc.IFirstFeature(); swBOMTable = null; configName = ""; topFileName = ""; BomFeature swBomFeat = null; while (feature != null) { Type type = feature.GetType(); if ("BomFeat" == feature.GetTypeName()) { //Console.WriteLine("******************************"); //Console.WriteLine("Feature Name : " + feature.Name); swBomFeat = (BomFeature)feature.GetSpecificFeature2(); break; } string name = feature.Name; feature = feature.IGetNextFeature(); } if (swBomFeat == null || swBomFeat.GetTableAnnotationCount() <= 0) { return; } Feature swFeat = (Feature)swBomFeat.GetFeature(); string featureName = swFeat.Name; swBOMTable = swBomFeat.IGetTableAnnotations(1);// default(TableAnnotation); topFileName = swBomFeat.GetReferencedModelName(); int configCount = swBomFeat.GetConfigurationCount(true); // //object[] vTableArr = (object[])swBomFeat.GetTableAnnotations(); //foreach (object vTable_loopVariable in vTableArr) //{ // object vTable = vTable_loopVariable; // TableAnnotation swTable = (TableAnnotation)vTable; // ProcessTableAnn(modelDoc, swTable); //} configName = ""; if (configCount > 0) { bool visibility = true; configName = swBomFeat.IGetConfigurations(true, 0, ref visibility); } //swBOMTable.Iget return; }
// Returns a List object containing each sketch as a Feature, from a given Solidworks ModelDoc2 private List <Feature> EnumerateSketchesInSolidworksPart(ModelDoc2 thisModel) { if (thisModel == null) { ShowNonFatalError("** Error: thisModel is NULL! Something's wrong..."); return(null); } Console.WriteLine("Enumerating all sketches in model '{0}'...", thisModel.GetTitle()); List <Feature> listOfSketches = new List <Feature>(); Feature currentFeature = default(Feature); int numParentFeatures = 0; // Loop through all features in 'thisModel' currentFeature = thisModel.IFirstFeature(); while (currentFeature != null) { numParentFeatures++; if (currentFeature.GetTypeName2() == "ProfileFeature") // If child is type Sketch { // Gather properties of sketch //GetSketchDetails(currentFeature); thisModel.ClearSelection2(true); // Clear all previous entity/item selections in Solidworks // 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; } } currentFeature = currentFeature.GetNextFeature(); } Console.WriteLine("Got " + listOfSketches.Count + " sketches from this model"); return(listOfSketches); }
///<summary> method <c>GetDrawingDocBOMTable</c> ///从SolidWorks 的Drawing文档获取到其材料明细表,一般一个文档一个,多余不获取 ///</summary> public void GetDrawingDocBOMTable(ModelDoc2 modelDoc, out BomTableAnnotation swBOMTable, out string configName, out string topFileName) { Feature feature = modelDoc.IFirstFeature(); swBOMTable = null; configName = ""; BomFeature swBomFeat = null; while (feature != null) { Type type = feature.GetType(); if ("BomFeat" == feature.GetTypeName()) { Console.WriteLine("******************************"); Console.WriteLine("Feature Name : " + feature.Name); swBomFeat = (BomFeature)feature.GetSpecificFeature2(); break; } string name = feature.Name; feature = feature.IGetNextFeature(); } if (swBomFeat == null || swBomFeat.GetTableAnnotationCount() <= 0) { return; } swBOMTable = swBomFeat.IGetTableAnnotations(1);// default(TableAnnotation); topFileName = swBomFeat.GetReferencedModelName(); configName = ""; if (configCount > 0) { bool visibility = true; configName = swBomFeat.IGetConfigurations(true, 0, ref visibility); } //swBOMTable.Iget return; }