修一个标注长度,标注的直线也跟着变化,
C#开发|大少爷|2017-07-27 11:52
-
回答:
用来选择实体对象. MxDrawUiPrEntity getEntity = new MxDrawUiPrEntity(); getEntity.message = "选择实体"; // 设置选择过滤条件. MxDrawResbuf selFilter = new MxDrawResbuf(); // 5020是实体类型的DXF组码. DIM是类型。 selFilter.AddStringEx("ALIGNEDDIMENSION",5020); getEntity.setFilter(selFilter); // 开始选择实体。 if(getEntity.go() != MCAD_McUiPrStatus.mcOk) return; // 得到选择的实体. MxDrawEntity ent = getEntity.Entity(); if (ent == null) return; if (!(ent is MxDrawDimAligned) ) { return; } // 得到选择的标注. MxDrawDimAligned dimAligned = (MxDrawDimAligned)ent; // 尺寸标注改成60 double dNewDist = 60.0; // 当前标注的两个点坐标。 MxDrawPoint pt1 = dimAligned.XLine1Point; MxDrawPoint pt2 = dimAligned.XLine2Point; // 计算pt1到pt2的向量. MxDrawVector3d vec = pt2.SumVector(pt1); // 把向量单位化 vec.Normalize(); //把向长度变成新距离. vec.Mult(dNewDist); // 算出在新距离下的新的坐标点。 MxDrawPoint newPt = new MxDrawPoint(); newPt.x = pt1.x; newPt.y = pt1.y; newPt.Add(vec); // 修改尺寸标注. dimAligned.XLine2Point = newPt; dimAligned.RecomputeDimBlock(true); // 查找尺寸标的直线段。并修改它。 MxDrawResbuf filter = new MxDrawResbuf(); filter.AddStringEx("LINE",5020); MxDrawSelectionSet ss = new MxDrawSelectionSet(); // 得到标注的开始点上的实体. // 搜索精度。 double dTol = 10;//axMxDrawX1.ViewLongToDocCoord(3); MxDrawPoint selPt1 = new MxDrawPoint(); MxDrawPoint selPt2 = new MxDrawPoint(); selPt1.x = pt1.x - dTol; selPt1.y = pt1.y - dTol; selPt2.x = pt1.x + dTol; selPt2.y = pt1.y + dTol; ss.Select(MCAD_McSelect.mcSelectionSetCrossing, selPt1, selPt2, filter); // 可能会得到多个实体,遍历所有实体,找到标注的直线对象。 for(int i = 0; i < ss.Count;i++) { MxDrawEntity findEnt = ss.Item(i); if (!(findEnt is MxDrawLine)) { continue; } MxDrawLine line = (MxDrawLine)findEnt; // 得到直线的两个点坐标。 MxDrawPoint sPt = line.StartPoint; MxDrawPoint ePt = line.EndPoint; double dDis1 = sPt.DistanceTo(pt1); double dDis2 = ePt.DistanceTo(pt1); if(dDis1 > dDis2) { if (dDis2 > dTol) continue; if(sPt.DistanceTo(pt2) > dTol) continue; // 直线的开始点,在pt2附近 line.StartPoint = newPt; break; } else { if(dDis1 > dTol) continue; if(ePt.DistanceTo(pt2) > dTol) continue; // 直线的结束点,在pt2附近 line.EndPoint = newPt; break; } } axMxDrawX1.ZoomAll();