C# SolidWorks二次开发---工程图简单版标注孔信息

突然感觉好久没有写技术文章了,确实,回头看了一下上次的文章,快一个月了。我在忙什么?

文章目录

  • 目标
  • 一、要标什么?
  • 二、思路
  • 三、代码
  • 总结


目标

提示:今天的内容和上一篇属于一个范围,就是工程图的标注

其实代码已经完成好久了,只是没有发文章,今天来说一下孔信息标注的内容。


一、要标什么?

一般来说,工程图上的孔信息主要就是定位与大小,外加上公差 基准这些,但这有点复杂,我们从简,标X 方向 Y 方向 ,再标上孔大小,相同尺寸的合并一下前缀。

二、思路

与上篇类似就是找基准,找孔, 读信息,再标注。
在这里插入图片描述
感觉写了很多,但字却很少。 可能是觉得大家都已经学会了。
在这里插入图片描述

三、代码

在这里插入图片描述
代码有点多,反正我也讲不明白,就贴一下结果。
在这里插入图片描述

这样还是会有一些重叠问题,再调用一下自动整理尺寸的功能:
在这里插入图片描述
在这里插入图片描述

    private void btnAddDimForHoles_Click(object sender, EventArgs e){var swApp = PStandAlone.GetSolidWorks();var swModel = (ModelDoc2)swApp.ActiveDoc;AddSizeDimensionForDrawing addSizeDimensionForDrawing = new AddSizeDimensionForDrawing(swApp, swModel);addSizeDimensionForDrawing.AutoAddHoleDimesnions("");}
    /// <summary>/// 给工程图标注长宽/// </summary>internal class AddSizeDimensionForDrawing{public SldWorks swApp { get; set; }public ModelDoc2 swModel  { get; set; }public SelectData swSelData { get; set; }public string  strError { get; set; }//public string Options = "Two";/// <summary>/// 尺寸标注上方/// </summary>public bool DimOnTop = true;/// <summary>/// 尺寸标注左侧/// </summary>public bool DimOnLeft = true;/// <summary>/// 尺寸位置偏移量/// </summary>public double HorOffset = 0.005;/// <summary>/// 尺寸位置偏移量/// </summary>public double VerOffset = 0.005;#region Holes相关/// <summary>/// 孔边集合/// </summary>List<Edge> swHoleList = new List<Edge>();/// <summary>/// 边集合/// </summary>List<Edge> swEdgesList = new List<Edge>();/// <summary>/// 点集合/// </summary>List<Vertex> swPointList = new List<Vertex>();#endregionpublic AddSizeDimensionForDrawing(SldWorks App, ModelDoc2 model){swApp = App;swModel = model;}double AllowAutoArrange = 0;/// <summary>/// 自动增加孔尺寸/// </summary>/// <param name="s"></param>public void AutoAddHoleDimesnions(string s) {var swDraw = swModel as DrawingDoc;if (swDraw != null){HorOffset = 0;VerOffset = 0;var swModelDocExt = (ModelDocExtension)swModel.Extension;var swSelMgr = (SelectionMgr)swModel.SelectionManager;swModel.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swViewDisplayHideAllTypes, true);//当前图纸Sheet swSheet = (Sheet)swDraw.GetCurrentSheet();//所有视图var swViews = (object[])swSheet.GetViews();swModel.ClearSelection2(true);//循环for (int i = 0; i < swViews.Length; i++){View swView = (View)swViews[i];if (swView.GetOrientationName() != "*Isometric" && swView.GetOrientationName() != "*Trimetric" && swView.GetOrientationName() != "*Dimetric"){var vBounds = (double[])swView.GetOutline();var swViewType = System.IO.Path.GetExtension(swView.GetReferencedModelName());var vComps = (object[])swView.GetVisibleComponents();if ( swView.GetVisibleComponentCount() > 0 ){var vEdges = (object[])swView.GetVisibleEntities((Component2)vComps[0], (int)swViewEntityType_e.swViewEntityType_Edge);swSelData = (SelectData)swModel.ISelectionManager.CreateSelectData();swSelData.View = swView;                         MathTransform swViewXform = ViewMathTransform(swDraw, swView);for (int itr = 0; itr < vEdges.Length; itr++){var swCurve = (Curve)((Edge)vEdges[itr]).GetCurve();if (swCurve.IsCircle()) {var swCircleParam = swCurve.GetEndParams(out double StartP, out double EndP, out bool IsClosedP, out bool IsPeriodicP);if (IsClosedP){swHoleList.Add((Edge)vEdges[itr]);}}else {swEdgesList.Add((Edge)vEdges[itr]);var startVertex = ((Edge)vEdges[itr]).GetStartVertex();swPointList.Add((Vertex)startVertex);}}Entity swEntXmax = null, swEntXmin = null, swEntYmax = null, swEntYmin =null;var refModel = swView.ReferencedDocument;if (swViewType.ToString().ToLower()==".sldprt"){if (swPointList.Count>0){swEntXmax = FindExtremun(0, "max", swPointList, refModel.GetType(), swViewXform);swEntXmin = FindExtremun(0, "min", swPointList, refModel.GetType(), swViewXform);swEntYmax = FindExtremun(1, "max", swPointList, refModel.GetType(), swViewXform);swEntYmin = FindExtremun(1, "min", swPointList, refModel.GetType(), swViewXform);}if (swHoleList.Count>0){AllowAutoArrange = 0;HorOffset = HorOffset + 0.01;VerOffset = VerOffset + 0.001;var swHcollSortX = SortHoles(0, swHoleList, swViewType, "CleanYes", swViewXform);//            ' 0 = X ,1 = YPlaceHoleDimension((Vertex)swEntXmin , swHcollSortX, "Horizontal", vBounds, swViewType, swViewXform);var swHcollSortY = SortHoles(1, swHoleList, swViewType, "CleanYes", swViewXform);      //     ' 0 = X ,1 = YPlaceHoleDimension((Vertex)swEntYmax, swHcollSortY, "Vertical", vBounds, swViewType, swViewXform);PlaceHoleLocationDimension(swHoleList, vBounds, swViewType, swViewXform);}if (AllowAutoArrange > 0 && AllowAutoArrange< 0.005 ){var swViewAnnot = (object[])swView.GetAnnotations();Annotation annotation;foreach (var item in swViewAnnot){annotation = (Annotation)item;annotation.Select3(true, null);}swModelDocExt.AlignDimensions((int)swAlignDimensionType_e.swAlignDimensionType_AutoArrange, 0.001);}}}}}}swModel.ClearSelection2(true);swModel.GraphicsRedraw2();}/// <summary>/// 标注孔位置尺寸/// </summary>/// <param name="swHcoll"></param>/// <param name="vBounds"></param>/// <param name="swViewType"></param>/// <param name="swViewXform"></param>private void PlaceHoleLocationDimension(List<Edge> swHcoll, double[] vBounds, string swViewType, MathTransform swViewXform){try{var swColl = new List<Edge>();var swTempColl = new List<Edge>();swColl.AddRange(swHcoll);for (int n = swColl.Count - 1; n >= 0; n--){swTempColl.Clear();(swColl[n] as Entity).Select4(false, swSelData);var swCircleCurve = (Curve)swColl[n].GetCurve();var swCircleParams = (double[])swCircleCurve.CircleParams;var swTempRadius = swCircleParams[6];swTempColl.Add(swColl[n]);swColl.Remove(swColl[n]);for (int j = swColl.Count - 1; j >= 0; j--){swCircleCurve = (Curve)swColl[j].GetCurve();(swHcoll[j] as Entity).Select4(false, swSelData);swCircleParams = (double[])swCircleCurve.CircleParams;if (Math.Abs(swTempRadius-swCircleParams[6])<0.001) {swTempColl.Add(swColl[j]);swColl.Remove(swColl[j]);}              }swTempColl = SortHoles(1, swTempColl, swViewType, "CleanNo", swViewXform);swTempColl = SortHoles(0, swTempColl, swViewType, "CleanNo", swViewXform);swCircleParams = CircleCoordinates(swTempColl[0], swViewType, swViewXform);var Xpos = swCircleParams[0] - 0.025;var  Ypos = vBounds[3];(swTempColl[0] as Entity).Select4(false, swSelData);var myDisplayDim = (DisplayDimension)swModel.AddDimension2(Xpos, Ypos, 0);if (swTempColl.Count > 2){myDisplayDim.SetBrokenLeader2(false, (int)swDisplayDimensionLeaderText_e.swBrokenLeaderHorizontalText);var oldText = myDisplayDim.GetText((int)swDimensionTextParts_e.swDimensionTextPrefix);myDisplayDim.SetText((int)swDimensionTextParts_e.swDimensionTextPrefix, $"{swTempColl.Count}x{oldText}");}n = swColl.Count;}}catch (Exception ex ){swApp.SendMsgToUser(ex.StackTrace);throw;}}/// <summary>/// 标注孔尺寸/// </summary>/// <param name="swVertex"></param>/// <param name="swHcoll"></param>/// <param name="DimOrientation"></param>/// <param name="vBounds"></param>/// <param name="swViewType"></param>/// <param name="swViewXform"></param>private void PlaceHoleDimension(Vertex swVertex, List<Edge> swHcoll, string DimOrientation, double[] vBounds, string swViewType, MathTransform swViewXform){try{swModel.ClearSelection2(true);var vPt = PointCoordinates(swApp,swVertex, swViewType, swViewXform);var vPt2 = CircleCoordinates(swHcoll[0], swViewType, swViewXform);double Xpos, Ypos;(swVertex as Entity).Select4(true, swSelData);//double dblConvFactor = GetUnitConvFactor("");if (DimOrientation == "Horizontal"){(swHcoll[0] as Entity).Select4(true, swSelData);vPt2 = CircleCoordinates(swHcoll[0], swViewType, swViewXform);Xpos = (vPt[0] + vPt2[0]) / 2;Ypos = (vBounds[3] + HorOffset);if (AllowAutoArrange == 0 || AllowAutoArrange > (Math.Abs(vPt[0] - vPt2[0]))) {AllowAutoArrange = Math.Abs(vPt[0] - vPt2[0]);}var myDisplayDim = swModel.AddHorizontalDimension2(Xpos, Ypos, 0);}if (DimOrientation == "Vertical"){(swHcoll[0] as Entity).Select4(true, swSelData);vPt2 = CircleCoordinates(swHcoll[0], swViewType, swViewXform);Xpos = (vBounds[0] - VerOffset);Ypos = (vPt[1] + vPt2[1]) / 2; ;if (AllowAutoArrange == 0 || AllowAutoArrange > (Math.Abs(vPt[1] - vPt2[1]))){AllowAutoArrange = Math.Abs(vPt[1] - vPt2[1]);}var myDisplayDim = swModel.AddVerticalDimension2(Xpos, Ypos, 0);}swModel.ClearSelection2(true);for (int i = 0; i < swHcoll.Count-1; i++){swModel.ClearSelection2(true);(swHcoll[i+1] as Entity).Select4(true, swSelData);var vPt1 = CircleCoordinates(swHcoll[i], swViewType, swViewXform);vPt2 = CircleCoordinates(swHcoll[i + 1], swViewType, swViewXform);if (DimOrientation == "Horizontal"){if (Math.Round(vPt1[1],10)!= Math.Round(vPt2[1], 10)){(swVertex as Entity).Select4(true, swSelData);HorOffset = HorOffset + 0.005;Xpos = (vPt[0] + vPt2[0]) / 2;Ypos = (vBounds[3] + HorOffset);}else{(swHcoll[i] as Entity).Select4(true, swSelData);Xpos = (vPt1[0] + vPt2[0]) / 2;Ypos = (vBounds[3] + HorOffset);if (AllowAutoArrange == 0 || AllowAutoArrange > (Math.Abs(vPt[0] - vPt2[0]))){AllowAutoArrange = Math.Abs(vPt[0] - vPt2[0]);}}var myDisplayDim = swModel.AddHorizontalDimension2(Xpos, Ypos, 0);}else  if (DimOrientation == "Vertical") {(swHcoll[i] as Entity).Select4(true, swSelData);//vPt2 = CircleCoordinates(swHcoll[0], swViewType, swViewXform);Xpos = (vBounds[0] - VerOffset);Ypos = (vPt[1] + vPt2[1]) / 2; ;if (AllowAutoArrange == 0 || AllowAutoArrange > (Math.Abs(vPt[1] - vPt2[1]))){AllowAutoArrange = Math.Abs(vPt[1] - vPt2[1]);}var myDisplayDim = swModel.AddVerticalDimension2(Xpos, Ypos, 0);}}}catch (Exception ex ){swApp.SendMsgToUser(ex.StackTrace.ToString());throw;}}/// <summary>/// 排序孔/// </summary>/// <param name="axis"></param>/// <param name="swHcoll"></param>/// <param name="swViewType"></param>/// <param name="swNeedToClean"></param>/// <param name="swViewXform"></param>/// <returns></returns>private List<Edge> SortHoles(int axis, List<Edge> swHcoll, string swViewType, string swNeedToClean, MathTransform swViewXform){try{var swColl = new List<Edge>();swColl.AddRange(swHcoll);for (int i = 0; i < swColl.Count; i++){for (int j = 0; j < swColl.Count-i-1; j++){double[] swCircleParams1 = CircleCoordinates(swColl[j], swViewType, swViewXform);double[] swCircleParams2 = CircleCoordinates(swColl[j+1], swViewType, swViewXform);if (axis==0){if (swCircleParams1[axis]>swCircleParams2[axis]){var vTemp = swColl[j + 1];swColl.Remove(swColl[j + 1]);swColl.Insert(j, vTemp);}}else if (axis==1){if (swCircleParams1[axis] < swCircleParams2[axis]){var vTemp = swColl[j + 1];swColl.Remove(swColl[j + 1]);swColl.Insert(j, vTemp);}}}      }if (swNeedToClean== "CleanYes"){return CleanSortedHoles(axis, swColl, swViewType, swViewXform);}else if (swNeedToClean == "CleanNo"){return swColl;}return null;}catch (Exception ex ){swApp.SendMsgToUser(ex.StackTrace);return null;}}/// <summary>/// 清理排序过的孔,比如X值 一样, Y值 一样的/// </summary>/// <param name="axis"></param>/// <param name="swColl"></param>/// <param name="swViewType"></param>/// <param name="swViewXform"></param>/// <returns></returns>private List<Edge> CleanSortedHoles(int axis, List<Edge> swColl, string swViewType, MathTransform swViewXform){try{for (int k = 0; k < swColl.Count-2; k++){for (int n = swColl.Count - 1; n >= 1; n--){double[] swCircleParams1 = CircleCoordinates(swColl[n], swViewType, swViewXform);double[] swCircleParams2 = CircleCoordinates(swColl[n - 1], swViewType, swViewXform);if (Math.Abs(swCircleParams1[axis]- swCircleParams2[axis])<0.000001){if (axis == 0){if (swCircleParams1[Math.Abs(axis-1)] > swCircleParams2[Math.Abs(axis - 1)]){swColl.Remove(swColl[n - 1]);}else{swColl.Remove(swColl[n]);}}else if (axis == 1){if (swCircleParams1[Math.Abs(axis - 1)] < swCircleParams2[Math.Abs(axis - 1)]){swColl.Remove(swColl[n - 1]);}else{swColl.Remove(swColl[n]);}}}}}return swColl;}catch (Exception){throw;}}/// <summary>/// 圆点坐标/// </summary>/// <param name="swCircle"></param>/// <param name="swViewType"></param>/// <param name="swViewXform"></param>/// <returns></returns>private double[] CircleCoordinates(Edge swCircle, string swViewType, MathTransform swViewXform){Curve swCircleCurve = (Curve)swCircle.GetCurve();var swCircleParams = (double[])swCircleCurve.CircleParams;var vPt = new double[3];vPt[0] = swCircleParams[0];vPt[1] = swCircleParams[1];vPt[2] = swCircleParams[2];var swMathUtils =(MathUtility) swApp.GetMathUtility();var swMathPt = (MathPoint)swMathUtils.CreatePoint(vPt);var swComp =(Component2) (swCircle as Entity).GetComponent();if (swViewType.ToUpper()==".SLDASM"){var swCompXform = swComp.Transform2;var swTotalXForm = swCompXform.Multiply(swViewXform);swMathPt = (MathPoint)swMathPt.MultiplyTransform(swTotalXForm);}else{swMathPt = (MathPoint)swMathPt.MultiplyTransform(swViewXform);}return (double[])swMathPt.ArrayData;}/// <summary>/// 增加长宽尺寸/// </summary>/// <param name="Top">尺寸位置放左?</param>/// <param name="Left">尺寸位置放右?</param>public void AutoAddSize(bool Top = true, bool Left = true) {try{DimOnLeft = Left;DimOnTop = Top;AutoOveralDimensions();}catch (Exception){throw;}       }/// <summary>/// 标注/// </summary>public void AutoOveralDimensions() {var swDraw = swModel as DrawingDoc;if (swDraw != null) {//当前图纸Sheet swSheet = (Sheet)swDraw.GetCurrentSheet();//所有视图var swViews = (object[])swSheet.GetViews();//循环for (int i = 0; i < swViews.Length; i++) {View swView = (View)swViews[i];//可以排除关联视图if (swView.Type==(int)swDrawingViewTypes_e.swDrawingNamedView){if (swView.GetOrientationName() != "*Isometric" && swView.GetOrientationName() != "*Trimetric" && swView.GetOrientationName() != "*Dimetric"){ProcessView(swDraw, swView, true, true);//找关联视图var depHorView = GetAlignedDependantView(swView, 0);if (depHorView != null){ProcessView(swDraw, depHorView, true, false);}var depVerView = GetAlignedDependantView(swView, 1);if (depVerView != null){ProcessView(swDraw, depVerView, false, true);}}}}}swModel.ClearSelection2(true);swModel.GraphicsRedraw2();}/// <summary>/// 找关联视图/// </summary>/// <param name="swParentView"></param>/// <param name="intOrientation">方向,横向/纵向</param>/// <returns></returns>private View GetAlignedDependantView(View swParentView, int intOrientation){var delta = 0.00001;var intDependantViews = swParentView.GetDependentViewCount(false, (int)swDrawingViewTypes_e.swDrawingProjectedView);var objDependantViews = (object[])swParentView.GetDependentViews(false, (int)swDrawingViewTypes_e.swDrawingProjectedView);var ParentPos =(double[]) swParentView.Position;for (int i = 0; i < intDependantViews; i++){var depView = (View)objDependantViews[i];var DependantPos = (double[])depView.Position;if (Math.Abs(ParentPos[Math.Abs(intOrientation - 1)] - DependantPos[Math.Abs(intOrientation - 1)])<delta) {return depView;}}return null;}/// <summary>/// 遍历 点 ,计算再标注/// </summary>/// <param name="swDraw"></param>/// <param name="swView"></param>/// <param name="PlaceHorDim"></param>/// <param name="PlaceVerDim"></param>private void ProcessView(DrawingDoc swDraw, View swView, bool PlaceHorDim, bool PlaceVerDim){List<Vertex> swPcoll= new List<Vertex> ();swModel.ClearSelection2(true);var refModel= swView.ReferencedDocument;var vComps = (object[])swView.GetVisibleComponents();MathTransform swViewXform = ViewMathTransform(swDraw, swView);//获取所有直线边点for (int j = 0;j < swView.GetVisibleComponentCount(); j++){var vEdges = (object[])swView.GetVisibleEntities((Component2)vComps[j], (int)swViewEntityType_e.swViewEntityType_Edge);swSelData = (SelectData)swModel.ISelectionManager.CreateSelectData();for (int itr = 0; itr < vEdges.Length; itr++){var swCurve = (Curve)((Edge)vEdges[itr]).GetCurve();if (!swCurve.IsCircle()){var startVertex= (Vertex)((Edge)vEdges[itr]).GetStartVertex();var endVertex = (Vertex)((Edge)vEdges[itr]).GetEndVertex();if (startVertex !=null){swPcoll.Add(startVertex);}if (endVertex != null){swPcoll.Add(endVertex);}}}}Entity swEntXmax, swEntXmin, swEntYmax, swEntYmin;if (swPcoll.Count>0){swEntXmax = FindExtremun(0, "max", swPcoll, refModel.GetType(), swViewXform);swEntXmin = FindExtremun(0, "min", swPcoll, refModel.GetType(), swViewXform);swEntYmax = FindExtremun(1, "max", swPcoll, refModel.GetType(), swViewXform);swEntYmin = FindExtremun(1, "min", swPcoll, refModel.GetType(), swViewXform);var vBounds = (double[])swView.GetOutline();if (PlaceHorDim){PlaceOverallDimension(swModel, swEntXmax, swEntXmin, "Horizontal", vBounds);}if (PlaceVerDim){PlaceOverallDimension(swModel, swEntYmax, swEntYmin, "Vertical", vBounds);}}}/// <summary>/// 放置尺寸/// </summary>/// <param name="swModel"></param>/// <param name="swVertex1"></param>/// <param name="swVertex2"></param>/// <param name="DimOrientation"></param>/// <param name="vBounds"></param>private void PlaceOverallDimension(ModelDoc2 swModel, Entity swVertex1, Entity swVertex2, string DimOrientation, double[] vBounds){double dblConvFactor = GetUnitConvFactor("");if (DimOrientation == "Horizontal") {HorOffset = HorOffset * dblConvFactor;}if (DimOrientation == "Vertical"){VerOffset = VerOffset * dblConvFactor;}swModel.ClearSelection2(true);swVertex1.Select4(false, swSelData);swVertex2.Select4(true, swSelData);double Xpos, Ypos;if (DimOrientation == "Horizontal"){Xpos = (vBounds[0] + vBounds[2]) / 2;if(DimOnTop) //标注在顶部{Ypos = (vBounds[3] + HorOffset);}else{Ypos = (vBounds[1] - HorOffset);}var myDisplayDim = swModel.AddHorizontalDimension2(Xpos, Ypos, 0);} else if (DimOrientation == "Vertical"){Ypos = (vBounds[1] + vBounds[3]) / 2;if (DimOnLeft) {Xpos = (vBounds[0] - HorOffset);}else{Xpos = (vBounds[2] + HorOffset);}var myDisplayDim = swModel.AddVerticalDimension2(Xpos, Ypos, 0);}}/// <summary>/// 获取单位/// </summary>/// <param name="v"></param>/// <returns></returns>private double GetUnitConvFactor(string v){var LenUnit = swModel.GetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swUnitsLinear);switch (LenUnit){case 0  : return 0.001;case 1  : return 0.01;case 2  : return 1;case 3  : return 0.0254;case 4  : return 0.3048;case 5  : return -1;case 6  : return 0.0000000001;case 7  : return 0.000000001;case 8  : return 0.000001;case 9  : return 0.00254;case 10  : return 0.00000254;default:return -1;}         }/// <summary>/// 找极点/// </summary>/// <param name="axis"></param>/// <param name="MinMax"></param>/// <param name="swPcoll"></param>/// <param name="swViewType"></param>/// <param name="swViewXform"></param>/// <returns></returns>private Entity FindExtremun(int axis, string MinMax, List<Vertex> swPcoll, int swViewType, MathTransform swViewXform){var swVertex = swPcoll[0];var vPt = PointCoordinates(swVertex, swViewType, swViewXform);var Extr = vPt[axis];for (int i = 0; i < swPcoll.Count; i++){vPt = PointCoordinates(swPcoll[i], swViewType, swViewXform);if (MinMax=="max" && vPt[axis]>Extr){Extr = vPt[axis];swVertex = swPcoll[i];}else if (MinMax == "min" && vPt[axis] < Extr){Extr = vPt[axis];swVertex = swPcoll[i];}}return swVertex as Entity;}/// <summary>/// 坐标系转换/// </summary>/// <param name="swVertex"></param>/// <param name="swViewType"></param>/// <param name="swViewXform"></param>/// <returns></returns>private double[] PointCoordinates(Vertex swVertex, int swViewType, MathTransform swViewXform){var swMathUtils = swApp.IGetMathUtility();var vPt = (double[])swVertex.GetPoint();var swMathPt = (MathPoint)swMathUtils.CreatePoint(vPt);if (swViewType==(int)swDocumentTypes_e.swDocASSEMBLY){var swComp =(Component2) (swVertex as Entity).GetComponent();if (swComp!=null){MathTransform swCompXform = swComp.Transform2;MathTransform swTotalXForm = (MathTransform)swCompXform.Multiply(swViewXform);swMathPt = (MathPoint)swMathPt.MultiplyTransform(swTotalXForm);}}else{swMathPt = (MathPoint)swMathPt.MultiplyTransform(swViewXform);}return (double[])swMathPt.ArrayData;}/// <summary>/// 坐标系转换/// </summary>/// <param name="swVertex"></param>/// <param name="swViewType"></param>/// <param name="swViewXform"></param>/// <returns></returns>private double[] PointCoordinates(SldWorks swApp,Vertex swVertex, string swViewType, MathTransform swViewXform){var swMathUtils = swApp.IGetMathUtility();var vPt = (double[])swVertex.GetPoint();var swMathPt = (MathPoint)swMathUtils.CreatePoint(vPt);if (swViewType == "SLDASM"){var swComp = (Component2)(swVertex as Entity).GetComponent();if (swComp != null){MathTransform swCompXform = swComp.Transform2;MathTransform swTotalXForm = (MathTransform)swCompXform.Multiply(swViewXform);swMathPt = (MathPoint)swMathPt.MultiplyTransform(swTotalXForm);}}else{swMathPt = (MathPoint)swMathPt.MultiplyTransform(swViewXform);}return (double[])swMathPt.ArrayData;}/// <summary>/// 视图转换/// </summary>/// <param name="swDraw"></param>/// <param name="swView"></param>/// <returns></returns>private MathTransform ViewMathTransform(DrawingDoc swDraw, View swView){try{var swViewXform = (MathTransform)swView.ModelToViewTransform;var swSheet = (Sheet)swDraw.GetCurrentSheet();var swSheetView = (View)swDraw.GetFirstView();var swSheetXform = (MathTransform)swSheetView.ModelToViewTransform;var vSheetPrps = (double[])swSheet.GetProperties();var scaleNom = vSheetPrps[2];var scaleDenom = vSheetPrps[3];var ViewMatrix = (Double[])swSheetXform.ArrayData;ViewMatrix[12] = 1; //'scaleNom / scaleDenomvar swMathUtil = (MathUtility)swApp.GetMathUtility();swSheetXform = (MathTransform)swMathUtil.CreateTransform(ViewMatrix);return (MathTransform)swViewXform.Multiply(swSheetXform.Inverse());}catch (Exception){return null;}}}

