/// <summary> /// 设置层显示 /// </summary> /// <param name="view"></param> private void SetViewVisibleLayer(DraftingView view) { Basic.DrawingUtils.SetLayerHidden(view); Basic.DrawingUtils.SetLayerVisible(new int[1] { 201 }, view); }
/// <summary> /// 电极竖直标注 /// </summary> /// <param name="topView"></param> /// <param name="originPt"></param> /// <param name="scale"></param> private void EleProViewDimension(DraftingView topView, double scale, Point3d originPt) { string err = ""; int[] pre = model.Info.AllInfo.Preparetion.Preparation; List <Edge> xEdge = new List <Edge>(); Point centerPt; model.GetEdge(out xEdge, out centerPt); // Point3d originPt = topView.GetDrawingReferencePoint(); Point3d dimPt = new Point3d(originPt.X - (pre[1] * scale / 2 + 10), originPt.Y, 0); if (xEdge.Count == 0 || centerPt == null) { return; } try { NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionVertical(topView, dimPt, xEdge[0], centerPt, ref err); if (dim != null) { Basic.DrawingUtils.SetDimensionPrecision(dim, 3); } } catch (NXException ex) { ClassItem.WriteLogFile(model.AssembleName + "电极视图竖直标注错误!" + ex.Message); } }
/// <summary> /// 创建视图 /// </summary> /// <param name="scale"></param> /// <param name="originPt"></param> /// <param name="tablePath"></param> public void CreateView(double scale, Point3d originPt, string tablePath) { Point3d projectedPt = new Point3d(); projectedPt.X = originPt.X; projectedPt.Y = originPt.Y - this.drawModel.DisPt.Y * scale - this.drawModel.DisPt.Z * scale - 30; double[] tableOrigin = new double[3] { originPt.X - 35, projectedPt.Y - this.drawModel.DisPt.Z * scale - 15, 0 }; List <NXOpen.Assemblies.Component> allComp = new List <NXOpen.Assemblies.Component>(); allComp.AddRange(workDra.HostComp); allComp.AddRange(workDra.OtherComp); List <NXOpen.Assemblies.Component> hiddenComd = this.drawModel.GetHiddenObjects(allComp); hiddenComd.AddRange(workDra.GetEleComp()); try { DraftingView topView = Basic.DrawingUtils.CreateView("top", originPt, scale, this.workModel.Info.Matr, hiddenComd.ToArray()); DraftingView proView = Basic.DrawingUtils.CreateProjectedView(topView, projectedPt, scale); SetViewVisibleLayer(topView); SetViewVisibleLayer(proView); TopDimension(topView, originPt, scale); ProjectedDimension(proView, projectedPt, scale); } catch (NXException ex) { ClassItem.WriteLogFile(this.drawModel.WorkpiecePart.Name + "创建视图! " + ex.Message); } SetTable(tablePath, tableOrigin); }
/// <summary> /// 隐藏工作视图组件 /// </summary> /// <param name="ct"></param> /// <returns></returns> public static bool HideComponent(DraftingView view = null, params NXOpen.Assemblies.Component[] ct) { Part workPart = theSession.Parts.Work; NXOpen.Assemblies.HideComponentBuilder hideComponentBuilder1; hideComponentBuilder1 = workPart.AssemblyManager.CreateHideComponentBuilder(); bool added1; added1 = hideComponentBuilder1.Components.Add(ct); if (view != null) { hideComponentBuilder1.Views.Add(view); } try { NXOpen.NXObject nXObject1; nXObject1 = hideComponentBuilder1.Commit(); return(true); } catch (NXException ex) { LogMgr.WriteLog("AssmbliesUtils:HideComponent: " + ex.Message); return(false); } finally { hideComponentBuilder1.Destroy(); } }
/// <summary> /// 显示工作视图组件 /// </summary> /// <param name="ct"></param> /// <returns></returns> public static bool ShowComponent(DraftingView view = null, params NXOpen.Assemblies.Component[] ct) { Part workPart = theSession.Parts.Work; NXOpen.Assemblies.ShowComponentBuilder showComponentBuilder1; showComponentBuilder1 = workPart.AssemblyManager.CreateShowComponentBuilder(); NXOpen.SelectTaggedObjectList selectTaggedObjectList1; selectTaggedObjectList1 = showComponentBuilder1.Components; bool added1; added1 = selectTaggedObjectList1.Add(ct); if (view != null) { showComponentBuilder1.Views.Add(view); } showComponentBuilder1.MaintainComponentsShown = false; try { NXOpen.NXObject nXObject1; nXObject1 = showComponentBuilder1.Commit(); return(true); } catch (NXException ex) { LogMgr.WriteLog("AssmbliesUtils:ShowComponent: " + ex.Message); return(false); } finally { showComponentBuilder1.Destroy(); } }
private void EleTopDimension(DraftingView topView, Point3d originPt, double scale, Face face) { int[] pre = draInfo.DraModel.Eles[0].EleInfo.Preparation; List <Edge> xEdge = new List <Edge>(); List <Edge> yEdge = new List <Edge>(); string err = ""; Point3d pt1 = new Point3d(originPt.X - (pre[0] * scale / 2 + 10), originPt.Y, 0); Point3d pt2 = new Point3d(originPt.X, originPt.Y - (pre[1] * scale / 2 + 10), 0); this.draInfo.GetEdge(face, out xEdge, out yEdge); if (xEdge.Count == 0 && yEdge.Count == 0) { return; } NXOpen.Annotations.Dimension dim1 = Basic.DrawingUtils.DimensionVertical(topView, pt1, xEdge[0], xEdge[1], ref err); if (dim1 != null) { Basic.DrawingUtils.SetDimensionPrecision(dim1, 0); } NXOpen.Annotations.Dimension dim2 = Basic.DrawingUtils.DimensionHorizontal(topView, pt2, yEdge[0], yEdge[1], ref err); if (dim2 != null) { Basic.DrawingUtils.SetDimensionPrecision(dim2, 0); } }
private void SetViewVisible(DraftingView view) { Basic.DrawingUtils.SetLayerHidden(view); Basic.DrawingUtils.SetLayerVisible(new int[2] { 1, 20 }, view); // Basic.DrawingUtils.ShowComponent(view, this.workpiece.workpieceComp); }
public void ByName_ValidArgs() { var view = DraftingView.ByName("poodle"); Assert.NotNull(view); Assert.IsTrue(DocumentManager.Instance.ElementExistsInDocument( new ElementUUID(view.InternalElement.UniqueId))); }
private void CreateView() { double scale = GetScale(); NXOpen.Drawings.DrawingSheet sheet = Basic.DrawingUtils.DrawingSheet(eleTemplate, 297, 420, draInfo.DraModel.AssembleName); Point3d origin = GetViewOriginPt(scale); Point3d projectedPt = new Point3d(0, 0, 0); projectedPt.X = origin.X; projectedPt.Y = origin.Y - (draInfo.DisPt.Y + draInfo.DisPt.Z) * scale - 30; DraftingView topView = Basic.DrawingUtils.CreateView("TOP", origin, scale, draInfo.DraModel.Work.WorkMatr, draInfo.GetHideComp()); DraftingView proView = Basic.DrawingUtils.CreateProjectedView(topView, projectedPt, scale); double eleScale = GetEleScale(); int[] pre = draInfo.DraModel.Eles[0].EleInfo.Preparation; Point3d eleOrigin = GetEleOrigin(eleScale); Point3d projectedElePt1 = new Point3d(eleOrigin.X, eleOrigin.Y + (pre[1] * eleScale / 2 + pre[2] * eleScale / 2 + 30), 0); Point3d projectedElePt2 = new Point3d(projectedElePt1.X - (pre[0] * eleScale / 2 + pre[1] * eleScale / 2 + 30), projectedElePt1.Y, 0); DraftingView topEleView = Basic.DrawingUtils.CreateView("TOP", eleOrigin, eleScale, draInfo.DraModel.Eles[0].EleMatr, draInfo.GetEleHideComp()); Basic.DrawingUtils.SetWireframeColorSource(NXOpen.Preferences.GeneralWireframeColorSourceOption.FromFace, topEleView); DraftingView proEleView1 = Basic.DrawingUtils.CreateProjectedView(topEleView, projectedElePt1, eleScale); DraftingView proEleView2 = Basic.DrawingUtils.CreateProjectedView(proEleView1, projectedElePt2, eleScale); Matrix4 mat = new Matrix4(draInfo.DraModel.Eles[0].EleMatr); mat.RolateWithX(-2 * Math.PI / 5); mat.RolateWithY(Math.PI / 10); DraftingView topEleView2 = Basic.DrawingUtils.CreateView("Trimetric", new Point3d(240, 120, 0), eleScale, mat, draInfo.GetEleHideComp()); List <Point> elePoint = this.draInfo.DraModel.GetEleCompPint(); Point workPoint = this.draInfo.DraModel.GetWorkCompPoint(); TopDimension(topView, origin, scale, workPoint, elePoint); ProViewDimension(proView, projectedPt, scale, workPoint, elePoint); List <Face> face = this.draInfo.EleFaceSort(); // EleTopDimension(topEleView, eleOrigin, eleScale, face[0]); EleProViewDimension(proEleView2, projectedElePt2, eleScale, face[10], elePoint[0]); SetViewVisible(new DraftingView[6] { topView, proView, topEleView, proEleView1, proEleView2, topEleView2 }); if (this.draInfo.DraModel.EleInfo.IsPreparation) { Basic.DrawingUtils.SetNote(new Point3d(130, 20, 0), 6, "标准铜料"); } else if (!this.draInfo.DraModel.EleInfo.IsPreparation) { Basic.DrawingUtils.SetNote(new Point3d(130, 20, 0), 6, "非标准铜料"); } Basic.DrawingUtils.SetNote(new Point3d(130, 30, 0), 4, this.draInfo.EleModel.EleInfo.ElePresentation); Basic.DrawingUtils.UpdateViews(sheet); }
/// <summary> /// 创建电极视图 /// </summary> public void CreateEleView() { double eleScale = model.GetEleScale(90, 150.0); int[] pre = model.Info.AllInfo.Preparetion.Preparation; Point3d eleOrigin = GetEleOrigin(eleScale); Point3d projectedElePt1 = new Point3d(eleOrigin.X, eleOrigin.Y + (pre[1] * eleScale / 2 + pre[2] * eleScale / 2 + 30), 0); Point3d projectedElePt2 = new Point3d(projectedElePt1.X - (pre[0] * eleScale / 2 + pre[1] * eleScale / 2 + 30), projectedElePt1.Y, 0); Point3d projectedElePt3 = new Point3d(projectedElePt2.X - pre[1] - 10, projectedElePt2.Y, 0); DraftingView topEleView = null; try { topEleView = Basic.DrawingUtils.CreateView("TOP", eleOrigin, eleScale, model.GetEleMatr(), eleHidden.ToArray()); } catch (NXException ex) { ClassItem.WriteLogFile(model.AssembleName + "电极视图创建错误!" + ex.Message); return; } Basic.DrawingUtils.SetWireframeColorSource(NXOpen.Preferences.GeneralWireframeColorSourceOption.FromFace, topEleView); DraftingView proEleView1; DraftingView proEleView2; try { proEleView1 = Basic.DrawingUtils.CreateProjectedView(topEleView, projectedElePt1, eleScale); proEleView2 = Basic.DrawingUtils.CreateProjectedView(proEleView1, projectedElePt2, eleScale); } catch (NXException ex) { ClassItem.WriteLogFile(model.AssembleName + "电极视图创建错误!" + ex.Message); return; } EleProViewDimension(proEleView2, eleScale, projectedElePt2); Matrix4 mat = model.GetEleMatr(); mat.RolateWithX(-2 * Math.PI / 5); mat.RolateWithY(Math.PI / 10); DraftingView topEleView2; try { topEleView2 = Basic.DrawingUtils.CreateView("Trimetric", new Point3d(240, 120, 0), eleScale, mat, eleHidden.ToArray()); } catch (NXException ex) { ClassItem.WriteLogFile(model.AssembleName + "电极视图创建错误!" + ex.Message); return; } SetViewVisible(new DraftingView[] { topEleView, proEleView1, proEleView2, topEleView2 }); }
private void ProViewDimension(DraftingView topView, Point3d originPt, double scale, Point workPoint, List <Point> elePoint) { string err = ""; Point3d dimPt = new Point3d(originPt.X - (this.draInfo.DisPt.X * scale + 10), originPt.Y + (this.draInfo.DisPt.X * scale), 0); NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionVertical(topView, dimPt, workPoint, elePoint[0], ref err); if (dim != null) { Basic.DrawingUtils.AppendedTextDim(dim, "EDM SETTING"); SetDimColor(dim); } }
private void TopDimension(DraftingView topView, Point3d originPt, double scale, Point workPoint, List <Point> elePoint) { string err = ""; Matrix4 mat = this.draInfo.DraModel.Work.WorkMatr; PointSort(ref elePoint, mat, "X"); for (int i = 0; i < elePoint.Count; i++) { Point3d dimPt = new Point3d(originPt.X + 10.0, originPt.Y + this.draInfo.DisPt.Y * scale + (10 * (i + 1)), 0); NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionHorizontal(topView, dimPt, workPoint, elePoint[i], ref err); if (dim != null) { Basic.DrawingUtils.AppendedTextDim(dim, "EDM SETTING"); SetDimColor(dim); } //Point3d temp = (elePoint[i].Prototype as Point).Coordinates; //if (temp.X != 0) //{ // double crude = -(this.draInfo.DraModel.Eles[0].EleInfo.CrudeInter); // double fine = -(this.draInfo.DraModel.Eles[0].EleInfo.FineInter); // if (crude != 0 && fine != 0) // Basic.DrawingUtils.ToleranceDim(dim, NXOpen.Annotations.ToleranceType.BilateralTwoLines, fine, crude); // if (crude != 0 && fine == 0) // Basic.DrawingUtils.ToleranceDim(dim, NXOpen.Annotations.ToleranceType.BilateralTwoLines, 0, crude); // if (crude == 0 && fine != 0) // Basic.DrawingUtils.ToleranceDim(dim, NXOpen.Annotations.ToleranceType.BilateralTwoLines, 0, fine); //} } PointSort(ref elePoint, mat, "Y"); for (int i = 0; i < elePoint.Count; i++) { Point3d dimPt = new Point3d(originPt.X - (this.draInfo.DisPt.X * scale + 8 * (i + 1)), originPt.Y + 10, 0); NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionVertical(topView, dimPt, workPoint, elePoint[i], ref err); if (dim != null) { Basic.DrawingUtils.AppendedTextDim(dim, "EDM SETTING"); SetDimColor(dim); } //Point3d temp = (elePoint[i].Prototype as Point).Coordinates; //if (temp.Y != 0) //{ // double crude = -(this.draInfo.DraModel.Eles[0].EleInfo.CrudeInter); // double fine = -(this.draInfo.DraModel.Eles[0].EleInfo.FineInter); // if (crude != 0 && fine != 0) // Basic.DrawingUtils.ToleranceDim(dim, NXOpen.Annotations.ToleranceType.BilateralTwoLines, fine, crude); // if (crude != 0 && fine == 0) // Basic.DrawingUtils.ToleranceDim(dim, NXOpen.Annotations.ToleranceType.BilateralTwoLines, 0, crude); // if (crude == 0 && fine != 0) // Basic.DrawingUtils.ToleranceDim(dim, NXOpen.Annotations.ToleranceType.BilateralTwoLines, 0, fine); //} } }
public void GetBorders(DraftingView view) { UFSession theUFSession = UFSession.GetUFSession(); double[] borders = new double[4]; theUFSession.Draw.AskViewBorders(view.Tag, borders); Point3d disPt = new Point3d(0, 0, 0); Point3d centerPt = new Point3d(0, 0, 0); disPt.X = (borders[2] - borders[0]) / 2; disPt.Y = (borders[3] - borders[1]) / 2; centerPt.X = (borders[0] + borders[2]) / 2; centerPt.Y = (borders[1] + borders[3]) / 2; }
/// <summary> /// 创建投影视图 /// </summary> public static ProjectedView ProjectedView(DraftingView view, Point2d point) { var workPart = Session.GetSession().Parts.Work; ProjectedView nullDrawings_ProjectedView = null; var projectedViewBuilder1 = workPart.DraftingViews.CreateProjectedViewBuilder(nullDrawings_ProjectedView); //设置基本视图 projectedViewBuilder1.Parent.View.Value = view; //定位 var p = new Point3d(point.X, point.Y, 0.0); projectedViewBuilder1.Placement.Placement.SetValue(null, workPart.Views.WorkView, p); nullDrawings_ProjectedView = projectedViewBuilder1.Commit() as ProjectedView; projectedViewBuilder1.Destroy(); return(nullDrawings_ProjectedView); }
public void CreateView(double scale, Point3d originPt, string tablePath) { Point3d projectedPt = new Point3d(); projectedPt.X = originPt.X; projectedPt.Y = originPt.Y - this.workpiece.DisPt.Y * scale - this.workpiece.DisPt.Z * scale - 30; double[] tableOrigin = new double[3] { originPt.X - 35, projectedPt.Y - this.workpiece.DisPt.Z * scale - 15, 0 }; DraftingView topView = Basic.DrawingUtils.CreateView("TOP", originPt, scale, this.work.WorkMatr, this.workpiece.GetHideComp()); DraftingView proView = Basic.DrawingUtils.CreateProjectedView(topView, projectedPt, scale); SetViewVisible(topView); SetViewVisible(proView); TopDimension(topView, originPt, scale); ProjectedDimension(proView, projectedPt, scale); SetTable(tablePath, tableOrigin); }
private void EleProViewDimension(DraftingView topView, Point3d originPt, double scale, Face face, Point elePoint) { string err = ""; int[] pre = draInfo.DraModel.Eles[0].EleInfo.Preparation; List <Edge> xEdge = new List <Edge>(); List <Edge> yEdge = new List <Edge>(); this.draInfo.GetEdge(face, out xEdge, out yEdge); Point3d dimPt = new Point3d(originPt.X, originPt.Y - (pre[1] * scale / 2 + 10), 0); if (xEdge.Count == 0) { return; } NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionVertical(topView, dimPt, xEdge[0], elePoint, ref err); if (dim != null) { Basic.DrawingUtils.SetDimensionPrecision(dim, 1); } }
/// <summary> /// 设定视图竖直标注 /// </summary> /// <param name="topView"></param> /// <param name="originPt"></param> /// <param name="scale"></param> /// <param name="workPoint"></param> /// <param name="elePoint"></param> private void ProViewDimension(DraftingView topView, double scale, Point3d originPt, Point workPoint, List <Point> elePoint) { string err = ""; Matrix4 mat = model.GetWorkMatr(); // Point3d originPt = topView.GetDrawingReferencePoint(); PointSort(ref elePoint, mat, "Z"); double zTemmp = 0; int z = 0; for (int i = 0; i < elePoint.Count; i++) { Point3d zPt = elePoint[i].Coordinates; mat.ApplyPos(ref zPt); if (i == 0) { zTemmp = zPt.Z; } if (UMathUtils.IsEqual(zTemmp, zPt.Z) && i != 0) { continue; } Point3d dimPt = new Point3d(originPt.X - (disPt.X * scale + 8 * (z + 1)), originPt.Y + 10, 0); try { NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionVertical(topView, dimPt, workPoint, elePoint[0], ref err); if (dim != null) { Basic.DrawingUtils.AppendedTextDim(dim, "EDM SETTING"); SetDimColor(dim); } z++; } catch (NXException ex) { ClassItem.WriteLogFile(model.AssembleName + "设定视图竖直标注错误!" + ex.Message); } } }
/// <summary> /// 创建设定图 /// </summary> public NXOpen.Drawings.DrawingSheet CreateSetValueView() { Matrix4 inv = model.GetWorkMatr().GetInversMatrix(); inv.ApplyPos(ref centerPt); double scale = model.GetScale(130.0, 170.0, disPt); NXOpen.Drawings.DrawingSheet sheet = Basic.DrawingUtils.DrawingSheet(eleTemplate, 297, 420, model.AssembleName); Point3d origin = GetSetValueViewOriginPt(scale); Point3d projectedPt = new Point3d(0, 0, 0); projectedPt.X = origin.X; projectedPt.Y = origin.Y - (disPt.Y + disPt.Z) * scale - 30; DraftingView topView = null; DraftingView proView = null; try { topView = Basic.DrawingUtils.CreateView("TOP", origin, scale, model.GetWorkMatr(), setValueHidden.ToArray()); proView = Basic.DrawingUtils.CreateProjectedView(topView, projectedPt, scale); } catch (NXException ex) { ClassItem.WriteLogFile(model.AssembleName + "视图创建错误!" + ex.Message); } Point workPt = model.CreateCenterPoint(); List <Point> setPt = model.GetEleSetPoint(); if (topView != null || workPt == null || setPt.Count > 0) { TopDimension(topView, scale, origin, workPt, setPt); } if (proView != null || workPt == null || setPt.Count > 0) { ProViewDimension(proView, scale, projectedPt, workPt, setPt); } SetViewVisible(new DraftingView[] { topView, proView }); return(sheet); }
/// <summary> /// 投影视图标注 /// </summary> /// <param name="topView"></param> /// <param name="originPt"></param> private void ProjectedDimension(DraftingView topView, Point3d originPt, double scale) { string err = ""; Point3d minPt = drawModel.MinPt.Coordinates; Point3d maxPt = drawModel.MaxPt.Coordinates; this.workModel.Info.Matr.ApplyPos(ref minPt); this.workModel.Info.Matr.ApplyPos(ref maxPt); if (!UMathUtils.IsEqual(minPt.Z, 0)) { Point3d dimPt = new Point3d(0, 0, 0); dimPt.X = originPt.X - this.drawModel.DisPt.X * scale - 10.0; dimPt.Y = originPt.Y - this.drawModel.DisPt.Z * scale - 10.0; try { Basic.DrawingUtils.DimensionVertical(topView, dimPt, this.originPoint, drawModel.MinPt, ref err); } catch (NXException ex) { ClassItem.WriteLogFile(this.drawModel.WorkpiecePart.Name + "投影标准错误! " + ex.Message); } } if (!UMathUtils.IsEqual(maxPt.Z, 0)) { Point3d dimPt = new Point3d(0, 0, 0); dimPt.X = originPt.X + this.drawModel.DisPt.X * scale + 10.0; dimPt.Y = originPt.Y + this.drawModel.DisPt.Z * scale + 10.0; try { Basic.DrawingUtils.DimensionVertical(topView, dimPt, this.originPoint, drawModel.MaxPt, ref err); } catch (NXException ex) { ClassItem.WriteLogFile(this.drawModel.WorkpiecePart.Name + "投影标准错误! " + ex.Message); } } }
/// <summary> /// 投影视图标注 /// </summary> /// <param name="topView"></param> /// <param name="originPt"></param> private void ProjectedDimension(DraftingView topView, Point3d originPt, double scale) { string err = ""; Point[] pointComp = this.workpiece.GetPointOcc(); Point3d minPt = GetPoint(pointComp[0]); Point3d maxPt = GetPoint(pointComp[1]); if (!UMathUtils.IsEqual(minPt.Z, 0)) { Point3d dimPt = new Point3d(0, 0, 0); dimPt.X = originPt.X - this.workpiece.DisPt.X * scale - 10.0; dimPt.Y = originPt.Y - this.workpiece.DisPt.Z * scale - 10.0; Basic.DrawingUtils.DimensionVertical(topView, dimPt, this.originPoint, pointComp[0], ref err); } if (!UMathUtils.IsEqual(maxPt.Z, 0)) { Point3d dimPt = new Point3d(0, 0, 0); dimPt.X = originPt.X + this.workpiece.DisPt.X * scale + 10.0; dimPt.Y = originPt.Y + this.workpiece.DisPt.Z * scale + 10.0; Basic.DrawingUtils.DimensionVertical(topView, dimPt, this.originPoint, pointComp[1], ref err); } }
public static DraftingView Wrap(Autodesk.Revit.DB.ViewDrafting view, bool isRevitOwned) { return(DraftingView.FromExisting(view, isRevitOwned)); }
/// <summary> /// 竖直标注 /// </summary> /// <param name="view"></param> /// <param name="xMarginPos"></param> /// <param name="yMarginPos"></param> /// <param name="xPos"></param> /// <param name="yPos"></param> /// <param name="obj"></param> /// <param name="ordinateOriginDimension1"></param> /// <param name="isdogle"></param> /// <param name="tolerBasic"></param> /// <returns></returns> public static NXObject DimensionVertical(DraftingView view, double xMarginPos, double yMarginPos, double xPos, double yPos, NXObject obj, OrdinateOriginDimension ordinateOriginDimension1, bool isdogle, ref string errorMsg, bool tolerBasic = false) { Session theSession = Session.GetSession(); Part workPart = theSession.Parts.Work; Part displayPart = theSession.Parts.Display; Point3d origin4 = new Point3d(xMarginPos, yMarginPos, 0.0); OrdinateMargin ordinateMargin2; ordinateMargin2 = workPart.Annotations.OrdinateMargins.CreateInferredMargin(ordinateOriginDimension1, origin4, 14); NXObject nullNXObject = null; DimensionData dimensionData3; dimensionData3 = workPart.Annotations.NewDimensionData(); Associativity associativity9; associativity9 = workPart.Annotations.NewAssociativity(); associativity9.FirstObject = ordinateOriginDimension1; associativity9.SecondObject = nullNXObject; associativity9.ObjectView = workPart.Views.WorkView; associativity9.PointOption = AssociativityPointOption.None; associativity9.LineOption = AssociativityLineOption.None; Point3d firstDefinitionPoint5 = new Point3d(0.0, 0.0, 0.0); associativity9.FirstDefinitionPoint = firstDefinitionPoint5; Point3d secondDefinitionPoint5 = new Point3d(0.0, 0.0, 0.0); associativity9.SecondDefinitionPoint = secondDefinitionPoint5; associativity9.Angle = 0.0; Point3d pickPoint5 = new Point3d(0.0, 0.0, 0.0); associativity9.PickPoint = pickPoint5; Associativity[] associativity10 = new Associativity[1]; associativity10[0] = associativity9; dimensionData3.SetAssociativity(1, associativity10); Associativity associativity11; associativity11 = workPart.Annotations.NewAssociativity(); associativity11.FirstObject = obj; associativity11.SecondObject = nullNXObject; associativity11.ObjectView = view; associativity11.PointOption = AssociativityPointOption.Control; associativity11.LineOption = AssociativityLineOption.None; Point3d firstDefinitionPoint6 = new Point3d(0.0, 0.0, 0.0); associativity11.FirstDefinitionPoint = firstDefinitionPoint6; Point3d secondDefinitionPoint6 = new Point3d(0.0, 0.0, 0.0); associativity11.SecondDefinitionPoint = secondDefinitionPoint6; associativity11.Angle = 0.0; Point3d pickPoint6 = new Point3d(0.0, 0.0, 0.0); associativity11.PickPoint = pickPoint6; Associativity[] associativity12 = new Associativity[1]; associativity12[0] = associativity11; dimensionData3.SetAssociativity(2, associativity12); Associativity associativity13; associativity13 = workPart.Annotations.NewAssociativity(); VerticalOrdinateMargin verticalOrdinateMargin1 = ordinateMargin2 as VerticalOrdinateMargin; associativity13.FirstObject = verticalOrdinateMargin1; associativity13.SecondObject = nullNXObject; View nullView = null; associativity13.ObjectView = nullView; associativity13.PointOption = AssociativityPointOption.None; associativity13.LineOption = AssociativityLineOption.None; Point3d firstDefinitionPoint7 = new Point3d(0.0, 0.0, 0.0); associativity13.FirstDefinitionPoint = firstDefinitionPoint7; Point3d secondDefinitionPoint7 = new Point3d(0.0, 0.0, 0.0); associativity13.SecondDefinitionPoint = secondDefinitionPoint7; associativity13.Angle = 0.0; Point3d pickPoint7 = new Point3d(0.0, 0.0, 0.0); associativity13.PickPoint = pickPoint7; Associativity[] associativity14 = new Associativity[1]; associativity14[0] = associativity13; dimensionData3.SetAssociativity(3, associativity14); if (isdogle) { DimensionPreferences dimensionPreferences1; dimensionPreferences1 = workPart.Annotations.Preferences.GetDimensionPreferences(); OrdinateDimensionPreferences ordinateDimensionPreferences1; ordinateDimensionPreferences1 = dimensionPreferences1.GetOrdinateDimensionPreferences(); ordinateDimensionPreferences1.DoglegCreationOption = OrdinateDoglegCreationOption.Yes; dimensionPreferences1.SetOrdinateDimensionPreferences(ordinateDimensionPreferences1); dimensionData3.SetDimensionPreferences(dimensionPreferences1); } VerticalOrdinateDimension verticalOrdinateDimension1 = null; try { Point3d origin5 = new Point3d(xPos, yPos, 0.0); verticalOrdinateDimension1 = workPart.Dimensions.CreateVerticalOrdinateDimension(dimensionData3, origin5); //NXOpen.Annotations.LetteringPreferences letteringPreferences1; //letteringPreferences1 = verticalOrdinateDimension1.GetLetteringPreferences(); //NXOpen.Annotations.Lettering dimensionText1; //dimensionText1.Size = 18.0; //dimensionText1.CharacterSpaceFactor = 1.0; //dimensionText1.AspectRatio = 1.0; //dimensionText1.LineSpaceFactor = 1.0; //dimensionText1.Cfw.Color = 125; //dimensionText1.Cfw.Font = 2; //dimensionText1.Cfw.Width = NXOpen.Annotations.LineWidth.Thin; //dimensionText1.Italic = false; //letteringPreferences1.SetDimensionText(dimensionText1); //verticalOrdinateDimension1.SetLetteringPreferences(letteringPreferences1); NXOpen.Annotations.LinearTolerance tolPre = verticalOrdinateDimension1.GetTolerance(); tolPre.PrimaryDimensionDecimalPlaces = 2; if (tolerBasic) { tolPre.ToleranceType = NXOpen.Annotations.ToleranceType.Basic; } verticalOrdinateDimension1.SetTolerance(tolPre); return(verticalOrdinateDimension1); } catch (Exception ex) { errorMsg = ex.Message; LogMgr.WriteLog("DrawingUtils:DimensionVertical" + ex.Message); throw ex; } }
/// <summary> /// 竖直标注 /// </summary> /// <param name="view"></param> /// <param name="ori"></param> /// <param name="obj1"></param> /// <param name="obj2"></param> public static Dimension DimensionVertical(DraftingView view, Point3d ori, NXObject obj1, NXObject obj2, ref string errorMsg) { if (obj1 == null || obj2 == null) { LogMgr.WriteLog("DrawingUtils:DimensionVertical" + "标注为空"); return(null); } Session theSession = Session.GetSession(); Part workPart = theSession.Parts.Work; Part displayPart = theSession.Parts.Display; NXObject nullNXObject = null; DimensionData dimensionData2; dimensionData2 = workPart.Annotations.NewDimensionData(); Associativity associativity5; associativity5 = workPart.Annotations.NewAssociativity(); associativity5.FirstObject = obj1; associativity5.SecondObject = nullNXObject; associativity5.ObjectView = view; associativity5.PointOption = AssociativityPointOption.Control; associativity5.LineOption = AssociativityLineOption.None; Point3d firstDefinitionPoint3 = new Point3d(0.0, 0.0, 0.0); associativity5.FirstDefinitionPoint = firstDefinitionPoint3; Point3d secondDefinitionPoint3 = new Point3d(0.0, 0.0, 0.0); associativity5.SecondDefinitionPoint = secondDefinitionPoint3; associativity5.Angle = 0.0; Point3d pickPoint3 = new Point3d(0, 0, 0); associativity5.PickPoint = pickPoint3; Associativity[] associativity6 = new Associativity[1]; associativity6[0] = associativity5; dimensionData2.SetAssociativity(1, associativity6); Associativity associativity7; associativity7 = workPart.Annotations.NewAssociativity(); associativity7.FirstObject = obj2; associativity7.SecondObject = nullNXObject; associativity7.ObjectView = view; associativity7.PointOption = AssociativityPointOption.Control; associativity7.LineOption = AssociativityLineOption.None; Point3d firstDefinitionPoint4 = new Point3d(0.0, 0.0, 0.0); associativity7.FirstDefinitionPoint = firstDefinitionPoint4; Point3d secondDefinitionPoint4 = new Point3d(0.0, 0.0, 0.0); associativity7.SecondDefinitionPoint = secondDefinitionPoint4; associativity7.Angle = 0.0; Point3d pickPoint4 = new Point3d(0.0, 0.0, 0.0); associativity7.PickPoint = pickPoint4; Associativity[] associativity8 = new Associativity[1]; associativity8[0] = associativity7; dimensionData2.SetAssociativity(2, associativity8); try { Point3d origin2 = new Point3d(0.0, 0.0, 0.0); VerticalDimension verticalDimension2; verticalDimension2 = workPart.Dimensions.CreateVerticalDimension(dimensionData2, origin2); //NXOpen.Annotations.LinearTolerance tolPre = verticalDimension2.GetTolerance(); //tolPre.PrimaryDimensionDecimalPlaces = 2; //verticalDimension2.SetTolerance(tolPre); //设置小数点后两位 Point3d origin3 = new Point3d(ori.X, ori.Y, ori.Z); verticalDimension2.AnnotationOrigin = origin3; verticalDimension2.LeaderOrientation = LeaderOrientation.FromLeft; return(verticalDimension2); } catch (Exception ex) { errorMsg = ex.Message; LogMgr.WriteLog("DrawingUtils:DimensionVertical" + ex.Message); throw ex; } }
/// <summary> /// 横向标准 /// </summary> /// <param name="view"></param> /// <param name="xMarginPos"></param> /// <param name="yMarginPos"></param> /// <param name="xPos"></param> /// <param name="yPos"></param> /// <param name="obj"></param> /// <param name="ordinateOriginDimension1"></param> /// <param name="isdogle"></param> /// <param name="tolerBasic"></param> /// <returns></returns> public static NXObject DimensionHorizontal(DraftingView view, double xMarginPos, double yMarginPos, double xPos, double yPos, NXObject obj, OrdinateOriginDimension ordinateOriginDimension1, bool isdogle, ref string errorMsg, bool tolerBasic = false) { Session theSession = Session.GetSession(); Part workPart = theSession.Parts.Work; Part displayPart = theSession.Parts.Display; NXObject nullNXObject = null; Point3d origin2 = new Point3d(xMarginPos, yMarginPos, 0.0); OrdinateMargin ordinateMargin1; ordinateMargin1 = workPart.Annotations.OrdinateMargins.CreateInferredMargin(ordinateOriginDimension1, origin2, 13); DimensionData dimensionData2; dimensionData2 = workPart.Annotations.NewDimensionData(); Associativity associativity3; associativity3 = workPart.Annotations.NewAssociativity(); associativity3.FirstObject = ordinateOriginDimension1; associativity3.SecondObject = nullNXObject; associativity3.ObjectView = workPart.Views.WorkView; associativity3.PointOption = AssociativityPointOption.Control; associativity3.LineOption = AssociativityLineOption.None; Point3d firstDefinitionPoint2 = new Point3d(0.0, 0.0, 0.0); associativity3.FirstDefinitionPoint = firstDefinitionPoint2; Point3d secondDefinitionPoint2 = new Point3d(0.0, 0.0, 0.0); associativity3.SecondDefinitionPoint = secondDefinitionPoint2; associativity3.Angle = 0.0; Point3d pickPoint2 = new Point3d(0.0, 0.0, 0.0); associativity3.PickPoint = pickPoint2; Associativity[] associativity4 = new Associativity[1]; associativity4[0] = associativity3; dimensionData2.SetAssociativity(1, associativity4); Associativity associativity5; associativity5 = workPart.Annotations.NewAssociativity(); associativity5.FirstObject = obj; associativity5.SecondObject = nullNXObject; associativity5.ObjectView = view; associativity5.PointOption = AssociativityPointOption.Control; associativity5.LineOption = AssociativityLineOption.None; Point3d firstDefinitionPoint3 = new Point3d(0.0, 0.0, 0.0); associativity5.FirstDefinitionPoint = firstDefinitionPoint3; Point3d secondDefinitionPoint3 = new Point3d(0.0, 0.0, 0.0); associativity5.SecondDefinitionPoint = secondDefinitionPoint3; associativity5.Angle = 0.0; // Point3d pickPoint3(-272.0, -147.259337018431, -100.945677475); Point3d pickPoint3 = new Point3d(0.0, 0.0, 0.0); associativity5.PickPoint = pickPoint3; Associativity[] associativity6 = new Associativity[1]; associativity6[0] = associativity5; dimensionData2.SetAssociativity(2, associativity6); Associativity associativity7; associativity7 = workPart.Annotations.NewAssociativity(); HorizontalOrdinateMargin horizontalOrdinateMargin1 = ordinateMargin1 as HorizontalOrdinateMargin; associativity7.FirstObject = horizontalOrdinateMargin1; associativity7.SecondObject = nullNXObject; View nullView = null; associativity7.ObjectView = nullView; associativity7.PointOption = AssociativityPointOption.Control; associativity7.LineOption = AssociativityLineOption.None; Point3d firstDefinitionPoint4 = new Point3d(0.0, 0.0, 0.0); associativity7.FirstDefinitionPoint = firstDefinitionPoint4; Point3d secondDefinitionPoint4 = new Point3d(0.0, 0.0, 0.0); associativity7.SecondDefinitionPoint = secondDefinitionPoint4; associativity7.Angle = 0.0; Point3d pickPoint4 = new Point3d(0.0, 0.0, 0.0); associativity7.PickPoint = pickPoint4; Associativity[] associativity8 = new Associativity[1]; associativity8[0] = associativity7; dimensionData2.SetAssociativity(3, associativity8); if (isdogle) { DimensionPreferences dimensionPreferences1; dimensionPreferences1 = workPart.Annotations.Preferences.GetDimensionPreferences(); OrdinateDimensionPreferences ordinateDimensionPreferences1; ordinateDimensionPreferences1 = dimensionPreferences1.GetOrdinateDimensionPreferences(); ordinateDimensionPreferences1.DoglegCreationOption = OrdinateDoglegCreationOption.Yes; dimensionPreferences1.SetOrdinateDimensionPreferences(ordinateDimensionPreferences1); dimensionData2.SetDimensionPreferences(dimensionPreferences1); } HorizontalOrdinateDimension horizontalOrdinateDimension1 = null; try { Point3d origin3 = new Point3d(xPos, yPos, 0.0); horizontalOrdinateDimension1 = workPart.Dimensions.CreateHorizontalOrdinateDimension(dimensionData2, origin3); //NXOpen.Annotations.LetteringPreferences letteringPreferences1; //letteringPreferences1 = horizontalOrdinateDimension1.GetLetteringPreferences(); //NXOpen.Annotations.Lettering dimensionText1; //dimensionText1.Size = 18.0; //dimensionText1.CharacterSpaceFactor = 1.0; //dimensionText1.AspectRatio = 1.0; //dimensionText1.LineSpaceFactor = 1.0; //dimensionText1.Cfw.Color = 125; //dimensionText1.Cfw.Font = 2; //dimensionText1.Cfw.Width = NXOpen.Annotations.LineWidth.Thin; //dimensionText1.Italic = false; //letteringPreferences1.SetDimensionText(dimensionText1); //horizontalOrdinateDimension1.SetLetteringPreferences(letteringPreferences1); NXOpen.Annotations.LinearTolerance tolPre = horizontalOrdinateDimension1.GetTolerance(); tolPre.PrimaryDimensionDecimalPlaces = 2; if (tolerBasic) { tolPre.ToleranceType = NXOpen.Annotations.ToleranceType.Basic; } horizontalOrdinateDimension1.SetTolerance(tolPre); //自己修改的部分 // //设置尺寸为无公差样式 horizontalOrdinateDimension1.ToleranceType = ToleranceType.None; // return(horizontalOrdinateDimension1); } catch (Exception ex) { errorMsg = ex.Message; LogMgr.WriteLog("DrawingUtils:DimensionHorizontal" + ex.Message); throw ex; } }
private void SetViewSite(DraftingView topView, DraftingView proView, Point3d origin) { DrawingOperation topOper = new DrawingOperation(topView); DrawingOperation proOper = new DrawingOperation(proView); }
/// <summary> /// 设定视图水平标注 /// </summary> /// <param name="topView"></param> /// <param name="originPt"></param> /// <param name="scale"></param> /// <param name="workPoint"></param> /// <param name="elePoint"></param> private void TopDimension(DraftingView topView, double scale, Point3d originPt, Point workPoint, List <Point> elePoint) { string err = ""; Matrix4 mat = model.GetWorkMatr(); // Point3d originPt = topView.GetDrawingReferencePoint(); PointSort(ref elePoint, mat, "X"); double xTemmp = 0; int x = 0; for (int i = 0; i < elePoint.Count; i++) { Point3d xPt = elePoint[i].Coordinates; mat.ApplyPos(ref xPt); if (i == 0) { xTemmp = xPt.X; } if (UMathUtils.IsEqual(xTemmp, xPt.X) && i != 0) { continue; } Point3d dimPt = new Point3d(originPt.X + 10.0, originPt.Y + disPt.Y * scale + (10 * (x + 1)), 0); try { NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionHorizontal(topView, dimPt, workPoint, elePoint[i], ref err); if (dim != null) { Basic.DrawingUtils.AppendedTextDim(dim, "EDM SETTING"); SetDimColor(dim); } x++; } catch (NXException ex) { ClassItem.WriteLogFile(model.AssembleName + "设定视图水平标注错误!" + ex.Message); } } PointSort(ref elePoint, mat, "Y"); double yTemmp = 0; int y = 0; for (int i = 0; i < elePoint.Count; i++) { Point3d yPt = elePoint[i].Coordinates; mat.ApplyPos(ref yPt); if (i == 0) { yTemmp = yPt.Y; } if (UMathUtils.IsEqual(yTemmp, yPt.Y) && i != 0) { continue; } Point3d dimPt = new Point3d(originPt.X - (this.disPt.X * scale + 8 * (y + 1)), originPt.Y + 10, 0); try { NXOpen.Annotations.Dimension dim = Basic.DrawingUtils.DimensionVertical(topView, dimPt, workPoint, elePoint[i], ref err); if (dim != null) { Basic.DrawingUtils.AppendedTextDim(dim, "EDM SETTING"); SetDimColor(dim); } y++; } catch (NXException ex) { ClassItem.WriteLogFile(model.AssembleName + "设定竖直标注错误!" + ex.Message); } } }
public DrawingOperation(DraftingView view) { this.View = view; this.OriginPt = view.GetDrawingReferencePoint(); GetBorders(this.View); }