private void DesactiverContrainte(Component2 cp) { List <Mate2> Liste = cp.eListeContraintes(true); foreach (Mate2 M in Liste) { Feature F = M as Feature; F.eSelectionnerById2(_MdlBase); _MdlBase.EditSuppress2(); } _MdlBase.ClearSelection2(true); }
// Строит или изменяет модель public void Build() { InitAndRunSwApp(); // имена размеров в документе полумуфты string fingerParameter1 = "fingers@Круговой массив1"; string fingerParameter2 = "fingers@Круговой массив2"; string nomianalDiameterParameter = "nominalDiameter@Эскиз1"; // имя полумуфты в сборке (имя компонента верхнего уровня) string assemblyPolumuftaName = "Полумуфта-1"; // Менеджер выделения, выбора SelectionMgr swSelMgr = (SelectionMgr)swModel.SelectionManager; // удалить выделение swModel.ClearSelection2(true); Component2 swComp = assembly.GetComponentByName(assemblyPolumuftaName); // выбрать полумуфту, не добавлять к выбранным, дата?, показать всплывающее кокшко swComp.Select4(false, null, false); int info = 0; // начать изменение полумуфты assembly.EditPart2(false, false, ref info); // получить редактируемую модель ModelDoc2 polumufta = (ModelDoc2)assembly.GetEditTarget(); // установка изменяемых параметров для всех конфигураций polumufta.Parameter(fingerParameter1).SetSystemValue3( countFingers, (int)swSetValueInConfiguration_e.swSetValue_InAllConfigurations ); polumufta.Parameter(fingerParameter2).SetSystemValue3( countFingers, (int)swSetValueInConfiguration_e.swSetValue_InAllConfigurations ); polumufta.Parameter(nomianalDiameterParameter).SetSystemValue3( nominalDiameter, (int)swSetValueInConfiguration_e.swSetValue_InAllConfigurations ); // ?? bool retVal = polumufta.EditSuppress2(); //Debug.Assert(retVal); // ?? assembly.EditAssembly(); swModel.EditRebuild3(); swModel.ForceRebuild3(false); swModel.ViewZoomtofit2(); }
private bool SuppressFolder(Feature swFeature, ModelDoc2 model, int value) { //bool inFolder = true; //do //{ // if (model.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY) // { // Component2 cp = ((AssemblyDoc)model).GetComponentByName(swFeature.Name); // if (cp != null) // { // cp.SetSuppression2(value == 0 ? 0 : 2); // } // } // swFeature.SetSuppression(value); // swFeature = swFeature.GetNextFeature() as Feature; // if (swFeature.GetTypeName() == "FtrFolder") // { // inFolder = false; // } //} while (swFeature != null && inFolder); bool sup = false; if (value == 1) { sup = true; } bool boolstatus = false; boolstatus = model.Extension.SelectByID2(swFeature.Name, "FTRFOLDER", 0, 0, 0, sup, 0, null, 0); if (sup) { model.EditUnsuppress2(); } else { model.EditSuppress2(); } model.ClearSelection2(true); return(true); }
public int[] interferenceDir(SldWorks swApp, ModelDoc2 swModel, Feature swMateFeat, MateEntity2[] swMateEnt) { // Initiate variables MathUtility swMathUtil = default(MathUtility); AssemblyDoc swAssembly = default(AssemblyDoc); ModelDocExtension swModelDocExt = default(ModelDocExtension); DragOperator swDragOp = default(DragOperator); MathTransform swXform = default(MathTransform); Feature swSubFeat = default(Feature); Component2 swComp0 = default(Component2); Component2 swComp1 = default(Component2); SelectionMgr swSelMgr = default(SelectionMgr); Component2[] EntityArray; bool supstat = false; bool bRet = false; int i = 0; int j = 0; int k = 0; double[] dir; double[] entityParameters = new double[8]; int[] swAssyDir = new int[6]; double[] trans = new double[16]; // Get accesss to the model swModelDocExt = swModel.Extension; // Suppressing mates to be able to move them swSubFeat = (Feature)swMateFeat.GetFirstSubFeature(); while ((swSubFeat != null)) { supstat = swModelDocExt.SelectByID2(swSubFeat.Name, "MATE", 0, 0, 0, false, 0, null, 0); supstat = swModel.EditSuppress2(); swSubFeat = (Feature)swSubFeat.GetNextSubFeature(); } // Get parts swComp0 = swMateEnt[0].ReferenceComponent; swComp1 = swMateEnt[1].ReferenceComponent; // Run .stl meshing function save.saveAs(swApp, swComp0, swComp1, swModelDocExt); // Define variables swAssembly = (AssemblyDoc)swModel; swDragOp = (DragOperator)swAssembly.GetDragOperator(); swMathUtil = (MathUtility)swApp.GetMathUtility(); swSelMgr = swModel.SelectionManager; EntityArray = new Component2[] { swComp0, swComp1 }; // Decide parameters for DragOperator interface bRet = swDragOp.AddComponent(swComp1, false); bRet = swDragOp.CollisionDetection(EntityArray, true, true); swDragOp.CollisionDetectionEnabled = true; swDragOp.DynamicClearanceEnabled = false; swDragOp.UseAbsoluteTransform = false; swDragOp.IgnoreComplexSurfaces = true; swDragOp.HearClashes = false; swDragOp.HighlightClashes = false; swDragOp.TransformType = 0; swDragOp.DragMode = 0; // Begin moving component bRet = swDragOp.BeginDrag(); for (i = 0; i < 6; i++) { if (i == 0) { dir = new double[] { 0.005, 0, 0 } } ; else if (i == 1) { dir = new double[] { -0.005, 0, 0 } } ; else if (i == 2) { dir = new double[] { 0, 0.005, 0 } } ; else if (i == 3) { dir = new double[] { 0, -0.005, 0 } } ; else if (i == 4) { dir = new double[] { 0, 0, 0.005 } } ; else { dir = new double[] { 0, 0, -0.005 } }; // Move up to five steps along vector (dir) for (j = 0; j < 5; j++) { trans = new double[] { 1, 0, 0, 0, 1, 0, 0, 0, 1, dir[0], dir[1], dir[2], 1, 0, 0, 0 }; swXform = (MathTransform)swMathUtil.CreateTransform(trans); bRet = swDragOp.Drag(swXform); // Check return status of interference detector k = j + 1; if (bRet == true) { swAssyDir[i] = 1; } else { swAssyDir[i] = 0; break; } } // Move back the number of steps moved if (swAssyDir[i] == 1) { trans[9] = trans[9] * (-k); trans[10] = trans[10] * (-k); trans[11] = trans[11] * (-k); swXform = (MathTransform)swMathUtil.CreateTransform(trans); bRet = swDragOp.Drag(swXform); } } bRet = swDragOp.EndDrag(); // Unsuppress mates swSubFeat = (Feature)swMateFeat.GetFirstSubFeature(); while ((swSubFeat != null)) { supstat = swModelDocExt.SelectByID2(swSubFeat.Name, "MATE", 0, 0, 0, false, 0, null, 0); supstat = swModel.EditUnsuppress2(); swSubFeat = (Feature)swSubFeat.GetNextSubFeature(); } // Return interference vector return(swAssyDir); } }
public string Build(RoofType_e type, int width, int lenght, bool onlyPath) { string newPartPath = string.Empty; string modelName; switch (type) { case RoofType_e.One: case RoofType_e.Two: case RoofType_e.Three: case RoofType_e.Four: case RoofType_e.Five: case RoofType_e.Six: modelName = "15-000"; break; default: modelName = "15-000"; break; } string newRoofName = "15-0" + type + "-" + width + "-" + lenght; string newRoofPath = $@"{RootFolder}{SubjectDestinationFolder}\{newRoofName}.SLDASM"; bool IsExistPart = false; CheckExistPart(newRoofName + ".SLDASM", out IsExistPart, out newRoofPath); var modelRoofPath = $@"{RootFolder}{SourceFolder}\{modelName}.SLDASM"; solidWorksDocument = SolidWorksAdapter.SldWoksAppExemplare.OpenDoc6(modelRoofPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_LoadModel + (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "00", 0, 0); AssemblyDoc solidWorcsAssemvlyDocyment = (AssemblyDoc)solidWorksDocument; solidWorcsAssemvlyDocyment.ResolveAllLightWeightComponents(false); DeleteComponents((int)type); #region Сохранение и изменение элементов var addwidth = 100; var addwidth2 = 75; var type4 = 0; var divwidth = 1; if (type == RoofType_e.Two || type == RoofType_e.Six) { addwidth = 75; divwidth = 2; } if (type == RoofType_e.Four) { type4 = 170; addwidth2 = 170 + 75; } var widthD = (Convert.ToDouble(width) / divwidth + addwidth); var lengthD = (Convert.ToDouble(lenght) - 28.5); const double step = 200; const double step2 = 150; var weldW = Convert.ToDouble((Math.Truncate(Convert.ToDouble(lenght) / step) + 1)); var weldW2 = Convert.ToDouble((Math.Truncate(Convert.ToDouble(lenght) / step2) + 1)); var newComponents = new List <FileInfo>(); //15-001 SolidWorksAdapter.SldWoksAppExemplare.IActivateDoc2("15-001", true, 0); var newPartName = $"15-0{type}-01-{width}-{lenght}"; CheckExistPart(newPartName, out IsExistPart, out newPartPath); if (IsExistPart) { solidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2("15-000.SLDASM", true, 0))); solidWorksDocument.Extension.SelectByID2("15-001-1@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0); solidWorcsAssemvlyDocyment.ReplaceComponents(newPartPath, "", true, true); SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("15-001.SLDPRT"); } else { newPartPath = $@"{SourceFolder}\{SubjectDestinationFolder}\{newPartName}.SLDPRT"; //EditPartParameters("15-001", // $@"{RootFolder}\{SubjectDestinationFolder}\{newPartName}", // new[,] // { // {"D1@Эскиз1", type == RoofType.Five || type == RoofType.Six ? Convert.ToString(140 + lengthD + type4) : Convert.ToString(lengthD + type4)}, // {"D2@Эскиз1", Convert.ToString(widthD)}, // {"D4@Эскиз27", Convert.ToString(addwidth2-4.62)}, // {"D1@Эскиз27", Convert.ToString(90)}, // {"D2@Эскиз27", Convert.ToString((75-4.62))}, // {"D1@Эскиз24", type == RoofType.Five || type == RoofType.Six? Convert.ToString(149.53) : Convert.ToString(9.53)}, // {"D1@Кривая2", Convert.ToString(weldW2*1000)}, // {"D1@Кривая1", Convert.ToString(weldW*1000)} // } ); try { VentsMatdll(new[] { "1700" }, new[] { "", "Шаргень", "2" }, newPartName); } catch (Exception e) { Patterns.Observer.MessageObserver.Instance.SetMessage(e.ToString()); } SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(newPartName); } //15-002 if (type == RoofType_e.Six) { try { SolidWorksAdapter.SldWoksAppExemplare.IActivateDoc2("15-002", true, 0); newPartName = $"15-0{type}-02-{width}-{lenght}"; CheckExistPart(newPartName, out IsExistPart, out newPartPath); if (IsExistPart) { solidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2("15-000.SLDASM", true, 0))); solidWorksDocument.Extension.SelectByID2("15-002-1@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0); solidWorcsAssemvlyDocyment.ReplaceComponents(newPartPath, "", true, true); SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("15-002.SLDPRT"); } else { newPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{newPartName}.SLDPRT"; //EditPartParameters("15-002", // $@"{RootFolder}\{SubjectDestinationFolder}\{newPartName}", // new[,] // { // {"D1@Эскиз1", type == RoofType.Five || type == RoofType.Six ? Convert.ToString(140 + lengthD + type4) : Convert.ToString(lengthD + type4)}, // {"D2@Эскиз1", Convert.ToString(widthD)}, // {"D4@Эскиз27", Convert.ToString(addwidth2-4.62)}, // {"D1@Эскиз27", Convert.ToString(90)}, // {"D2@Эскиз27", Convert.ToString((75-4.62))}, // {"D2@Эскиз23", type == RoofType.Five || type == RoofType.Six ? Convert.ToString(165) : Convert.ToString(25)}, // {"D1@Кривая2", Convert.ToString(weldW2*1000)}, // {"D1@Кривая1", Convert.ToString(weldW*1000)} // } ); try { VentsMatdll(new[] { "1700" }, new[] { "", "Шаргень", "2" }, newPartName); } catch (Exception e) { //MessageBox.Show(e.ToString()); } SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(newPartName); } solidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2("15-000.SLDASM", true, 0))); solidWorksDocument.Extension.SelectByID2("15-001-3@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0); solidWorksDocument.Extension.SelectByID2("ЗеркальныйКомпонент2@15-000", "COMPPATTERN", 0, 0, 0, false, 0, null, 0); solidWorksDocument.EditSuppress2(); } catch (Exception e) { Patterns.Observer.MessageObserver.Instance.SetMessage(e.ToString()); } } else if (type != RoofType_e.Six) { solidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2("15-000.SLDASM", true, 0))); solidWorksDocument.Extension.SelectByID2("15-002-1@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0); solidWorksDocument.EditDelete(); } switch (type) { case RoofType_e.Two: case RoofType_e.Six: solidWorksDocument.Extension.SelectByID2("Винт самосверл 6-гр.гол с шайбой-33@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0); solidWorksDocument.EditDelete(); break; default: solidWorksDocument.Extension.SelectByID2("Винт самосверл 6-гр.гол с шайбой-26@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0); solidWorksDocument.EditDelete(); break; } #endregion // GabaritsForPaintingCamera(SolidWorksDocument); try { solidWorksDocument.ForceRebuild3(true); //Console.WriteLine("newRoofPath " + newRoofPath); solidWorksDocument.SaveAs2(newRoofPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); newComponents.Add(new FileInfo(newRoofPath)); SolidWorksAdapter.CloseAllDocumentsAndExit(); // PDMWebService.Data.PDM.SolidWorksPdmAdapter.Instance.CheckInOutPdm(newComponents, true); //Console.WriteLine("RoofBuilder строка 324 пересмотреть CheckInOutPdm"); foreach (var newComponent in ComponentsPathList) { // ExportXmlSql.Export(newComponent.FullName); } } catch (Exception ex) { Patterns.Observer.MessageObserver.Instance.SetMessage(ex.ToString()); } if (onlyPath) { return(newRoofPath); } //MessageBox.Show(newRoofPath, "Модель построена"); return(newRoofPath); }