总结

在这里插入图片描述

我这功能是抄来的,有问题别问我,哈哈

想要源码的自取

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/58262.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

软件工程-数据流图

阅读以下说明和图&#xff0c;回答问题1至问题3。 某时装邮购提供商拟开发订单处理系统,用于处理客户通过电话、传真、邮件或 Web站点所下订单。其主要功能如下: (1)增加客户记录。将新客户信息添加到客户文件,并分配一个客户号以备后续使用。 (2)查询商品信息。接收客户提交…

基于GTK+的Linux聊天室设计

1.聊天窗口的设计 本聊天室分为服务器端和客户端两部分&#xff0c;采用GTK2.0&#xff0c;即可用简短的代码来编写窗口并向窗口中插入各个控件&#xff0c;通过灵活地使用信号/回调函数机制&#xff0c;实现用户登录、通信连接、信息发送、信息接收等功能。首先运行服务器端&…

高德地图实现多点标注marker和动态信息窗体

先说一下项目对地图的需求&#xff1a;在后台新增地图管理模块&#xff0c;要求&#xff0c;每一辆车都在地图上有标注&#xff0c;而且点击标注时要显示出车辆的相关信息&#xff0c;比如车牌和车辆的当前状态。 下图就是实现的效果。 当然从高德地图api也能查看到这一块&am…

