/// <summary> /// 读取属性 /// </summary> public static ElectrodeAllInfo GetAttribute(NXObject obj) { try { ElectrodeRemarksInfo rem = ElectrodeRemarksInfo.GetAttribute(obj); ElectrodeCAMInfo cam = ElectrodeCAMInfo.GetAttribute(obj); ElectrodeGapValueInfo gap = ElectrodeGapValueInfo.GetAttribute(obj); ElectrodePitchInfo pitch = ElectrodePitchInfo.GetAttribute(obj); ElectrodePreparationInfo pre = ElectrodePreparationInfo.GetAttribute(obj); ElectrodeSetValueInfo sv = ElectrodeSetValueInfo.GetAttribute(obj); ElectrodeNameInfo name = ElectrodeNameInfo.GetAttribute(obj); ElectrodeDatumInfo da = ElectrodeDatumInfo.GetAttribute(obj); return(new ElectrodeAllInfo() { Remarks = rem, CAM = cam, GapValue = gap, Pitch = pitch, Preparetion = pre, SetValue = sv, Name = name, Datum = da }); } catch (NXException ex) { throw ex; } }
public static string ExportPDF(NXOpen.Drawings.DrawingSheet ds, string dsName) { if (Directory.Exists(_pdfFilePath)) { Directory.Delete(_pdfFilePath, true); } Directory.CreateDirectory(_pdfFilePath); Session theSession = Session.GetSession(); Part workPart = theSession.Parts.Work; Part displayPart = theSession.Parts.Display; PrintPDFBuilder printPDFBuilder1; printPDFBuilder1 = workPart.PlotManager.CreatePrintPdfbuilder(); NXObject[] sheets1 = new NXObject[1]; NXOpen.Drawings.DrawingSheet drawingSheet1 = ds; sheets1[0] = drawingSheet1; printPDFBuilder1.SourceBuilder.SetSheets(sheets1); var fileName = string.Format("{0}{1}", dsName, ".pdf"); var result = System.IO.Path.Combine(_pdfFilePath, fileName); printPDFBuilder1.Filename = result; NXObject nXObject1; nXObject1 = printPDFBuilder1.Commit(); printPDFBuilder1.Destroy(); return(result); }
/// <summary> /// 复制电极 /// </summary> /// <param name="eleCt"></param> /// <param name="workPt"></param> /// <returns></returns> public List <string> LoadEle(NXOpen.Assemblies.Component eleCt, Part workPt) { Matrix3x3 mat; Point3d setPt; List <string> err = new List <string>(); eleCt.GetPosition(out setPt, out mat); ElectrodeSetValueInfo setValue = ElectrodeSetValueInfo.GetAttribute(eleCt); NXOpen.PartLoadStatus partLoadStatus1 = null; string partPath = (eleCt.Prototype as Part).FullPath; try { NXOpen.Assemblies.Component copyCt = workPt.ComponentAssembly.AddComponent(partPath, "None", eleCt.Name, setPt, mat, -1, out partLoadStatus1, true); NXObject obj = AssmbliesUtils.GetOccOfInstance(copyCt.Tag); bool attOk = setValue.SetAttribute(obj); AttributeUtils.AttributeOperation("EleComponentCopy", 1, obj); if (!attOk) { err.Add("写入属性错误!"); } } catch (NXException ex) { err.Add(eleCt.Name + "复制电极错误! " + ex.Message); } return(err); }
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="vec"></param> /// <returns></returns> public bool MovePositionBuilder(Vector3d vec) { try { Matrix4 inv = this.work.Info.Matr.GetInversMatrix(); CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(this.work.Info.Matr, inv); ElectrodeSetValueInfo setValue = ElectrodeSetValueInfo.GetAttribute(eleComp); ElectrodeSetValueInfo newSetValue = setValue.Clone() as ElectrodeSetValueInfo; AssmbliesUtils.MoveCompPart(eleComp, vec, work.Info.Matr); NXObject instance = AssmbliesUtils.GetOccOfInstance(eleComp.Tag); BodyInfo info = GetDischargeFace(csys, eleComp); newSetValue.EleSetValue[0] = setValue.EleSetValue[0] + vec.X; newSetValue.EleSetValue[1] = setValue.EleSetValue[1] + vec.Y; newSetValue.EleSetValue[2] = setValue.EleSetValue[2] + vec.Z; newSetValue.Positioning = GetPositionName(); newSetValue.PositioningRemark = "设定值改变"; if (info != null) { newSetValue.ContactArea = info.ContactArea; newSetValue.ProjectedArea = info.GetProjectedArea(csys, this.work.Info.Matr); } newSetValue.SetAttribute(instance); return(true); } catch (NXException ex) { ClassItem.WriteLogFile("电极跑位错误!" + ex.Message); return(false); } }
public DatumAxis DatumAxisCreation(Part workPart, Point3d first3d, Point3d second3d) { //Tworzenie "buildera dla osi Y". NXOpen.Features.Feature nullFeatures_Feature = null; NXOpen.Features.DatumAxisBuilder datumAxisBuilder; datumAxisBuilder = workPart.Features.CreateDatumAxisBuilder(nullFeatures_Feature); datumAxisBuilder.IsAssociative = true; datumAxisBuilder.Type = NXOpen.Features.DatumAxisBuilder.Types.TwoPoints; datumAxisBuilder.ResizedEndDistance = 0.0; Point first = workPart.Points.CreatePoint(first3d); Point second = workPart.Points.CreatePoint(second3d); datumAxisBuilder.Point1 = first; datumAxisBuilder.Point2 = second; NXObject vector = datumAxisBuilder.Commit(); string journalName = vector.JournalIdentifier.ToString(); DatumAxis datumAxis = (DatumAxis)workPart.Datums.FindObject(journalName); datumAxisBuilder.Destroy(); return(datumAxis); }
public NXOpen.Features.DatumCsys CsysCreation(Part workPart, Point3d pointOrigin3d, Point3d pointAxis13d, Point3d pointAxis23d) { NXOpen.Features.Feature nullFeatures_Feature = null; NXOpen.Features.DatumCsysBuilder datumCsysBuilder; datumCsysBuilder = workPart.Features.CreateDatumCsysBuilder(nullFeatures_Feature); Point pointOrigin = workPart.Points.CreatePoint(pointOrigin3d); Point pointAxis2 = workPart.Points.CreatePoint(pointAxis13d); Point pointAxis1 = workPart.Points.CreatePoint(pointAxis23d); Xform xform1; xform1 = workPart.Xforms.CreateXform(pointOrigin, pointAxis1, pointAxis2, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0); CartesianCoordinateSystem cartesianCoordinateSystem; cartesianCoordinateSystem = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, NXOpen.SmartObject.UpdateOption.WithinModeling); datumCsysBuilder.Csys = cartesianCoordinateSystem; datumCsysBuilder.ComponentsCreation = true; datumCsysBuilder.FixedSizeDatum = true; datumCsysBuilder.DisplayScaleFactor = 1.25; NXObject cSys = datumCsysBuilder.Commit(); string journalName = cSys.JournalIdentifier.ToString(); NXOpen.Features.DatumCsys datumCsys = (NXOpen.Features.DatumCsys)workPart.Features.FindObject(journalName); datumCsysBuilder.Destroy(); return(datumCsys); }
/// <summary> /// 创建位置约束 /// </summary> /// <param name="obj1">要约束的对象</param> /// <param name="obj2">约束到的对象</param> /// <param name="type">约束类型</param> public static bool CreateConstraint(NXObject obj2, SketchConstraintBuilder.Constraint type, params NXObject[] obj1) { Part workPart = theSession.Parts.Work; NXOpen.SketchConstraintBuilder sketchConstraintBuilder1; sketchConstraintBuilder1 = workPart.Sketches.CreateConstraintBuilder(); sketchConstraintBuilder1.ConstraintType = type; sketchConstraintBuilder1.GeometryToConstrain.SetArray(obj1); sketchConstraintBuilder1.GeometryToConstrainTo.Value = obj2; try { NXOpen.NXObject nXObject1; nXObject1 = sketchConstraintBuilder1.Commit(); return(true); } catch (NXException ex) { LogMgr.WriteLog("SketchUtils:CreateConstraint:" + ex.Message); return(false); } finally { sketchConstraintBuilder1.Destroy(); } }
public void hideit(NXObject objtohide)//////这是一个隐藏NXObject的方法 { DisplayableObject a = (DisplayableObject)objtohide; DisplayableObject[] objects1 = new DisplayableObject[1]; objects1[0] = a; theSession.DisplayManager.BlankObjects(objects1); }
public bool SetOffsetInter(List <Face> ErFace, double ErSide, List <Face> EfFace, double EfSide) { string mb = AttributeUtils.GetAttrForString(pt, "MdblsShrinkBody"); if (mb.Equals("1", StringComparison.CurrentCultureIgnoreCase)) { return(true); } if (mb.Equals("0", StringComparison.CurrentCultureIgnoreCase)) { return(false); } bool isokEr = false; bool isokEf = false; UFSession theUFSession = UFSession.GetUFSession(); List <Tag> featureTags = new List <Tag>(); Tag groupTag; foreach (NXOpen.Features.Feature fe in pt.Features) { featureTags.Add(fe.Tag); } theUFSession.Modl.CreateSetOfFeature("电极特征", featureTags.ToArray(), featureTags.Count, 1, out groupTag); NXObject objEr = null; try { objEr = OffsetRegionUtils.Offset(-ErSide, out isokEr, ErFace.ToArray()); if (isokEr) { objEr.SetName((-ErSide).ToString()); } } catch { this.SetAttribute(true); return(false); } try { NXObject obj = OffsetRegionUtils.Offset(-EfSide, out isokEf, EfFace.ToArray()); if (isokEf) { obj.SetName((-EfSide).ToString()); } this.SetAttribute(true); return(true); } catch { if (objEr != null) { DeleteObject.Delete(objEr); } this.SetAttribute(false); return(false); } }
public static void DeleteUserAttributes(this NXObject obj, NXOpen.NXObject.AttributeType type, Update.Option option) { //JAM.StartCall(); //int status = JA_NXOBJECT_delete_user_attributes(obj.Tag, type, option); //if (status != 0) //{ // throw NXException.Create(status); //} obj.DeleteAllAttributesByType(type, option); }
public static int Startup(string[] args) { int retValue = 0; try { theProgram = new Program(); PartLoadStatus pld; string partPath = @"D:\ACCEPTED_NX_MODELS\Q5\TEST\TEST.prt"; Part workPart = theSession.Parts.OpenBaseDisplay(partPath, out pld) as Part; ComponentAssembly assembly = workPart.ComponentAssembly; Component rootComponent = assembly.RootComponent; theProgram.Traverse(rootComponent); theSession.ListingWindow.Open(); foreach (Component leaf in theProgram.leafList) { Part leafPart = leaf.Prototype as Part; Body[] leafBodies = leafPart.Bodies.ToArray(); if (leafBodies.Length != 0) { Body leafBody = leafBodies[0]; Promotion promoteBody = null; PromotionBuilder promotionBuider1 = workPart.Features.CreatePromotionBuilder(promoteBody); leafBody = leaf.FindOccurrence(leafBody) as Body; bool added = promotionBuider1.Body.Add(leafBody); bool validated = promotionBuider1.Validate(); NXObject objects = promotionBuider1.Commit(); promotionBuider1.Destroy(); theSession.ListingWindow.WriteLine(leaf.Name + "\t" + leafBodies.Length.ToString() + "\t" + leafBody.Name.ToString()); } } PartSaveStatus ps; bool partSaved; theSession.Parts.SaveAll(out partSaved, out ps); theUFSession.Part.CloseAll(); theProgram.Dispose(); } catch (NXOpen.NXException ex) { theUFSession.Part.CloseAll(); theSession.ListingWindow.Open(); theSession.ListingWindow.WriteLine(ex.ToString()); // ---- Enter your exception handling code here ----- } return(retValue); }
//------------------------------------------------------------------------------ // Callback Name: filter_cb // Following callback is associated with the "changeDialog" Styler item. // Input: eventObject - object of UIStyler.StylerEvent class //------------------------------------------------------------------------------ //Following is Filter Callback - This function gets invoked during selection. //Here, we can put a logic to accept or reject the selected entities. In this example "Edge * 6 *1" is rejected. public int filter_cb(NXObject selectedObject, NXOpen.Selection.MaskTriple selectionMask_array, SelectionHandle selectHandle) { if (String.Equals(selectedObject.JournalIdentifier, "EDGE * 6 * 1")) { return(NXOpen.UF.UFConstants.UF_UI_SEL_REJECT); } else { return(NXOpen.UF.UFConstants.UF_UI_SEL_ACCEPT); } }
/// <summary> /// 创建装配 /// </summary> /// <param name="filePath"></param> /// <returns></returns> public NXOpen.Assemblies.Component CreateCompPart() { CsysUtils.SetWcsOfCenteAndMatr(this.CenterPt, this.EleMatr.GetMatrix3()); NXObject obj = AssmbliesUtils.CreateNew(this.AssembleName, WorkpiecePath); NXOpen.Assemblies.Component comp = obj as NXOpen.Assemblies.Component; this.PartTag = obj.Prototype as Part; SetAttribute(); CsysUtils.SetWcsToAbs(); return(comp); }
/// <summary> /// 以属性得到实体 /// </summary> /// <param name="obj"></param> /// <returns></returns> public new static WorkPieceInfo GetAttribute(NXObject obj) { try { return(new WorkPieceInfo(MoldInfo.GetAttribute(obj), UserModel.GetAttribute(obj))); } catch (NXException ex) { throw ex; } }
public static Body TryConvertNxObjectToBody(NXObject nxObject) { Body body = null; try { body = (Body)nxObject; } catch (Exception) {} return(body); }
public static void DeleteUserAttribute(this NXObject obj, NXOpen.NXObject.AttributeType type, string title, bool deleteEntireArray, Update.Option option) { //JAM.StartCall(); //IntPtr ptr = JAM.ToText(title); //int status = JA_NXOBJECT_delete_user_attribute(obj, type, ptr, deleteEntireArray, option); //JAM.TextFree(ptr); //if (status != 0) //{ // throw NXException.Create(status); //} obj.DeleteAttributeByTypeAndTitle(type, title, option); }
/// <summary> /// 以属性得到实体 /// </summary> /// <param name="obj"></param> /// <returns></returns> public new static EDMInfo GetAttribute(NXObject obj) { try { return(new EDMInfo(MoldInfo.GetAttribute(obj), UserModel.GetAttribute(obj))); } catch (NXException ex) { ClassItem.WriteLogFile("未获取到EdmNumber 属性" + ex.Message); return(null); } }
public static bool GetAttrForBool(NXObject obj, string title, int index) { try { return(obj.GetBooleanUserAttribute(title, index)); //获取属性 } catch { // LogMgr.WriteLog("获取" + title + "属性函数错误"); return(false); } }
public static int GetAttrForInt(NXObject obj, string title, int index) { try { return(obj.GetIntegerUserAttribute(title, index)); //获取属性 } catch { // LogMgr.WriteLog("获取" + title + "属性函数错误"); return(0); } }
public static string GetAttrForString(NXObject obj, string title, int index) { try { return(obj.GetStringUserAttribute(title, index)); //获取属性 } catch { // LogMgr.WriteLog("获取" + title + "属性函数错误"); return(" "); } }
public static double GetAttrForDouble(NXObject obj, string title, int index) { try { return(obj.GetRealUserAttribute(title, index)); //获取属性 } catch { // LogMgr.WriteLog("获取" + title + "属性函数错误"); return(0); } }
/// <summary> /// 以属性得到实体 /// </summary> /// <param name="obj"></param> /// <returns></returns> public new static ElectrodeInfo GetAttribute(NXObject obj) { try { return(new ElectrodeInfo(MoldInfo.GetAttribute(obj), UserModel.GetAttribute(obj), ElectrodeAllInfo.GetAttribute(obj), Matrix4Info.GetAttribute(obj))); } catch (NXException ex) { ClassItem.WriteLogFile("未获取到属性" + ex.Message); return(null); } }
//------------------------------------------------------------------------------ //Callback Name: apply_cb //------------------------------------------------------------------------------ public int apply_cb() { int errorCode = 0; try { firstpt = point0.GetProperties().GetTaggedObjectVector("SelectedObjects"); secpt = point01.GetProperties().GetTaggedObjectVector("SelectedObjects"); Point a = Tag2NXObject <Point>(firstpt[0].Tag); Point b = Tag2NXObject <Point>(secpt[0].Tag); NXObject axisyo = shank(a, b); double[] real3d; NXOpen.Features.DatumAxisFeature axisreal = (NXOpen.Features.DatumAxisFeature)axisyo; DatumAxis axisreal1 = axisreal.DatumAxis; Point3d stpt; //轴的起点 Point3d endpt; //轴的终点 stpt = a.Coordinates; endpt = b.Coordinates; // axisreal1.GetEndPoints(out stpt, out endpt); hideit(axisreal1); real3d = angle(axisreal1); thepmi = selection0.GetProperties().GetTaggedObjectVector("SelectedObjects"); NXObject last = Tag2NXObject <NXObject>(thepmi[0].Tag); NXOpen.Annotations.Dimension lastdimn = (NXOpen.Annotations.Dimension)last; double m = lastdimn.ComputedSize; double cosx = Math.Cos(ConvertDegreesToRadians(real3d[0])); double cosy = Math.Cos(ConvertDegreesToRadians(real3d[1])); double cosz = Math.Cos(ConvertDegreesToRadians(real3d[2])); double cosxx = cosx * m; double cosyy = cosy * m; double coszz = cosz * m; last.SetAttribute("X", cosxx); last.SetAttribute("Y", cosyy); last.SetAttribute("Z", coszz); last.SetAttribute("START-X", stpt.X); last.SetAttribute("START-Y", stpt.Y); last.SetAttribute("START-Z", stpt.Z); last.SetAttribute("END-X", endpt.X); last.SetAttribute("END-Y", endpt.Y); last.SetAttribute("END-Z", endpt.Z); //---- Enter your callback code here ----- } catch (Exception ex) { //---- Enter your exception handling code here ----- errorCode = 1; theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return(errorCode); }
public Body Revolve(Part workPart, Axis axisRotation, Sketch sketch, Line lineSketch, Point3d point3dSketch, double degStart, double degEnd) { //RevolveBulidier NXOpen.Features.Feature nullFeature1 = null; NXOpen.Features.RevolveBuilder revolveBuilder1 = workPart.Features.CreateRevolveBuilder(nullFeature1); //Section Section section1 = workPart.Sections.CreateSection(0.02, 0.02, 0.02); revolveBuilder1.Section = section1; revolveBuilder1.Axis = axisRotation; revolveBuilder1.Tolerance = 0.02; section1.DistanceTolerance = 0.02; section1.ChainingTolerance = 0.02; //Line assignment NXOpen.Features.Feature[] features1 = new NXOpen.Features.Feature[1]; NXOpen.Features.SketchFeature sketchFeature1 = (NXOpen.Features.SketchFeature)sketch.Feature; features1[0] = sketchFeature1; CurveFeatureRule curveFeatureRule1; curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1); section1.AllowSelfIntersection(true); SelectionIntentRule[] rules1 = new SelectionIntentRule[1]; rules1[0] = curveFeatureRule1; NXObject nullNXObject = null; //Selection section1.AddToSection(rules1, lineSketch, nullNXObject, nullNXObject, point3dSketch, NXOpen.Section.Mode.Create, false); revolveBuilder1.Axis = axisRotation; //Sheet Body selection revolveBuilder1.FeatureOptions.BodyType = NXOpen.GeometricUtilities.FeatureOptions.BodyStyle.Sheet; revolveBuilder1.Section = section1; //Ustawienia revolveBuilder1.Limits.StartExtend.Value.RightHandSide = degStart.ToString(); revolveBuilder1.Limits.EndExtend.Value.RightHandSide = degEnd.ToString(); revolveBuilder1.ParentFeatureInternal = false; NXObject feature_revolve1 = revolveBuilder1.CommitFeature(); NXOpen.Features.BodyFeature bodyFeature1 = (NXOpen.Features.BodyFeature)feature_revolve1; Body[] body = bodyFeature1.GetBodies(); return(body[0]); }
private void button_read_Click(object sender, EventArgs e) { NXObject[] nxobs = NXFun.GetSelectObjects(); if (nxobs.Length == 0) { MessageBox.Show("û����NXѡ�ж���Ŷ��"); } else //��ѯ { AttrList.Clear(); if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { //�õ�sheet ����άͼ����Ҫ������������ NXOpen.Drawings.DrawingSheet[] ds = theSession.Parts.Work.DrawingSheets.ToArray(); if (ds.Length!=0) { obj = ds[0]; } else { obj = nxobs[0]; } } else { obj = nxobs[0]; } s_Attr s_attr; NXObject.AttributeInformation[] ais = obj.GetAttributeTitlesByType(NXObject.AttributeType.String); for (int i = 0; i < ais.Length; i ++ ) { s_attr.title = ais[i].Title; s_attr.s_value = obj.GetStringAttribute(s_attr.title); s_attr.type = "string"; s_attr.i_value = 0; AttrList.Add(s_attr); } ais = obj.GetAttributeTitlesByType(NXObject.AttributeType.Integer); for (int i = 0; i < ais.Length; i++) { s_attr.title = ais[i].Title; s_attr.i_value = obj.GetIntegerAttribute(s_attr.title); s_attr.type = "int"; s_attr.s_value = ""; AttrList.Add(s_attr); } RefreshDisplay(); } }
/// <summary> /// 以属性得到实体 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static ParentAssmblieInfo GetAttribute(NXObject obj) { try { string partType = AttributeUtils.GetAttrForString(obj, "PartType"); ParentAssmblieInfo info = new ParentAssmblieInfo(MoldInfo.GetAttribute(obj), UserModel.GetAttribute(obj)); info.Type = (PartType)Enum.Parse(typeof(PartType), partType); return(info); } catch (NXException ex) { throw ex; } }
/// <summary> /// 设置模具信息属性 /// </summary> /// <param name="part"></param> public bool SetAttribute(NXObject obj) { try { AttributeUtils.AttributeOperation("Matrx4", Matrx4ToString(this.Matr), obj); AttributeUtils.AttributeOperation("CsysCenter", new double[] { Math.Round(this.CenterPt.X, 4), Math.Round(this.CenterPt.Y, 4), Math.Round(this.CenterPt.Z, 4) }, obj); return(true); } catch (NXException ex) { ClassItem.WriteLogFile("写入属性错误!" + ex.Message); return(false); } }
private void button_read_Click(object sender, EventArgs e) { NXObject[] nxobs = NXFun.GetSelectObjects(); if (nxobs.Length == 0) { MessageBox.Show("没有在NX选中东东哦!"); } else //查询 { AttrList.Clear(); if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { //得到sheet 做二维图表需要设置隐藏属性 NXOpen.Drawings.DrawingSheet[] ds = theSession.Parts.Work.DrawingSheets.ToArray(); if (ds.Length != 0) { obj = ds[0]; } else { obj = nxobs[0]; } } else { obj = nxobs[0]; } s_Attr s_attr; NXObject.AttributeInformation[] ais = obj.GetAttributeTitlesByType(NXObject.AttributeType.String); for (int i = 0; i < ais.Length; i++) { s_attr.title = ais[i].Title; s_attr.s_value = obj.GetStringAttribute(s_attr.title); s_attr.type = "string"; s_attr.i_value = 0; AttrList.Add(s_attr); } ais = obj.GetAttributeTitlesByType(NXObject.AttributeType.Integer); for (int i = 0; i < ais.Length; i++) { s_attr.title = ais[i].Title; s_attr.i_value = obj.GetIntegerAttribute(s_attr.title); s_attr.type = "int"; s_attr.s_value = ""; AttrList.Add(s_attr); } RefreshDisplay(); } }
/// <summary> /// 多選物件 /// </summary> /// <param name="objary"></param> /// <returns></returns> public static bool SelectObjects(out NXObject[] objary) { objary = new NXObject[] { }; try { UI theUI = UI.GetUI(); objary = new NXObject[] { }; theUI.SelectionManager.SelectObjects("Select Object", "Select Object", Selection.SelectionScope.AnyInAssembly, true, false, out objary); } catch (System.Exception ex) { return(false); } return(true); }
public static UserModel GetAttribute(NXObject obj) { UserModel model = new UserModel(); try { model.CreatorName = AttributeUtils.GetAttrForString(obj, "CreatorName"); model.CreatedDate = AttributeUtils.GetAttrForString(obj, "CreatedDate"); return(model); } catch (NXException ex) { throw ex; } }
public void function_note(string[] zhushiwenzi, DisplayableObject guanlian, NXObject zhiyinobj, Point3d placeptobj) { NXOpen.Annotations.SimpleDraftingAid nullAnnotations_SimpleDraftingAid = null; NXOpen.Annotations.PmiNoteBuilder pmiNoteBuilder1; pmiNoteBuilder1 = workPart.Annotations.CreatePmiNoteBuilder(nullAnnotations_SimpleDraftingAid); pmiNoteBuilder1.Origin.SetInferRelativeToGeometry(true); pmiNoteBuilder1.Origin.Anchor = NXOpen.Annotations.OriginBuilder.AlignmentPosition.MidCenter; pmiNoteBuilder1.TextAlignment = NXOpen.Annotations.DraftingNoteBuilder.TextAlign.Middle; pmiNoteBuilder1.Origin.Plane.PlaneMethod = NXOpen.Annotations.PlaneBuilder.PlaneMethodType.ModelView; pmiNoteBuilder1.Origin.SetInferRelativeToGeometry(true); NXOpen.Annotations.LeaderData leaderData1; leaderData1 = workPart.Annotations.CreateLeaderData(); leaderData1.Arrowhead = NXOpen.Annotations.LeaderData.ArrowheadType.FilledArrow; pmiNoteBuilder1.Leader.Leaders.Append(leaderData1); leaderData1.StubSide = NXOpen.Annotations.LeaderSide.Inferred; leaderData1.StubSize = 5.0; leaderData1.Perpendicular = false; //double symbolscale1; //symbolscale1 = pmiNoteBuilder1.Text.TextBlock.SymbolScale; //double symbolaspectratio1; //symbolaspectratio1 = pmiNoteBuilder1.Text.TextBlock.SymbolAspectRatio; Xform xform1; xform1 = workPart.Annotations.GetDefaultAnnotationPlane(NXOpen.Annotations.PmiDefaultPlane.ModelView); pmiNoteBuilder1.Origin.SetInferRelativeToGeometry(true); //pmiNoteBuilder1.Origin.SetInferRelativeToGeometry(true); pmiNoteBuilder1.Text.TextBlock.SetText(zhushiwenzi); //NXOpen.Annotations.Annotation.AssociativeOriginData assocOrigin1; //assocOrigin1.OriginType = NXOpen.Annotations.AssociativeOriginType.Drag; //NXOpen.View nullView = null; //assocOrigin1.View = nullView; //assocOrigin1.ViewOfGeometry = nullView; //NXOpen.Point nullPoint = null; //assocOrigin1.PointOnGeometry = nullPoint; //assocOrigin1.VertAnnotation = null; //assocOrigin1.VertAlignmentPosition = NXOpen.Annotations.AlignmentPosition.TopLeft; //assocOrigin1.HorizAnnotation = null; //assocOrigin1.HorizAlignmentPosition = NXOpen.Annotations.AlignmentPosition.TopLeft; //assocOrigin1.AlignedAnnotation = null; //assocOrigin1.DimensionLine = 0; //assocOrigin1.AssociatedView = nullView; //assocOrigin1.AssociatedPoint = nullPoint; //assocOrigin1.OffsetAnnotation = null; //assocOrigin1.OffsetAlignmentPosition = NXOpen.Annotations.AlignmentPosition.TopLeft; //assocOrigin1.XOffsetFactor = 0.0; //assocOrigin1.YOffsetFactor = 0.0; //assocOrigin1.StackAlignmentPosition = NXOpen.Annotations.StackAlignmentPosition.Above; //pmiNoteBuilder1.Origin.SetAssociativeOrigin(assocOrigin1); bool added1; added1 = pmiNoteBuilder1.AssociatedObjects.Objects.Add(guanlian); pmiNoteBuilder1.Origin.Origin.SetValue(null, null, placeptobj); pmiNoteBuilder1.Origin.SetInferRelativeToGeometry(true); if (zhiyinobj != null) { Point zhiyin = (Point)zhiyinobj; Point3d zhiyindian = zhiyin.Coordinates; //NXOpen.Features.Extrude extrude1 = (NXOpen.Features.Extrude)workPart.Features.FindObject("EXTRUDE(3)"); //Edge edge1 = (Edge)extrude1.FindObject("EDGE * 120 * 140 {(11,2,-5)(11,0.5,-5)(11,-1,-5) EXTRUDE(2)}"); //edge1.GetVertices(); leaderData1.Leader.SetValue(zhiyin, workPart.ModelingViews.WorkView, zhiyindian); } NXObject nXObject1; nXObject1 = pmiNoteBuilder1.Commit(); pmiNoteBuilder1.Destroy(); }