/// <summary> /// 创建唯一 /// </summary> /// <param name="component"></param> /// <param name="str"></param> public static NXObject MakeUnique(NXOpen.Assemblies.Component component, string newFileName) { Part workPart = theSession.Parts.Work; NXOpen.Assemblies.MakeUniquePartBuilder makeUniquePartBuilder1; makeUniquePartBuilder1 = workPart.AssemblyManager.CreateMakeUniquePartBuilder(); bool added1; added1 = makeUniquePartBuilder1.SelectedComponents.Add(component); Tag partTag = theUFSession.Assem.AskPrototypeOfOcc(component.Tag); try { NXOpen.Part part1 = (Part)NXObjectManager.Get(partTag); part1.SetMakeUniqueName(newFileName); NXOpen.NXObject nXObject1; nXObject1 = makeUniquePartBuilder1.Commit(); return(nXObject1); } catch (Exception ex) { LogMgr.WriteLog("AssmbliesUtils:MakeUnique: " + ex.Message); return(null); } finally { makeUniquePartBuilder1.Destroy(); } }
/// <summary> ///判断是否是导套 /// </summary> /// <returns></returns> public bool IsGuidePin() { Face face = this.Builder.CylFeater[0].CylinderFace[0].Data.Face; FaceLoopUtils.LoopList[] loopList = FaceLoopUtils.AskFaceLoops(face.Tag); string err = ""; Vector3d vec = new Vector3d(-this.Direction.X, -this.Direction.Y, -this.Direction.Z); if (loopList.Length != 2) { return(false); } foreach (FaceLoopUtils.LoopList lt in loopList) { if (lt.Type == 2 && lt.EdgeList.Length == 1) { Edge edge = NXObjectManager.Get(lt.EdgeList[0]) as Edge; if (edge.SolidEdgeType == Edge.EdgeType.Circular) { ArcEdgeData data = EdgeUtils.GetArcData(edge, ref err); if (data.Radius >= 8 && UMathUtils.IsEqual(data.Angle, Math.PI * 2)) { int count1 = TraceARay.AskTraceARay(this.Body, data.Center, vec); int count2 = TraceARay.AskTraceARay(this.Body, data.Center, this.Direction); if (count1 == 0 && count2 == 0) { return(true); } } } } } return(false); }
private IEnumerable <NxOperation> GetOperations(NCGroup ncGroup) { if (ncGroup == null) { return(null); } var members = GetMembers(ncGroup.GetMembers()); var operations = members.OfType <NXOpen.CAM.Operation>(); if (NxSession.Ufs == null) { throw new Exception("Не удалось получить сессию пользовательских функций NX."); } Tag cutterTag; var enumerable = operations.Where(op => { NxSession.Ufs.Oper.AskCutterGroup(op.Tag, out cutterTag); return(cutterTag != Tag.Null && NXObjectManager.Get(cutterTag) is Tool); }); return(enumerable .Select(op => new NxOperation(op, this))); }
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> /// 替换电极图纸 /// </summary> /// <param name="oldParenInfo"></param> /// <param name="newParenInfo"></param> /// <returns></returns> public List <string> AlterEleDra(ParentAssmblieInfo oldParenInfo, ParentAssmblieInfo newParenInfo) { List <string> err = new List <string>(); UFSession theUFSession = UFSession.GetUFSession(); Part workPart = Session.GetSession().Parts.Work; string oldDra = directoryPath + oldNameInfo.EleName + "_dwg.prt"; if (!File.Exists(oldDra)) { return(err); } string newDra = directoryPath + newNameInfo.EleName + "_dwg.prt"; if (File.Exists(newDra)) { err.Add(newNameInfo.EleName + " 替换失败,替换后有同名工件! "); return(err); } else { foreach (Part pt in Session.GetSession().Parts) { if (pt.Name.Equals(oldNameInfo.EleName + "_dwg", StringComparison.CurrentCultureIgnoreCase)) { pt.Close(NXOpen.BasePart.CloseWholeTree.False, NXOpen.BasePart.CloseModified.UseResponses, null); } } File.Move(oldDra, newDra); Tag partTag; UFPart.LoadStatus error_status; theUFSession.Part.Open(newDra, out partTag, out error_status); Part newPart = NXObjectManager.Get(partTag) as Part; PartUtils.SetPartDisplay(newPart); NXOpen.Assemblies.Component comp = newPart.ComponentAssembly.RootComponent.GetChildren()[0]; string workName = comp.Name.Replace(oldParenInfo.MoldInfo.MoldNumber + "-" + oldParenInfo.MoldInfo.WorkpieceNumber, newParenInfo.MoldInfo.MoldNumber + "-" + newParenInfo.MoldInfo.WorkpieceNumber); try { Basic.AssmbliesUtils.ReplaceComp(comp, this.directoryPath + workName + ".prt", workName); } catch { } if (newPart != null) { newNameInfo.SetAttribute(newPart); ParentAssmblieInfo info = ParentAssmblieInfo.GetAttribute(newPart); info.MoldInfo = newParenInfo.MoldInfo; info.UserModel = newParenInfo.UserModel; info.SetAttribute(newPart); foreach (DrawingSheet st in newPart.DrawingSheets) { Basic.DrawingUtils.UpdateViews(st); } } PartUtils.SetPartDisplay(workPart); err.Add(newNameInfo.EleName + " 图纸替换成功! "); return(err); } }
/// <summary> /// 替换模号件号 /// </summary> /// <param name="model"></param> /// <param name="info"></param> /// <returns></returns> public static Part Replace(AbstractModel model, MoldInfoModel info) { Session theSession = Session.GetSession(); UFSession theUFSession = UFSession.GetUFSession(); Part workPart = theSession.Parts.Work; Component ct = model.GetPartComp(workPart); string OldName = model.MoldInfo.MoldNumber + "-" + model.MoldInfo.WorkpieceNumber; string newName = info.MoldNumber + "-" + info.WorkpieceNumber; string newPartPath = model.WorkpiecePath.Replace(OldName, newName); if (File.Exists(newPartPath)) { File.Delete(newPartPath); } File.Move(model.WorkpiecePath, newPartPath); if (ct != null) { model.PartTag.Close(NXOpen.BasePart.CloseWholeTree.False, NXOpen.BasePart.CloseModified.UseResponses, null); if (Basic.AssmbliesUtils.ReplaceComp(ct, newPartPath, ct.Name.Replace(OldName, newName))) { return(ct.Prototype as Part); } return(null); } else { model.PartTag.Close(NXOpen.BasePart.CloseWholeTree.False, NXOpen.BasePart.CloseModified.UseResponses, null); //NXOpen.PartLoadStatus partLoadStatus1; //BasePart part = theSession.Parts.OpenBaseDisplay(newPartPath, out partLoadStatus1); Tag partTag; UFPart.LoadStatus error_status; theUFSession.Part.Open(newPartPath, out partTag, out error_status); return(NXObjectManager.Get(partTag) as Part); } }
private void GetCutterTool() { if (ufs == null) { return; } ufs.Oper.AskOperType(Operation.Tag, out OPERATION_TYPE); ufs.Oper.AskCutterGroup(Operation.Tag, out CUTTER_TAG); ufs.Cutter.AskTypeAndSubtype(CUTTER_TAG, out CUTTER_TYPE, out CUTTER_SUBTYPE); if (CUTTER_TAG == Tag.Null) { throw new Exception("Не удалось получить инструмент из операции!"); } Tool = NXObjectManager.Get(CUTTER_TAG) as Tool; if (Tool == null) { throw new Exception("Не удалось получить инструмент из операции!"); } //----------------определяем тип инструмента---------------------------- Tool.Types tt; //Tool.Types.MillForm; Tool.Subtypes ts; // Tool.Subtypes.Undefined; Tool.GetTypeAndSubtype(out tt, out ts); if (tt == Tool.Types.MillForm) { UF_PARAM_TL_DIAMETER = determinateDiameterOfUserTool(); } //-------------------------------------------- CUTTER_ATTRIBUTES = Tool.GetUserAttributes(); }
/// <summary> /// 判断设定值是否正确 /// </summary> /// <param name="ele"></param> /// <returns></returns> private bool IsSetValueOk() { Point pt = null; foreach (Point k in this.eleModel.PartTag.Points.ToArray()) { if (k.Name.ToUpper().Equals(("SetValuePoint").ToUpper())) { pt = k; } } if (pt == null) { return(false); } Tag ptOccsTag = theUFSession.Assem.FindOccurrence(this.eleModel.GetPartComp(workPart).Tag, pt.Tag); Point ptOcc = NXObjectManager.Get(ptOccsTag) as Point; Point3d value = ptOcc.Coordinates; Point3d eleSet = new Point3d(this.eleModel.EleInfo.EleSetValue[0], this.eleModel.EleInfo.EleSetValue[1], this.eleModel.EleInfo.EleSetValue[2]); this.work.WorkMatr.ApplyPos(ref value); if (UMathUtils.IsEqual(value, eleSet)) { return(true); } return(false); }
public double determinateDiameterOfUserTool() { if (Operation == null) { return(0.0); } //создаем инструмент Tag tempCutterTag; ufs.Oper.AskCutterGroup(Operation.Tag, out tempCutterTag); Tool tTool = NXObjectManager.Get(tempCutterTag) as Tool; string nameTrPoint; int DefType; double doubleDiameter; double doubleDistance; double zOffset; int zOffsetUsed; int adjust; int adjustUsed; int cutcom; int cutcomUsed; NXOpen.CAM.MillFormToolBuilder millFormToolBuilder; millFormToolBuilder = NxSession.Part.CAMSetup.CAMGroupCollection.CreateMillFormToolBuilder(tTool); NXObject nxobj = millFormToolBuilder.MillingTrackpointBuilder.GetTrackPoint(0); millFormToolBuilder.MillingTrackpointBuilder.GetTrackPoint(nxobj, out nameTrPoint, out DefType, out doubleDiameter, out doubleDistance, out zOffset, out zOffsetUsed, out adjust, out adjustUsed, out cutcom, out cutcomUsed); millFormToolBuilder.Destroy(); return(Math.Round(doubleDiameter, 2)); }
/// <summary> /// 创建外形点 /// </summary> /// <param name="centerPt"></param> /// <param name="disPt"></param> /// <returns></returns> public List <NXObject> CreatePoint() { UFSession theUFSession = UFSession.GetUFSession(); if (UMathUtils.IsEqual(this.DisPt.X, 0) && UMathUtils.IsEqual(this.DisPt.Y, 0) && UMathUtils.IsEqual(this.DisPt.Z, 0)) { return(null); } double[] x = { CenterPt.X - DisPt.X, CenterPt.X, CenterPt.X + DisPt.X }; double[] y = { CenterPt.Y - DisPt.Y, CenterPt.Y, CenterPt.Y + DisPt.Y }; double[] z = { CenterPt.Z - DisPt.Z, CenterPt.Z, CenterPt.Z + DisPt.Z }; Matrix4 mat = new Matrix4(); List <NXObject> points = new List <NXObject>(); mat.Identity(); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { Point3d temp = new Point3d(x[i], y[j], z[k]); mat.ApplyPos(ref temp); Tag pointTag = Tag.Null; theUFSession.Curve.CreatePoint(new double[] { temp.X, temp.Y, temp.Z }, out pointTag); theUFSession.Obj.SetColor(pointTag, 186); points.Add(NXObjectManager.Get(pointTag) as NXObject); } } } return(points); }
/// <summary> /// 修改电极名 /// </summary> /// <param name="model"></param> /// <param name="newName"></param> /// <returns></returns> public static Part ReplaceElectrode(ElectrodeModel model, string newName) { Session theSession = Session.GetSession(); Part workPart = theSession.Parts.Work; Component ct = model.GetPartComp(workPart); string OldName = model.EleInfo.EleName; string newPartPath = model.WorkpiecePath.Replace(OldName, newName); File.Move(model.WorkpiecePath, newPartPath); if (ct != null) { model.PartTag.Close(NXOpen.BasePart.CloseWholeTree.False, NXOpen.BasePart.CloseModified.UseResponses, null); if (Basic.AssmbliesUtils.ReplaceComp(ct, newPartPath, ct.Name.Replace(OldName, newName))) { Part elePart = ct.Prototype as Part; string dwgPath = model.WorkpieceDirectoryPath + model.AssembleName + "_dwg.prt"; AttributeUtils.AttributeOperation("EleName", newName, elePart); AttributeUtils.AttributeOperation("EleNumber", GetEleNumber(newName), elePart); if (File.Exists(dwgPath)) { UFSession theUFSession = UFSession.GetUFSession(); Tag partTag; UFPart.LoadStatus error_status; File.Move(dwgPath, dwgPath.Replace(OldName, newName)); theUFSession.Part.Open(dwgPath.Replace(OldName, newName), out partTag, out error_status); AttributeUtils.AttributeOperation("EleName", newName, NXObjectManager.Get(partTag) as Part); } return(elePart); } return(null); } return(null); }
/// <summary> /// 获取obj的objOcc /// </summary> /// <param name="partOcc"></param> /// <param name="obj"></param> /// <returns></returns> public static NXObject GetNXObjectOfOcc(Tag partOcc, Tag obj) { Tag objOccTag = Tag.Null; NXOpen.UF.UFSession theUFSession = NXOpen.UF.UFSession.GetUFSession(); objOccTag = theUFSession.Assem.FindOccurrence(partOcc, obj); return(NXObjectManager.Get(objOccTag) as NXObject); }
internal static NXMatrix CreateMatrix2(Vector axisX, Vector axisY, Vector axisZ) { Tag tag; UFSession uFSession = Globals.UFSession; double[] numArray = new double[] { axisX.X, axisX.Y, axisX.Z, axisY.X, axisY.Y, axisY.Z, axisZ.X, axisZ.Y, axisZ.Z }; uFSession.Csys.CreateMatrix(numArray, out tag); return((NXMatrix)NXObjectManager.Get(tag)); }
public static Point CreatePoint(Point3d point) { Tag pointTag = Tag.Null; theUFSession.Curve.CreatePoint(new double[3] { point.X, point.Y, point.Z }, out pointTag); return(NXObjectManager.Get(pointTag) as Point); }
internal static Snap.NX.Point CreatePoint(double x, double y, double z) { Tag tag; UFSession uFSession = Globals.UFSession; double[] numArray = new double[] { x, y, z }; uFSession.Curve.CreatePoint(numArray, out tag); return(new Snap.NX.Point((NXOpen.Point)NXObjectManager.Get(tag))); }
/// <summary> /// Loop转换为边 /// </summary> /// <param name="loop"></param> /// <returns></returns> private List <Edge> GetLoopToEdge(FaceLoopUtils.LoopList loop) { List <Edge> edges = new List <Edge>(); foreach (Tag t in loop.EdgeList) { edges.Add(NXObjectManager.Get(t) as Edge); } return(edges); }
/// <summary> /// 修改版本 /// </summary> /// <param name="editionNumber"></param> private void UpdateEditionNumber(string editionNumber) { UFSession theUFSession = UFSession.GetUFSession(); Session theSession = Session.GetSession(); MoldInfo mf = asm.Info.MoldInfo; mf.EditionNumber = editionNumber; mf.SetAttribute(asm.PartTag); foreach (ElectrodeModel em in asmColl.GetElectrodes()) { MoldInfo mi = em.Info.MoldInfo; mi.EditionNumber = editionNumber; mi.SetAttribute(em.PartTag); string dwgName = em.Info.AllInfo.Name.EleName + "_dwg"; string dwg = em.WorkpieceDirectoryPath + em.Info.AllInfo.Name.EleName + "_dwg.prt"; if (File.Exists(dwg)) { Part dwgPart = null; try { dwgPart = theSession.Parts.FindObject(dwgName) as Part; if (dwgPart != null) { mi.SetAttribute(dwgPart); continue; } } catch { } Tag part; UFPart.LoadStatus error_status; theUFSession.Part.Open(dwg, out part, out error_status); mi.SetAttribute(NXObjectManager.Get(part) as Part); } } foreach (MoldInfo mi in asmColl.MoldInfo) { WorkCollection wkColl = asmColl.GetWorkCollection(mi); foreach (WorkModel wm in wkColl.Work) { MoldInfo wmMold = wm.Info.MoldInfo; wmMold.EditionNumber = editionNumber; wmMold.SetAttribute(wm.PartTag); } foreach (EDMModel em in wkColl.EdmModel) { MoldInfo wmMold = em.Info.MoldInfo; wmMold.EditionNumber = editionNumber; wmMold.SetAttribute(em.PartTag); } } PartUtils.SetPartDisplay(asm.PartTag); }
internal static NXOpen.NXObject GetObjectFromTag(Tag tag) { NXOpen.NXObject obj2 = null; try { obj2 = NXObjectManager.Get(tag) as NXOpen.NXObject; } catch { } return(obj2); }
public static NXOpen.Section Section(this NXOpen.Features.DatumAxisBuilder obj) { IntPtr ptr; JAM.StartCall(); int status = JA_DATUM_AXIS_BUILDER_get_section(JAM.Lookup(obj.Tag), out ptr); if (status != 0) { throw NXException.Create(status); } return((NXOpen.Section)NXObjectManager.Get(JAM.Lookup(ptr))); }
public static Snap.NX.Face Wrap(Tag nxopenFaceTag) { if (nxopenFaceTag == Tag.Null) { return(null); } if (Snap.NX.NXObject.GetTypeFromTag(nxopenFaceTag) != ObjectTypes.Type.Face) { throw new ArgumentException("Input tag doesn't belong to an NXOpen.Face object"); } NXOpen.Face nxopenFace = (NXOpen.Face)NXObjectManager.Get(nxopenFaceTag); return(CreateFace(nxopenFace)); }
/// <summary> /// 获取occ下Part所有体 /// </summary> /// <returns></returns> private List <Body> GetOccsInBods(Part pt) { List <Body> bodys = new List <Body>(); Tag[] workpiecePartOccsTag; theUFSession.Assem.AskOccsOfPart(workPart.Tag, pt.Tag, out workpiecePartOccsTag); foreach (Body body in pt.Bodies) { Tag bodyOccsTag = theUFSession.Assem.FindOccurrence(workpiecePartOccsTag[0], body.Tag); bodys.Add(NXObjectManager.Get(bodyOccsTag) as Body); } return(bodys); }
/// <summary> /// 抽取面 /// </summary> /// <param name="face"></param> /// <returns></returns> public static Body ExtraetFace(Face face) { Tag sheetBody = Tag.Null; try { theUFSession.Modl.ExtractFace(face.Tag, 0, out sheetBody); return(NXObjectManager.Get(sheetBody) as Body); } catch (NXException ex) { // LogMgr.WriteLog("ExtraetUtils:ExtraetFace " + ex.Message); throw ex; } }
private void OK_Click(object sender, EventArgs e) { try { for (int i = 0; i < panel.Rows.Count; i++) { DisplayableObject singleObj = (DisplayableObject)NXObjectManager.Get((Tag)panel.GetCell(i, 0).Tag); singleObj.SetAttribute("CustomerBalloon", panel.GetCell(i, 1).Value.ToString()); } MessageBox.Show("設定完成!"); } catch (System.Exception ex) { } }
/// <summary> /// 取得此Operation的刀子 /// </summary> /// <returns></returns> public static bool AskOperTool(Tag operTag, out Tool tool) { tool = null; try { Tag bb; theUfSession.Oper.AskCutterGroup(operTag, out bb); tool = (Tool)NXObjectManager.Get(bb); } catch (System.Exception ex) { return(false); } return(true); }
private void GetAttributes() { if (CUTTER_TAG == Tag.Null) { return; } var cutter = NXObjectManager.Get(CUTTER_TAG) as Tool; if (cutter == null) { throw new Exception("NXObjectManager.Get(CUTTER_TAG) as Tool is NULL!"); } CUTTER_ATTRIBUTES = cutter.GetUserAttributes(); }
/// <summary> /// 获取obj的objOcc /// </summary> /// <param name="partOcc"></param> /// <param name="obj"></param> /// <returns></returns> public static NXObject GetOccOfInstance(Tag partOcc) { Tag objOccTag = Tag.Null; NXOpen.UF.UFSession theUFSession = NXOpen.UF.UFSession.GetUFSession(); try { objOccTag = theUFSession.Assem.AskInstOfPartOcc(partOcc); return(NXObjectManager.Get(objOccTag) as NXObject); } catch (NXException ex) { LogMgr.WriteLog("AssmbliesUtils:GetNXObjectOfInstance: " + ex.Message); throw ex; } }
/// <summary> /// 取得Operation父層名稱 /// </summary> /// <param name="operTag"></param> /// <param name="operProgramName"></param> /// <returns></returns> public static bool AskOperProgramNameFromTag(Tag operTag, out string operProgramName) { operProgramName = ""; try { Tag bb; theUfSession.Oper.AskProgramGroup(operTag, out bb); NXOpen.CAM.NCGroup gg = (NXOpen.CAM.NCGroup)NXObjectManager.Get(bb); operProgramName = gg.Name; } catch (System.Exception ex) { return(false); } return(true); }
/// <summary> /// 替换组件 /// </summary> /// <param name="pt"></param> /// <param name="info"></param> /// <param name="newPath"></param> /// <param name="newName"></param> /// <returns></returns> public static List <string> Replace(Part pt, string newPath, string newName, out Part newPart) { List <string> err = new List <string>(); newPart = null; Session theSession = Session.GetSession(); UFSession theUFSession = UFSession.GetUFSession(); Part workPart = theSession.Parts.Work; List <Component> cts = AssmbliesUtils.GetPartComp(workPart, pt); string oldPath = pt.FullPath; pt.Close(NXOpen.BasePart.CloseWholeTree.False, NXOpen.BasePart.CloseModified.UseResponses, null); File.Move(oldPath, newPath); if (cts.Count > 0) { foreach (Component co in cts) { try { bool rep = AssmbliesUtils.ReplaceComp(co, newPath, newName); if (rep) { err.Add(newName + " 组件替换成功! "); } else { err.Add(newName + " 组件替换失败! "); } } catch { err.Add(newName + " 组件替换失败! "); } } newPart = cts[0].Prototype as Part; return(err); } else { Tag partTag; UFPart.LoadStatus error_status; theUFSession.Part.Open(newPath, out partTag, out error_status); err.Add(newName + " 组件替换成功! "); newPart = NXObjectManager.Get(partTag) as Part; return(err); } }
public string determinateNameOfTool() { string nameTool = null; Tag tempCutterTag; Tool tempTool; if (Operation == null) { return(null); } //создаем инструмент, затем пропускаем его через метод enc() ufs.Oper.AskCutterGroup(Operation.Tag, out tempCutterTag); tempTool = NXObjectManager.Get(tempCutterTag) as Tool; nameTool = enc(tempTool.Name); return(nameTool); }
/// <summary> /// 取得Operation加工方法 /// </summary> /// <param name="operTag"></param> /// <param name="operMethodName"></param> /// <returns></returns> public static bool AskOperMethodNameFromTag(Tag operTag, out string operMethodName) { operMethodName = ""; try { Tag bb; theUfSession.Oper.AskMethodGroup(operTag, out bb); NXOpen.CAM.Method cc = (NXOpen.CAM.Method)NXObjectManager.Get(bb); operMethodName = cc.Name; } catch (System.Exception ex) { CaxLog.ShowListingWindow("使用AskOperMethodNameFromTag出錯:" + ex.ToString()); return(false); } return(true); }