C#使用GDI+绘制高质量图和字体

对于GDI,在正常的操作,Bitmap-- Graphcis -- DrawImage或者DrawString ,生成图片的话,会产生很多杂点,或者是图片质量不稳定..尤其是在读取图片后,生成缩略图之后,文件会被压缩而失真..主要原因是因为没有重新设置Graphics的几个属性..1.Graphics.SmoothingMode属性: 例如Smoot…

软件设计师:09-软件工程

章节章节01 - 计算机组成原理与体系结构07 - 法律法规与标准化与多媒体基础02 - 操作系统基本原理08 - 设计模式03 - 数据库系统09 - 软件工程04 - 计算机网络10 - 面向对象05 - 数据结构与算法11 - 结构化开发与UML06 - 程序设计语言与语言处理程序基础12 - 下午题历年真题End…

【中级软件设计师】—(针对上午题)软件工程上(三十五)

【中级软件设计师】—&#xff08;针对上午题&#xff09;软件工程&#xff08;三十五&#xff09; 一、CMM 1 2 3 4 5 二、能力成熟度模型集成&#xff08;CMMI&#xff09; 6 7 8 9 三、软件过程模型 &#xff08;一&#xff09;、瀑布模型 &#xff08;二&#xff09;、V模…

软件工程_绘制数据流图

