private void setLoftTerminalTo(string name) { IFeature fov = fieldOfView.FeatureByName("field of view"); ILoftFeatureData fieldOfViewLoft = (ILoftFeatureData)fov.GetDefinition(); fieldOfViewLoft.AccessSelections(swDoc, fieldOfView); Object[] fovProfiles = fieldOfViewLoft.Profiles; IFeature sizedSketch = fieldOfView.FeatureByName(name); IFeature originalSketch = fovProfiles[0] as IFeature; IFeature[] newProfiles = new IFeature[] { fovProfiles[0] as IFeature, sizedSketch }; fieldOfViewLoft.Profiles = newProfiles; fov.ModifyDefinition(fieldOfViewLoft, swDoc, fieldOfView); fieldOfViewLoft.ReleaseSelectionAccess(); swDoc.EditRebuild3(); swAssembly.EditAssembly(); }
public static void AddMate(SldWorks swApp, ModelDoc2 Doc, string newpartpath) { #region 添加部件 swApp.OpenDoc(newpartpath, 1); ((AssemblyDoc)Doc).AddComponent5(newpartpath, 0, "", false, "", 0, 0.3, 0); swApp.CloseDoc(newpartpath); #endregion Component2 BaseComp = ((AssemblyDoc)Doc).GetComponentByName("底座-1"); Component2 RoateComp = ((AssemblyDoc)Doc).GetComponentByName("转轴-1"); int err = 0; #region 轴装配 Feature BaseAxi = BaseComp.FeatureByName("基准轴1"); Feature RoateAxi = RoateComp.FeatureByName("转轴中心轴"); BaseAxi.Select(false); RoateAxi.Select(true); ((AssemblyDoc)Doc).AddMate5((int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out err); #endregion #region 底面装配距离 Feature BaseBp = BaseComp.FeatureByName("Top"); Feature RoateBp = RoateComp.FeatureByName("Top"); BaseBp.Select(false); RoateBp.Select(true); ((AssemblyDoc)Doc).AddMate5((int)swMateType_e.swMateDISTANCE, (int)swMateAlign_e.swMateAlignALIGNED, false, 10 / 1000.0, 10 / 1000.0, 10 / 1000.0, 0, 0, 0, 0, 0, false, false, 0, out err); #endregion #region 方位装配 Feature BaseOir = BaseComp.FeatureByName("Right"); Feature RoateOir = RoateComp.FeatureByName("Right"); BaseOir.Select(false); RoateOir.Select(true); ((AssemblyDoc)Doc).AddMate5((int)swMateType_e.swMateANGLE, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, (30 / 180.0) * Math.PI, (30 / 180.0) * Math.PI, (30 / 180.0) * Math.PI, false, false, 0, out err); #endregion Doc.EditRebuild3(); }
public Extrusion(Component2 belongsTo, Camera camera, SldWorks swApp, ModelDoc2 swDoc, AssemblyDoc swAssembly, FeatureManager swFeatureMgr) { IFeature extrusionFeature = belongsTo.FeatureByName("flag"); if (extrusionFeature == null) { Utilities.alert("this component has no extrudeable feature"); return; } this.belongsTo = belongsTo; this.extrusion = (Feature)extrusionFeature; this.camera = camera; setDefaultDepth(); this.swApp = swApp; this.swDoc = swDoc; this.swAssembly = swAssembly; this.swFeatureMgr = swFeatureMgr; }
public Boolean FiltreFonctionRepetition(Object SelBox, Object selection, int selType, String itemText) { EffacerContraintes(); if (selType == (int)swSelectType_e.swSelBODYFEATURES) { Feature f = selection as Feature; if (f.GetTypeName2() == FeatureType.swTnCurvePattern) { SelectContraintes(); return(true); } } else { try { Face2 face = selection as Face2; Body2 b = face.GetBody(); Entity e = face as Entity; Component2 c = e.GetComponent(); String cNomFonc = _pFonctionRepet.GetValeur <String>(); Feature F = b.eChercherFonction(f => { return(Regex.IsMatch(f.Name, cNomFonc)); }, false); if (F.IsNull()) { F = b.eChercherFonction(f => { return(f.GetTypeName2() == FeatureType.swTnCurvePattern); }, false); } F = c.FeatureByName(F.Name); SelectFonctionRepetition((CtrlSelectionBox)SelBox, F); } catch (Exception e) { this.LogMethode(new Object[] { e }); } } return(false); }
// Renvoi le plan de contrainte "Plan de face" private Feature PlanContrainte(Component2 composant) { return(composant.FeatureByName("Plan de face")); //return composant.eChercherFonction("Plan de face", false); }
private InfoForMate FindMinTopTable(LinkedList<Component2> swComponents, Component2 swAddedComp, bool? isLeft) { bool status; InfoForMate minDistance = new InfoForMate(double.MaxValue, null, null); InfoForMate currentDistance1 = null, currentDistance2 = null; foreach (Component2 component in swComponents) { bool isAnglePart, isUpPart, isTabletop, isKtExist; var swCompModel = (ModelDoc2)component.GetModelDoc(); if (swCompModel == null) continue; isKtExist = GetTypeProperty(swCompModel.GetCustomInfoValue("", "KitchenType"), out isAnglePart, out isUpPart, out isTabletop); if (!isKtExist) continue; if (isUpPart || !isTabletop) continue; if (component.Name == swAddedComp.Name) continue; swModel.ClearSelection(); //пересекает ли эта столешница столешницу к которой мы хотим прикрепится. bool isIntersect = false; status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfЗадняя", swAddedComp.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateleft, component.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); isIntersect = (measure.NormalDistance <= 0.002 && measure.NormalDistance != -1) || measure.IsIntersect; if (!isIntersect) { swModel.ClearSelection(); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfЗадняя", swAddedComp.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateright, component.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); isIntersect = (measure.NormalDistance <= 0.002 && measure.NormalDistance != -1) || measure.IsIntersect; } if (!isIntersect) continue; swModel.ClearSelection(); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateleft, swAddedComp.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfПередняя", component.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (minDistance.distance > measure.Distance && measure.Distance != -1 && measure.IsParallel) currentDistance1 = new InfoForMate(measure.Distance, component.FeatureByName("#swrfПередняя"), swAddedComp.FeatureByName(plateright)); swModel.ClearSelection(); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateright, swAddedComp.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfПередняя", component.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (minDistance.distance > measure.Distance && measure.Distance != -1 && measure.IsParallel) currentDistance2 = new InfoForMate(measure.Distance, component.FeatureByName("#swrfПередняя"), swAddedComp.FeatureByName(plateleft)); if (currentDistance1 != null && currentDistance2 != null) { if ((bool)isLeft && currentDistance1.distance > currentDistance2.distance) minDistance = currentDistance1; else if (!(bool)isLeft && currentDistance1.distance < currentDistance2.distance) minDistance = currentDistance2; } else { if (currentDistance1 != null) minDistance = currentDistance1; if (currentDistance2 != null) minDistance = currentDistance2; } } return minDistance; }
private InfoForMate FindMaxPlate(LinkedList<Component2> swComponents, Component2 swAddedComp, Component2 firstComponent, double origaverx, double origaverz, bool isAnglePartFirst, bool? isLeft) { InfoForMate maxDistance = new InfoForMate(double.MinValue, null, null); bool status; string firstPlateLeft = plateleft; string firstPlateRight = plateright; if (isAnglePartFirst) { firstPlateLeft = "#swrfЗадняя2"; firstPlateRight = "#swrfЗадняя2"; } InfoForMate currentDistance1 = null, currentDistance2 = null; bool isAnglePart, isUpPart, isTabletop, isKtExist; foreach (Component2 component in swComponents) { currentDistance1 = null; currentDistance2 = null; var swCompModel = (ModelDoc2)component.GetModelDoc(); if (swCompModel == null) continue; isKtExist = GetTypeProperty(swCompModel.GetCustomInfoValue("", "KitchenType"), out isAnglePart, out isUpPart, out isTabletop); if (!isKtExist) continue; if (isUpPart || isTabletop) continue; if (component.Name == swAddedComp.Name) continue; //if (component.Name == firstComponent.Name) // continue; swModel.ClearSelection(); //сначала проверка на удаленность /*double[] currentBox = component.GetBox(true, true); double averx = Math.Min(currentBox[3], currentBox[0]) + Math.Abs(currentBox[3] - currentBox[0]) / 2; double averz = Math.Min(currentBox[5], currentBox[2]) + Math.Abs(currentBox[5] - currentBox[2]) / 2; double a = Math.Abs(averx - origaverx); double b = Math.Abs(averz - origaverz); double c = Math.Sqrt(a * a + b * b) * 1000; if (c > 4000) continue;*/ swModel.ClearSelection(); //тут проверить что она у той же стенки string swrfBackAngle = "#swrfЗадняя2"; if (component.Name != firstComponent.Name) { status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfЗадняя", firstComponent.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfЗадняя", component.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if ((!measure.IsIntersect || !measure.IsParallel) && !isAnglePart) continue; if (isAnglePart && (!measure.IsParallel || !measure.IsIntersect)) { swModel.ClearSelection(); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfЗадняя", firstComponent.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", swrfBackAngle, component.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (!measure.IsIntersect || !measure.IsParallel) continue; else swrfBackAngle = "#swrfЗадняя"; } } swModel.ClearSelection(); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", firstPlateLeft, firstComponent.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateright, component.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (!measure.IsParallel && !isAnglePart) continue; if (isAnglePart) //&& !measure.IsParallel) { swModel.ClearSelection(); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", firstPlateLeft, firstComponent.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", swrfBackAngle, component.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (measure.Distance != -1 && measure.IsParallel) currentDistance1 = new InfoForMate(measure.Distance, component.FeatureByName(swrfBackAngle), firstComponent.FeatureByName(firstPlateLeft)); } else { //if (measure.Distance != -1) currentDistance1 = new InfoForMate(measure.Distance, component.FeatureByName(plateright), firstComponent.FeatureByName(firstPlateLeft)); } swModel.ClearSelection(); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", firstPlateRight, firstComponent.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateleft, component.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (!measure.IsParallel && !isAnglePart) continue; if (isAnglePart) //&& !measure.IsParallel) { swModel.ClearSelection(); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", firstPlateRight, firstComponent.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", swrfBackAngle, component.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (measure.Distance != -1 && measure.IsParallel) currentDistance2 = new InfoForMate(measure.Distance, component.FeatureByName(swrfBackAngle), firstComponent.FeatureByName(firstPlateRight)); } else { //if (measure.Distance != -1) currentDistance2 = new InfoForMate(measure.Distance, component.FeatureByName(plateleft), firstComponent.FeatureByName(firstPlateRight)); } if (component.Name == firstComponent.Name) { if ((bool)isLeft) { if (currentDistance1 != null && maxDistance.distance < currentDistance1.distance) maxDistance = currentDistance1; } else { if (currentDistance1 != null && maxDistance.distance < currentDistance2.distance) maxDistance = currentDistance2; } } else { if (currentDistance1 != null && currentDistance2 != null) { if ((bool)isLeft && currentDistance1.distance >= currentDistance2.distance && maxDistance.distance < currentDistance1.distance) maxDistance = currentDistance1; else if (!(bool)isLeft && currentDistance1.distance <= currentDistance2.distance && maxDistance.distance < currentDistance2.distance) maxDistance = currentDistance2; } else { if (currentDistance1 != null && maxDistance.distance < currentDistance1.distance) maxDistance = currentDistance1; if (currentDistance2 != null && maxDistance.distance < currentDistance2.distance) maxDistance = currentDistance2; } } } return maxDistance; }
public void TableTopProcess(Component2 swAddedComp) { var mates = swAddedComp.GetMates(); Component2 firstComponent = null; var swAddedCompModel = (ModelDoc2)swAddedComp.GetModelDoc(); bool? isLeft = null; if (swAddedCompModel.GetCustomInfoValue("", "KitchenType").Contains("левая")) isLeft = true; else if (swAddedCompModel.GetCustomInfoValue("", "KitchenType").Contains("правая")) isLeft = false; if (isLeft == null) return; if (mates != null) { foreach (var mate in mates) { if (mate is Mate2) { var spec = (Mate2)mate; int mec = spec.GetMateEntityCount(); if (mec > 1) { for (int ik = 0; ik < mec; ik++) { MateEntity2 me = spec.MateEntity(ik); if (me.ReferenceComponent.Name.Contains(swAddedComp.Name)) { string firstComp = spec.MateEntity(0).ReferenceComponent.Name.Split('/')[0]; swAddin.GetComponentByName(RootModel, firstComp, false, out firstComponent); break; } } } } } } if (firstComponent != null) { //привязать... swAddin.AddMate(RootModel, firstComponent.FeatureByName("#swrfЗадняя"), swAddedComp.FeatureByName("#swrfЗадняя"), true); } bool status; var swComponents = new LinkedList<Component2>(); if (swAddin.GetComponents(swRootComponent, swComponents, false, false)) { double[] origBox = swAddedComp.GetBox(true, true); double origaverx = Math.Min(origBox[3], origBox[0]) + Math.Abs(origBox[3] - origBox[0]) / 2; double origaverz = Math.Min(origBox[5], origBox[2]) + Math.Abs(origBox[5] - origBox[2]) / 2; var swCompModel = (ModelDoc2)firstComponent.GetModelDoc(); bool isAnglePartFirst = false, isUpPartfirst = false, isTabletopFirst = false; if (swCompModel != null) GetTypeProperty(swCompModel.GetCustomInfoValue("", "KitchenType"), out isAnglePartFirst, out isUpPartfirst, out isTabletopFirst); if (isTabletopFirst || isUpPartfirst) return; string tmp = (bool)isLeft ? "#swrfЛевая" : "#swrfПравая"; if (isAnglePartFirst) swAddin.AddMate(RootModel, firstComponent.FeatureByName("#swrfЗадняя2"), swAddedComp.FeatureByName(tmp), true); else swAddin.AddMate(RootModel, firstComponent.FeatureByName(tmp), swAddedComp.FeatureByName(tmp), true); InfoForMate maxDistance = FindMinTopTable(swComponents, swAddedComp, isLeft); InfoForMate maxDistance3 = FindMaxPlate(swComponents, swAddedComp, firstComponent, origaverx, origaverz, isAnglePartFirst, isLeft); if (maxDistance.planeDist != null && maxDistance.planeSource != null && maxDistance3.distance > maxDistance.distance)//&& maxDistance3.planeSource.Name == maxDistance.planeSource.Name) { swModel.ClearSelection(); InfoForMate maxDistance2 = new InfoForMate(double.MinValue, null, null); string tt = isAnglePartFirst ? "#swrfЗадняя2" : plateleft; status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", tt, firstComponent.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); maxDistance.planeDist.Select(true); measure.Calculate(null); if (measure.IsParallel && maxDistance2.distance < measure.Distance) maxDistance2 = new InfoForMate(measure.Distance, firstComponent.FeatureByName(tt), null); swModel.ClearSelection(); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateright, firstComponent.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); maxDistance.planeDist.Select(true); measure.Calculate(null); if (measure.IsParallel && maxDistance2.distance < measure.Distance) maxDistance2 = new InfoForMate(measure.Distance, firstComponent.FeatureByName(plateright), null); //if (maxDistance2.planeDist!=null) // swAddin.AddMate(swModel, maxDistance2.planeDist, maxDistance.planeSource, true);//distToTopTable = new InfoForMate(maxDistance.distance, maxDistance2.planeDist, maxDistance.planeSource);// swModel.ClearSelection(); maxDistance.planeDist.Select(false); maxDistance2.planeDist.Select(true); measure.Calculate(null); maxDistance.distance = measure.Distance; } else { maxDistance = maxDistance3;//maxDistance = FindMaxPlate(swComponents, swAddedComp, firstComponent, origaverx, origaverz,isAnglePartFirst); //if (maxDistance.planeDist != null && maxDistance.planeSource != null) //{ // if (maxDistance.planeSource.Name != "#swrfЗадняя2") // swAddin.AddMate(swModel, maxDistance.planeSource, swAddedComp.FeatureByName(maxDistance.planeSource.Name), true); // else // { // maxDistance.planeSource.Select(false); // swAddedComp.FeatureByName(plateleft).Select(true); // measure.Calculate(null); // double distanceleft = measure.Distance; // maxDistance.planeSource.Select(false); // swAddedComp.FeatureByName(plateright).Select(true); // measure.Calculate(null); // double distanceright = measure.Distance; // if (distanceleft<distanceright) // swAddin.AddMate(swModel, maxDistance.planeSource, swAddedComp.FeatureByName(plateleft), true); // else // swAddin.AddMate(swModel, maxDistance.planeSource, swAddedComp.FeatureByName(plateright), true); // } //} } double distance2; swModel.ClearSelection(); if (!isAnglePartFirst) status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "Передняя", firstComponent.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); else status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateleft, firstComponent.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfЗадняя", firstComponent.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); distance2 = measure.Distance * 1000; //поменять размер.. var curModel = swAddedComp.GetModelDoc2(); bool isNumber = false; OleDbConnection oleDb; OleDbDataReader rd; List<string> strObjNames = new List<string>(); string filePath = swAddedComp.GetPathName(); if (swAddin.OpenModelDatabase(curModel, out oleDb)) { using (oleDb) { OleDbCommand cm; cm = isNumber ? new OleDbCommand( "SELECT * FROM objects WHERE number>0 ORDER BY number", oleDb) : new OleDbCommand("SELECT * FROM objects ORDER BY id", oleDb); rd = cm.ExecuteReader(); while (rd.Read()) { if (rd["caption"].ToString() == null || rd["caption"].ToString() == "" || rd["caption"].ToString().Trim() == "") continue; string strObjName = rd["name"].ToString(); if (filePath.Contains("_SWLIB_BACKUP")) { string pn = Path.GetFileNameWithoutExtension(filePath); string last3 = pn.Substring(pn.Length - 4, 4); string[] arr = strObjName.Split('@'); if (arr.Length != 3) throw new Exception("что-то не так"); arr[2] = Path.GetFileNameWithoutExtension(arr[2]) + last3 + Path.GetExtension(arr[2]); strObjName = string.Format("{0}@{1}@{2}", arr[0], arr[1], arr[2]); } strObjNames.Add(strObjName); } } } swAddin.SetObjectValue(curModel, strObjNames[0], 14, maxDistance.distance * 1000); swAddin.SetObjectValue(curModel, strObjNames[1], 14, distance2); } }
public InfoForMate GetSimilarTables(Component2 swComp2, bool isUpPart, bool isAnglePartOrig) { var swComponents = new LinkedList<Component2>(); InfoForMate minDistance = new InfoForMate(double.MaxValue, null, null); string origplateright = plateright; string origplateleft = plateleft; if (isAnglePartOrig) { origplateright = "#swrfПраваяЗадняя"; origplateleft = "#swrfЛеваяЗадняя"; } if (swAddin.GetComponents(swRootComponent, swComponents, false, false)) { double[] origBox = swComp2.GetBox(true, true); double origaverx = Math.Min(origBox[3], origBox[0]) + Math.Abs(origBox[3] - origBox[0]) / 2; double origaverz = Math.Min(origBox[5], origBox[2]) + Math.Abs(origBox[5] - origBox[2]) / 2; foreach (Component2 component in swComponents) { bool isAnglePart, isDistUpPart, isTabletop, isKtExist; var swCompModel = (ModelDoc2)component.GetModelDoc(); if (swCompModel == null) continue; isKtExist = GetTypeProperty(swCompModel.GetCustomInfoValue("", "KitchenType"), out isAnglePart, out isDistUpPart, out isTabletop); if (!isKtExist) continue; if (isTabletop) continue; if (isDistUpPart != isUpPart) continue; double[] currentBox = component.GetBox(true, true); double averx = Math.Min(currentBox[3], currentBox[0]) + Math.Abs(currentBox[3] - currentBox[0]) / 2; double averz = Math.Min(currentBox[5], currentBox[2]) + Math.Abs(currentBox[5] - currentBox[2]) / 2; double a = Math.Abs(averx - origaverx); double b = Math.Abs(averz - origaverz); double c = Math.Sqrt(a * a + b * b) * 1000; if (c > 4000) continue; string compName = component.Name2; if (compName.Contains("Замер") || compName == swComp2.Name) continue; bool bb = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfЗадняя", compName, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); bb = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfЗадняя", swComp2.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (!(measure.IsIntersect && measure.IsParallel)) { if (isAnglePart) { bb = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfЗадняя2", compName, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); bb = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfЗадняя", swComp2.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (!(measure.IsIntersect && measure.IsParallel)) continue; } else continue; } swModel.ClearSelection(); bb = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateright, compName, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); bb = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", origplateleft, swComp2.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (!measure.IsParallel && !isAnglePart) continue; if (minDistance.distance > measure.Distance && measure.IsParallel) { minDistance = new InfoForMate(measure.Distance, component.FeatureByName(plateright), swComp2.FeatureByName(origplateleft)); if (isAnglePart) { swModel.ClearSelection(); bb = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateright, compName, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); bb = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", origplateright, swComp2.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (minDistance.distance > measure.Distance && measure.IsParallel) { minDistance = new InfoForMate(measure.Distance, component.FeatureByName(plateright), swComp2.FeatureByName(origplateright)); } } } bb = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateleft, compName, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); bb = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", origplateright, swComp2.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (!measure.IsParallel) continue; if (minDistance.distance > measure.Distance) { minDistance = new InfoForMate(measure.Distance, component.FeatureByName(plateleft), swComp2.FeatureByName(origplateright)); if (isAnglePart) { swModel.ClearSelection(); bb = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateleft, compName, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); bb = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", origplateleft, swComp2.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (minDistance.distance > measure.Distance && measure.IsParallel) { minDistance = new InfoForMate(measure.Distance, component.FeatureByName(plateleft), swComp2.FeatureByName(origplateleft)); } } } } } return minDistance; }
public InfoForMate GetPointsMate(Component2 swComp2, Component2 mainComponent, bool isAnglePartOrig) { bool status = false; InfoForMate minDistance = new InfoForMate(double.MaxValue, null, null); //status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateleft, swComp2.Name, rootName), "PLANE", 0, 0, 0, false, 0, null, 0); //status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateright, swComp2.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); //measure.Calculate(null); List<string> goodPoints = new List<string>(); for (int i = 1; i < 40; i++) { status = RootModel.Extension.SelectByID2(string.Format("Точка{0}@{1}@{2}", i.ToString(), mainComponent.Name, rootName), "DATUMPOINT", 0, 0, 0, false, 0, null, 0); if (!status) { if (RootModel.Extension.SelectByID2(string.Format("Точка{0}@{1}@{2}", (i + 1).ToString(), mainComponent.Name, rootName), "DATUMPOINT", 0, 0, 0, false, 0, null, 0)) continue; else break; } status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfЗадняя", swComp2.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (measure.IsIntersect || measure.NormalDistance < 0.00001) goodPoints.Add(string.Format("Точка{0}@{1}@{2}", i.ToString(), mainComponent.Name, rootName)); } minDistance = new InfoForMate(double.MaxValue, null, null); foreach (var point in goodPoints) { if (isAnglePartOrig) { status = RootModel.Extension.SelectByID2(point, "DATUMPOINT", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", "#swrfЗадняя2", swComp2.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (measure.Distance != -1) { if (measure.Distance < minDistance.distance) minDistance = new InfoForMate(measure.Distance, mainComponent.FeatureByName(point.Split('@')[0]), swComp2.FeatureByName("#swrfЗадняя2")); } } else { status = RootModel.Extension.SelectByID2(point, "DATUMPOINT", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateleft, swComp2.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (measure.Distance != -1) { if (measure.Distance < minDistance.distance) minDistance = new InfoForMate(measure.Distance, mainComponent.FeatureByName(point.Split('@')[0]), swComp2.FeatureByName(plateleft)); } RootModel.ClearSelection(); status = RootModel.Extension.SelectByID2(point, "DATUMPOINT", 0, 0, 0, false, 0, null, 0); status = RootModel.Extension.SelectByID2(string.Format("{0}@{1}@{2}", plateright, swComp2.Name, rootName), "PLANE", 0, 0, 0, true, 0, null, 0); measure.Calculate(null); if (measure.Distance != -1) { if (measure.Distance < minDistance.distance) minDistance = new InfoForMate(measure.Distance, mainComponent.FeatureByName(point.Split('@')[0]), swComp2.FeatureByName(plateright)); } } } return minDistance; }
protected override void Command() { Ass = MdlBase.eAssemblyDoc(); try { CurveDrivenPatternFeatureData def = FonctionRepetition.GetDefinition(); Object[] tabB = def.PatternBodyArray; Body2 b = (Body2)tabB[0]; MathTransform compRepetTrans = ComposantRepetition.Transform2; MathTransform baseMarcheTrans = Marche.Transform2; Vertex v = (Vertex)Point; Edge e = (Edge)Arrete; List <Face2> ListeFace = FonctionRepetition.eListeDesFaces(); Sketch sk = PointMarche.GetSketch(); Feature fPointMarche = (Feature)sk; List <Component2> ListeComposants = new List <Component2>() { Marche }; Double arr = 0.0001; for (int i = 1; i <= (def.D1InstanceCount + def.D2InstanceCount); i++) { MathTransform bodyTrans = def.GetTransform(i); if (bodyTrans.IsNull()) { break; } MathTransform Transform = compRepetTrans.Inverse(); Transform = Transform.Multiply(bodyTrans); Transform = Transform.Multiply(compRepetTrans); Transform = baseMarcheTrans.Multiply(Transform); gPoint pt = new gPoint(v); gSegment sg = new gSegment(e); pt.MultiplyTransfom(bodyTrans); sg.MultiplyTransfom(bodyTrans); Vertex vertex = null; Edge edge = null; foreach (Face2 face in ListeFace) { foreach (Edge ed in face.eListeDesArretes()) { gSegment s = new gSegment(ed); if (sg.Compare(s, arr)) { edge = ed; } if (s.Start.Comparer(pt, arr)) { vertex = ed.GetStartVertex(); } if (s.End.Comparer(pt, arr)) { vertex = ed.GetEndVertex(); } if (edge.IsRef() && vertex.IsRef()) { break; } } if (edge.IsRef() && vertex.IsRef()) { break; } } Entity eVertex = (Entity)vertex; Entity eEdge = (Entity)edge; Component2 cp = Ass.AddComponent5(Marche.GetPathName(), (int)swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, "", false, "", 0, 0, 0); if (cp.IsNull()) { continue; } // Quand on réinsere un composant, les précédentes contraintes sont recrées. // On les supprime pour eviter des conflits Object[] Mates = cp.GetMates(); if (Mates.IsRef()) { foreach (Feature mate in Mates) { mate.eSelect(); MdlBase.Extension.DeleteSelection2((int)swDeleteSelectionOptions_e.swDelete_Absorbed); } } WindowLog.Ecrire(cp.Name2); cp.Transform2 = Transform; ListeComposants.Add(cp); int longstatus = 0; MdlBase.eEffacerSelection(); eVertex.eSelectEntite(false); Feature f = cp.FeatureByName(fPointMarche.Name); Sketch sketchOrigine = f.GetSpecificFeature2(); Object[] tabPt = sketchOrigine.GetSketchPoints2(); SketchPoint origine = (SketchPoint)tabPt[0]; origine.Select4(true, null); Mate2 mPoint = Ass.AddMate5((int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignCLOSEST, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out longstatus); MdlBase.eEffacerSelection(); MdlBase.eEffacerSelection(); eEdge.eSelectEntite(false); cp.FeatureByName(AxeMarche.Name).eSelect(true); Mate2 mAxe = Ass.AddMate5((int)swMateType_e.swMateANGLE, (int)swMateAlign_e.swAlignNONE, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out longstatus); MdlBase.eEffacerSelection(); MdlBase.eEffacerSelection(); Plan.eSelect(false); cp.FeatureByName(PlanMarche.Name).eSelect(true); Mate2 mPlan = Ass.AddMate5((int)swMateType_e.swMatePARALLEL, (int)swMateAlign_e.swAlignNONE, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out longstatus); MdlBase.eEffacerSelection(); Feature m = (Feature)mPoint; WindowLog.Ecrire(" " + m.Name); m = (Feature)mAxe; WindowLog.Ecrire(" " + m.Name); m = (Feature)mPlan; WindowLog.Ecrire(" " + m.Name); } MdlBase.eEffacerSelection(); foreach (var cp in ListeComposants) { cp.eSelectById(MdlBase, -1, true); } Feature Dossier = MdlBase.FeatureManager.InsertFeatureTreeFolder2((int)swFeatureTreeFolderType_e.swFeatureTreeFolder_Containing); Dossier.eRenommerFonction(String.Format("Marches ({0} {1}) ", ComposantRepetition.Name2, FonctionRepetition.Name)); } catch (Exception e) { this.LogErreur(new Object[] { e }); } }
// Renvoi le plan de contrainte "Plan de face" private Feature PlanDeFace(Component2 composant) { return(composant.FeatureByName("Plan de face")); }