public static bool GetRootAssemblyPart(Tag partOccTag, out Part rootPart) { Tag[] tagArray; bool flag; try { rootPart = null; CaxAsm.theUfSession.Assem.WhereIsPartUsed(partOccTag, out tagArray); if ((int)tagArray.Length != 0) { CaxAsm.GetRootAssemblyPart(tagArray[0], out rootPart); return(true); } else { rootPart = (Part)NXObjectManager.Get(partOccTag); flag = true; } } catch (Exception exception) { rootPart = null; flag = false; } return(flag); }
/// <summary> /// 取得子Comp集合(只找下一層) /// </summary> /// <param name="compAry"></param> /// <param name="comp"></param> /// <returns></returns> public static bool GetCompChildren(out List <NXOpen.Assemblies.Component> compAry, Component comp = null) { compAry = new List <NXOpen.Assemblies.Component>(); try { CaxAsm.SetWorkComponent(comp); Part rootPart = theSession.Parts.Work; NXOpen.Assemblies.ComponentAssembly casm = rootPart.ComponentAssembly; NXOpen.Assemblies.Component[] tempCompAry = casm.RootComponent.GetChildren(); compAry.AddRange(tempCompAry.ToList()); } catch (System.Exception ex) { //compAry = null; return(false); } return(true); }
public static bool GetComponentPath(Part displayPart, CaxDownUpLoad.DownUpLoadDat cDownUpLoadDat, ref Dictionary <string, PartDirData> DicPartDirData) { try { PartDirData sPartDirData = new PartDirData(); sPartDirData.PartLocalDir = displayPart.FullPath; sPartDirData.PartServer1Dir = string.Format(@"{0}\{1}", cDownUpLoadDat.Server_ShareStr, Path.GetFileName(displayPart.FullPath)); DicPartDirData.Add(Path.GetFileNameWithoutExtension(displayPart.FullPath), sPartDirData); //listView1.Items.Add(Path.GetFileName(displayPart.FullPath)); List <Component> ListChildrenComp = new List <Component>(); CaxAsm.GetCompChildren(displayPart.ComponentAssembly.RootComponent, ref ListChildrenComp); foreach (Component i in ListChildrenComp) { if (DicPartDirData.TryGetValue(i.DisplayName, out sPartDirData)) { continue; } if (!File.Exists(string.Format(@"{0}\{1}", Path.GetDirectoryName(displayPart.FullPath), i.DisplayName + ".prt"))) { MessageBox.Show("零件:" + i.DisplayName + "找不到,請檢察本機資料夾是否存在"); return(false); } sPartDirData = new PartDirData(); string ServerPartPath = string.Format(@"{0}\{1}", cDownUpLoadDat.Server_ShareStr, i.DisplayName + ".prt"); sPartDirData.PartLocalDir = string.Format(@"{0}\{1}", Path.GetDirectoryName(displayPart.FullPath), i.DisplayName + ".prt"); sPartDirData.PartServer1Dir = ServerPartPath; DicPartDirData.Add(i.DisplayName, sPartDirData); //listView1.Items.Add(i.DisplayName + ".prt"); } } catch (System.Exception ex) { return(false); } return(true); }