软件工程_绘制数据流图 实验目的&#xff1a; 1、掌握数据流的分析方法 2、掌握数据流图的绘制 实验原理&#xff1a; 数据流图&#xff08;DFD&#xff09;是软件系统系统的逻辑模型&#xff0c;仅仅描绘数据在软件中流动&#xff08;从输入移动到输出&#xff09;的过程中所…

20230120英语学习

How Animals May Have Conquered Snowball Earth “雪球地球”时期&#xff0c;动物是如何存活的&#xff1f; Planet Earth used to be something like a cross between a deep freeze and a car crusher.During vast stretches of the planet’s history, everything from p…

Time For Kids 很不错的英语学习周刊

英语&#xff0c;是全世界使用范围最广的一门语言&#xff0c;因此&#xff0c;学好英语是一件很重要的事情&#xff0c;而它的重要和存在形式也不仅仅是在学习分数上&#xff0c;英语是一种语言&#xff0c;也是一门工具&#xff0c;学好它&#xff0c;对于我们&#xff0c;尤…

大数据工程师应聘要求高么?好找工作么

大数据开发工程师该岗位对于技术要求较高&#xff0c;有一定的技术门槛。大数据工程师不少细分方向&#xff0c;不同的方向需要具备不同的知识结构&#xff0c;分别是大数据底层平台研发、大数据应用开发、大数据分析和大数据运维。 大数据开发工程师负责数据仓库建设、ETL开发…

