/// <summary> /// 选择后执行特定动作 /// </summary> /// <param name="comp"></param> /// <param name="action"></param> /// <param name="AfterDeSelect">执行完动作是否清除选择状态</param> public static void SelectFor(this IComponent2 comp, Action <IComponent2> action, bool AfterDeSelect = true) { comp.Select2(false, -1); action?.Invoke(comp); if (AfterDeSelect) { comp.DeSelect(); } }
internal static Color?GetColor(IComponent2 ownerComp, Func <swInConfigurationOpts_e, string[], double[]> getColorAction) { GetColorScope(ownerComp, out swInConfigurationOpts_e confOpts, out string[] confs); var matPrps = getColorAction.Invoke(confOpts, confs); return(FromMaterialProperties(matPrps)); }
internal static void GetColorScope(IComponent2 comp, out swInConfigurationOpts_e confOpts, out string[] confs) { confOpts = comp != null ? swInConfigurationOpts_e.swSpecifyConfiguration : swInConfigurationOpts_e.swThisConfiguration; confs = comp != null ? new string[] { comp.ReferencedConfiguration } : null; }
internal SwComponent(IComponent2 comp, SwAssembly parentAssembly) : base(comp) { m_ParentAssembly = parentAssembly; Component = comp; Children = new SwChildComponentsCollection(parentAssembly, comp); Features = new ComponentFeatureRepository(parentAssembly, comp); Bodies = new SwComponentBodyCollection(comp, parentAssembly); m_FilePathResolver = m_ParentAssembly.App.Services.GetService <IFilePathResolver>(); }
internal SwComponent(IComponent2 comp, SwAssembly rootAssembly) : base(comp) { m_RootAssembly = rootAssembly; Component = comp; Children = new SwChildComponentsCollection(rootAssembly, comp); m_Features = new Lazy <ISwFeatureManager>(() => new ComponentFeatureRepository(rootAssembly, comp)); Bodies = new SwComponentBodyCollection(comp, rootAssembly); m_FilePathResolver = m_RootAssembly.App.Services.GetService <IFilePathResolver>(); }
/// <summary> /// Obtains the components. /// </summary> /// <param name="swAssy">The SolidWorks assembly.</param> /// <returns>All child components.</returns> public static List <IComponent2> ObtainChildComponents(IAssemblyDoc swAssy) { // Obtain the root component var swModel = (IModelDoc2)swAssy; IConfiguration swConfiguration = swModel.GetActiveConfiguration(); IComponent2 swRootComp = swConfiguration.GetRootComponent3(true); // Build a list of all child components return(GetChildren(swRootComp)); }
public void Main() { try { IModelDoc2 model = swApp.IActiveDoc2; if (model != null) { string fileNameBase = ""; float[] tessTriangs; float[] tessNorms; if (model is IPartDoc) { fileNameBase = model.GetTitle(); GetTesselationDataFromPart(model as IPartDoc, out tessTriangs, out tessNorms); } else if (model is IAssemblyDoc) { IComponent2 comp = model.ISelectionManager.GetSelectedObjectsComponent3(1, -1) as IComponent2; if (comp != null) { GetTesselationData(comp, out tessTriangs, out tessNorms); fileNameBase = comp.GetPathName(); } else { throw new NullReferenceException("Please select component"); } } else { throw new NotSupportedException("Document type is not support, parts or assembly components are supported"); } string filePath = BrowseFile(Path.GetFileNameWithoutExtension(fileNameBase)); if (!string.IsNullOrEmpty(filePath)) { ExportToStl(filePath, tessTriangs, tessNorms, m_Transform); } } else { throw new NullReferenceException("Please open part or assembly"); } } catch (Exception ex) { swApp.SendMsgToUser2(ex.Message, (int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk); } }
/// <summary> /// 获取组件顶层的所有特征 /// </summary> /// <param name="comp"></param> /// <returns></returns> public static IEnumerable <IFeature> GetCompTopFeatures(this IComponent2 comp) { var feat = comp.FirstFeature(); while (feat != null) { yield return(feat); feat = feat.GetNextFeature() as Feature; } }
/// <summary> /// 直接返回转换类型的ModelDoc对象 /// </summary> /// <param name="comp"></param> /// <returns></returns> public static ModelDoc2 GetModelDoc2Ex(this IComponent2 comp) { try { return(comp.GetModelDoc2() as ModelDoc2); } catch (NullReferenceException) { throw; } }
/// <summary> /// 虚拟化 并且不修改名称 /// </summary> /// <param name="comp"></param> /// <returns></returns> public static bool MakeVirtualWithSameName(this IComponent2 comp) { string name = comp.Name2; bool res = comp.MakeVirtual(); if (res) { comp.Name2 = name; } return(res); }
/// <summary> /// 虚拟化 并且不修改名称 /// </summary> /// <param name="comp"></param> /// <param name="alseChildVirtual">子级是否虚拟化</param> /// <returns></returns> public static bool MakeVirtual2WithSameName(this IComponent2 comp, bool alseChildVirtual = false) { string name = comp.Name2; bool res = comp.MakeVirtual2(alseChildVirtual); if (res) { comp.Name2 = name; } return(res); }
/// <summary> /// 对所有子件操作 /// </summary> /// <param name="comp"></param> /// <param name="action"></param> public static void UsingChildren(this IComponent2 comp, Action <Component2> action) { var child = comp.GetChildren() as Component2[]; if (child != null) { foreach (var item in child) { action(item); } } }
internal SwComponent(IComponent2 comp, SwAssembly rootAssembly, ISwApplication app) : base(comp, rootAssembly, app) { m_RootAssembly = rootAssembly; Component = comp; Children = new SwChildComponentsCollection(rootAssembly, this); m_FeaturesLazy = new Lazy <ISwFeatureManager>(() => new SwComponentFeatureManager(this, rootAssembly, app)); m_DimensionsLazy = new Lazy <ISwDimensionsCollection>(() => new SwFeatureManagerDimensionsCollection(Features)); m_MathUtils = app.Sw.IGetMathUtility(); Bodies = new SwComponentBodyCollection(comp, rootAssembly); m_FilePathResolver = ((SwApplication)OwnerApplication).Services.GetService <IFilePathResolver>(); }
/// <summary> /// 用类型名过滤特征--只获取第一级特征 /// </summary> /// <param name="comp"></param> /// <param name="TypeName"></param> /// <returns></returns> public static IList <Feature> GetCompTopFeaturesWithTypeName(this IComponent2 comp, string TypeName) { List <Feature> features = new List <Feature>(); var feat = comp.FirstFeature(); while (feat != null) { if (feat.GetTypeName2() == TypeName) { features.Add(feat); } feat = feat.GetNextFeature() as Feature; } return(features); }
/// <summary> /// 获取特定的特征 /// </summary> /// <param name="comp"></param> /// <param name="func"></param> /// <returns></returns> public static IList <Feature> TakeCompTopFeaturesWhile(this IComponent2 comp, Func <Feature, bool> func) { List <Feature> features = new List <Feature>(); var feat = comp.FirstFeature(); while (feat != null) { if (func != null && func(feat)) { features.Add(feat); } feat = feat.GetNextFeature() as Feature; } return(features); }
/// <summary> /// 遍历所有实体 /// </summary> /// <param name="comp"></param> /// <param name="action"></param> /// <param name="bodyType_E"></param> /// <param name="VisbleOnly"></param> public static void UsingAllBody(this IComponent2 comp, Action <Body2> action, swBodyType_e bodyType_E, bool VisbleOnly = false) { var bodys = comp.GetBodies2((int)bodyType_E) as Body2[]; foreach (var item in bodys) { if (VisbleOnly && item.Visible) { action(item); } else { action(item); } } }
/// <summary> /// 获取组件的类型 /// </summary> /// <param name="comp"></param> /// <returns></returns> public static swDocumentTypes_e GetCompType(this IComponent2 comp) { string extension = Path.GetExtension(comp.GetPathName()); switch (extension.ToLower()) { case ".sldprt": return(swDocumentTypes_e.swDocPART); case ".sldasm": return(swDocumentTypes_e.swDocASSEMBLY); default: throw new FileFormatException(string.Format("can not get :{0} 's type,The component's filepath is {1}", comp.Name2, comp.GetPathName())); } }
public static void Export(this IComponent2 comp, string filePath) { var model = comp.IGetModelDoc(); if (model != null) { int err = -1; int warn = -1; model.Extension.SaveAs(filePath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref err, ref warn); } else { throw new NullReferenceException("Model"); } }
/// <summary> /// Gets the children. /// </summary> /// <param name="component">The component.</param> /// <returns></returns> private static List <IComponent2> GetChildren(IComponent2 component) { Array childComponentsArray = component.GetChildren(); var childComponents = new List <IComponent2>(); if (childComponentsArray == null) { return(childComponents); } foreach (IComponent2 comp in childComponentsArray) { childComponents.Add(comp); // Add the child childComponents.AddRange(GetChildren(comp)); // Recursively add children of the child } return(childComponents); }
internal static void SetColor(Color?color, IComponent2 ownerComp, Action <double[], swInConfigurationOpts_e, string[]> setColorAction, Action <swInConfigurationOpts_e, string[]> removeColorAction) { GetColorScope(ownerComp, out swInConfigurationOpts_e confOpts, out string[] confs); if (color.HasValue) { var matPrps = ToMaterialProperties(color.Value); setColorAction.Invoke(matPrps, confOpts, confs); } else { removeColorAction?.Invoke(confOpts, confs); } }
private string GetRelativeName(IComponent2 comp) { var parentComp = comp.GetParent(); if (parentComp == null) { return(comp.Name2); } else { if (comp.Name2.StartsWith(parentComp.Name2, StringComparison.CurrentCultureIgnoreCase)) { return(comp.Name2.Substring(parentComp.Name2.Length + 1)); } else { throw new Exception("Invalid component name"); } } }
public static void GetActualDoc(string[] Args) { try { foreach (string Arg in Args) { switch (Arg) { case "modeldoc": modeldoc = (ModelDoc2)App.ActiveDoc; break; case "assemblyDoc": assemblyDoc = (AssemblyDoc)App.ActiveDoc; break; case "configuration": configuration = (Configuration)modeldoc.GetActiveConfiguration(); break; case "iComponent": iComponent = (IComponent2)configuration.GetRootComponent(); break; //case "Child": // iComponent = (IComponent2)configuration.GetRootComponent(); // break; } } } catch (Exception ex) { //KKS.KKS_Message.Show(ex.Message); } //return modeldoc; }
public bool MoveNext() { if (m_CurChildIndex == -1) { m_Children = (m_Parent.GetChildren() as object[])?.Cast <IComponent2>().ToArray(); if (m_Children == null) { m_Children = new IComponent2[0]; } } m_CurChildIndex++; if (m_CurChildIndex < m_Children.Length) { m_CurComp = m_Children[m_CurChildIndex]; return(true); } else { return(false); } }
/// <summary> /// 获取原点特征 /// </summary> /// <param name="comp"><see cref="IComponent2"/> Interface</param> /// <returns></returns> public static IFeature GetOrignFeat(this IComponent2 comp) { return(comp.GetCompTopFeatures().Where(f => f.GetTypeName2() == FeatureTypeName.OrignSys).FirstOrDefault()); }
/// <summary> /// 获取组件的子组件 /// </summary> /// <param name="comp"></param> /// <returns></returns> public static IEnumerable <IComponent2> GetChildrenEx(this IComponent2 comp) { return(comp.GetChildren().CastObj <object[]>().Cast <IComponent2>()); }
public void GetParts(IComponent2 Comp) { try { if (Settings.Run) { bool Include = true; Object Children; //TreferencedDoc ActDoc = new TreferencedDoc(); if (!Comp.IsSuppressed())//Wenn Zeichnung nicht unterdrückt { Part part = new Part(); modeldoc = (ModelDoc2)Comp.GetModelDoc2(); if (modeldoc != null) { string FileName = Path.GetFileNameWithoutExtension(modeldoc.GetPathName()); part.Name = FileName.Substring(FileName.LastIndexOf("/") + 1); foreach (Part partfromList in Parts) { if (SWX.Settings.NotInBil && Comp.ExcludeFromBOM) { Include = false; break; } if (Settings.OnlyAssembly && modeldoc.GetType() != (int)swDocumentTypes_e.swDocASSEMBLY) { Include = false; break; } if (partfromList.Name == part.Name) { partfromList.Cnt++; Include = false; break; } } if (Include) { part.PathName = modeldoc.GetPathName(); part.RefConfig = Comp.ReferencedConfiguration; part.Released = modeldoc.GetCustomInfoValue("", "Status"); part.Beschreibung = modeldoc.GetCustomInfoValue("", "Description"); part.IsFastener = modeldoc.GetCustomInfoValue("", "isfastener"); if (modeldoc.GetCustomInfoValue("", "Medienberührend").ToUpper() == "JA") { part.Zertifikat = true; } part.Revision = modeldoc.GetCustomInfoValue(part.RefConfig, "Revision"); modelDocExtension = modeldoc.Extension; //int ret = modelDocExtension.ToolboxPartType; //if (ret != 0) //{ // part.IsToolBoxPart = true; //} } } else { part.PathName = modeldoc.GetPathName(); string TempName = Path.GetFileNameWithoutExtension(Comp.GetPathName()); part.Name = TempName.Substring(TempName.LastIndexOf("/") + 1); //KKS.KKS_Message.Show(ActDoc.Name); part.RefConfig = ""; part.Released = modeldoc.GetCustomInfoValue("", "Status"); part.Revision = modeldoc.GetCustomInfoValue(part.RefConfig, "Revision"); } if (Include) { Parts.Add(part); } } Children = Comp.GetChildren(); foreach (Object com in (Object[])Children) { Child = (IComponent2)com; GetParts(Child); } } } catch (Exception ex) { if (KKS.KKS_Message.Show("Folgender Fehler ist aufgetreten. Um den Vorgang weiter zu führen Klicke auf OK. /n" + ex.Message, "Fehler", true, "OK", "Abbrechen") == System.Windows.Forms.DialogResult.Cancel) { Settings.Run = false; } } }
public void Reset() { m_CurComp = null; m_CurChildIndex = -1; m_Children = null; }
/// <summary> /// 获取组件位置 /// </summary> /// <param name="comp">><see cref="IComponent2"/></param> /// <returns><see cref="Vector3"/></returns> public static Vector3 GetPostion(this IComponent2 comp) { return(comp.Transform2.GetPostion()); }
public HomeController(IComponent2 component2, IComponent4 component4) { this.component2 = component2; _component4 = component4; }
private void AddMateCylinderLocator(IComponent2 cylinderLocator, IFace2 cylinderBase) { IFeature firstFeature = cylinderLocator.FeatureByName(configuration[Property.MOUNTING_CYLINDER_PLANE_NAME_1]); IFeature secondFeature = cylinderLocator.FeatureByName(configuration[Property.MOUNTING_CYLINDER_PLANE_NAME_2]); mounter.AddMate(firstFeature, cylinderBase, (int)swMateType_e.swMateTANGENT, (int)swMateAlign_e.swAlignSAME); mounter.AddMate(secondFeature, cylinderBase, (int)swMateType_e.swMateTANGENT, (int)swMateAlign_e.swAlignSAME); }
private void AlignWithPlane(IComponent2 component, IFeature baseFace) { IFeature face = component.FeatureByName(TOP_PLANE_NAME_RU); face = face == null ? component.FeatureByName(TOP_PLANE_NAME_EN) : face; mounter.AddMate(baseFace, face, (int)swMateType_e.swMatePARALLEL, (int)swMateAlign_e.swAlignNONE); }
private void SetExtrudeDepth(IAssemblyDoc assy, IComponent2 comp, string extrudeFeatName, double depth) { if (comp != null) { if (comp.GetSuppression() == (int)swComponentSuppressionState_e.swComponentLightweight || comp.GetSuppression() == (int)swComponentSuppressionState_e.swComponentFullyLightweight) { if (comp.SetSuppression2((int)swComponentSuppressionState_e.swComponentResolved) != (int)swSuppressionError_e.swSuppressionChangeOk) { throw new InvalidOperationException("Failed to set component state to resolved"); } } else if (comp.GetSuppression() == (int)swComponentSuppressionState_e.swComponentSuppressed) { throw new NotSupportedException("Suppressed component is not supported"); } var feat = comp.FeatureByName(extrudeFeatName); if (feat == null) { throw new MissingMemberException("Feature is not found in the component"); } if (comp.Select4(false, null, false)) { int info = -1; if (assy.EditPart2(true, false, ref info) == (int)swEditPartCommandStatus_e.swEditPartSuccessful) { var featData = feat.GetDefinition() as IExtrudeFeatureData2; if (featData != null) { if (featData.AccessSelections(assy, comp)) { featData.SetDepth(true, depth); if (feat.ModifyDefinition(featData, assy, comp)) { (assy as IModelDoc2).ClearSelection2(true); assy.EditAssembly();//Exit edit part mode } else { throw new Exception("Failed to set the depth to the feature"); } } else { throw new InvalidOperationException("Failed to access feature"); } } else { throw new InvalidCastException("Selected feature is not an extrude feature"); } } else { throw new InvalidOperationException("Failed to edit part"); } } else { throw new InvalidOperationException("Failed to select component"); } } else { throw new Exception("Select component"); } }
// Suppresses limit mates to make it easier to find the free degree of freedom in a joint public List<Mate2> suppressLimitMates(IComponent2 component) { ModelDoc2 modelDoc = component.GetModelDoc2(); List<Mate2> limitMates = new List<Mate2>(); object[] objs = component.GetMates(); //limit mates aren't always present if (objs != null) { foreach (object obj in objs) { if (obj is Mate2) { Mate2 swMate = (Mate2)obj; if (swMate.MinimumVariation != swMate.MaximumVariation) { limitMates.Add(swMate); } } } } foreach (Mate2 swMate in limitMates) { ModelDoc2 doc = component.GetModelDoc2(); Feature feat = (Feature)swMate; feat.Select(false); feat.SetSuppression2((int)swFeatureSuppressionAction_e.swSuppressFeature, (int)swInConfigurationOpts_e.swThisConfiguration, null); } return limitMates; }
public SwComponentBodyCollection(IComponent2 comp, ISwDocument rootDoc) : base(rootDoc) { m_Comp = comp; }