大数据好找工作么?前景如何

大数据好不好找工作不是一概而论的&#xff0c;要根据你个人的学历情况&#xff0c;掌握技能程度&#xff0c;所在城市招聘需求&#xff0c;甚至是你的面试能力和简历是否突出优势有关。 但是毋庸置疑的是&#xff0c;大数据目前的发展前景还是相当优秀的。 我们知道&#xf…

都说大数据前景很好,那么大数据培训出来就业情况如何?

大数据的就业形式还是很不错&#xff0c;就业薪资还是很高&#xff0c;在网上随便一搜&#xff0c;如图 如果大数据还在自学中的同志们&#xff0c;赠送你们一张学习路线

如何读一个在职在线的海外名校的计算机硕士

对于参加工作几年的朋友&#xff0c;可能面临职场晋升压力&#xff0c;而身边的同事又都拥有硕士、博士学历&#xff0c;此时迫切想提升学历。 现在以某教育机构和伊利诺伊理工大学的在线硕士项目为例&#xff0c;作简单的科普介绍&#xff0c;事先说明此非推广宣传&#xff0…

计算机专业留学美国前景一如何,美国计算机专业国内外就业前景到底如何?和你想的一样吗?...

原标题&#xff1a;美国计算机专业国内外就业前景到底如何&#xff1f;和你想的一样吗&#xff1f; 在我们选择专业的时候&#xff0c;“就业前景”是几乎每个同学和家长都会考虑的问题。我们都知道美国大学有很多专业&#xff0c;其中计算机科学专业是绝对的优势也是申请的热门…

英国计算机专业申请条件有哪些?就业前景怎么样?

曾经有人说过&#xff0c;计算机是人类历史上最伟大的发明&#xff0c;因为计算机的出现使人们的工作效率大大提升了&#xff0c;而且自从计算机越来越普遍之后&#xff0c;学习计算机专业的学生也越来越多了&#xff0c;而英国在计算机领域的造诣非常高&#xff0c;因此去英国…

ChatGPT评中国最好就业的十大专业!人工智能,数据科学,网络安全排名前列!...

以下是ChatGPT认为未来考研最好就业的十大专业&#xff0c;并按照重要性从高到低排列&#xff08;仅供娱乐哦&#xff09; 需要注意的是&#xff0c;这只是ChatGPT的看法&#xff0c;其他人可能会有不同的观点和评价标准。 此外&#xff0c;不同的发展阶段和政策导向也会对专业…

商业创业计划书的21条重要事项

创业者们&#xff0c;商业计划书是你们找VC的敲门砖。没有一块有分量的敲门砖&#xff0c;怕你们敲不开VC的大门。 这世界上永远是来要钱的人多&#xff0c;能给出去的钱少&#xff0c;僧多粥少&#xff0c;融资是有门槛的。如果没有一份有分量的商业计划书&#xff0c;你根本就…

“ 奋斗者耕耘论坛 ” 商业计划书 | 内卷 | 大学生创业计划书 | 大创 | 创新杯项目 | 如何财富自由 | 怎么发财 | 赚钱方法

1. 1. 产品背景 产品背景 2020 年, 各行各业的奋斗者们都很焦虑. 他们在”内卷”的大环境下压力 从从. 无论是大学还是职场, 奋斗者们努力着挥洒汗水, 希望实现自己的梦想, 过上追求的美好生活. 无论是学业的压力还是职场的压力, 让这些曾经高考的 佼佼者, 毕业生中的优胜者也苦…

2021大学生创业计划书范例

想看更多算法题&#xff0c;可以扫描上方二维码关注我微信公众号“数据结构和算法”&#xff0c;截止到目前我已经在公众号中更新了500多道算法题&#xff0c;其中部分已经整理成了pdf文档&#xff0c;截止到目前总共有800多页&#xff08;并且还会不断的增加&#xff09;&…