线形换向原码[附图]
<br/><br/><br/>原码:<br/>取出AcDb2dPolyline实体中的点数组,而且将AcDb2dPolyline实体中的点反向<br/>A=(student *)malloc(3000*sizeof(student));<br/> acedSSGet(NULL,NULL,NULL,NULL,ss);//选择实体<br/> acedSSLength(ss,&len);<br/> if(acedSSName(ss,0,ent)!=RTNORM) return;<br/> AcDbObjectId eId;<br/> AcDbObject *pObj;<br/> AcDb::Poly2dType type;//拟合类型<br/> AcGePoint2d lp;<br/> acdbGetObjectId(eId, ent);<br/> acdbOpenObject(pObj, eId, AcDb::kForWrite);<br/> if(pObj->isKindOf(AcDbPolyline::desc())) {//AcDbPolyline换向<br/>N=AcDbPolyline::cast(pObj)->numVerts();<br/>for(j=0; j AcDbPolyline::cast(pObj)->getPointAt(j, lp);<br/> (A+j)->x=lp;<br/> (A+j)->y=lp;<br/>}<br/>kv=N;<br/>for(j=0;j kv=kv-1;<br/> lp=(A+kv)->x;<br/> lp=(A+kv)->y;<br/> AcDbPolyline::cast(pObj)->setPointAt(j, lp);<br/>}<br/>pObj->close();<br/> }else if(pObj->isKindOf(AcDb2dPolyline::desc())) {//AcDb2dPolyline换向<br/>AcDb2dPolyline *pPline;<br/>acdbOpenObject(pPline, eId, AcDb::kForRead);<br/>type=pPline->polyType();//拟合类型<br/>pPline->close();<br/>acdbOpenObject(pPline,eId,AcDb::kForWrite);<br/>pPline->convertToPolyType(AcDb::k2dSimplePoly);//改成不拟合<br/>pPline->close();<br/>acdbOpenObject(pPline,eId,AcDb::kForRead);<br/>AcDbObjectIterator *pVertIter=pPline->vertexIterator();<br/>AcDb2dVertex *pVertex;<br/>AcGePoint3d location;<br/>AcDbObjectId vertexObjId;<br/>N=0;<br/>for(j=0;!pVertIter->done();j++,pVertIter->step()) {//遍历坐标<br/> vertexObjId=pVertIter->objectId();<br/> acdbOpenObject(pVertex,vertexObjId,AcDb::kForRead);<br/> location = pVertex->position();<br/> N=N+1;<br/> (A+N)->x=location;<br/> (A+N)->y=location;<br/> (A+N)->z=location;<br/> pVertex->close();<br/>}<br/>delete pVertIter;<br/>pPline->close();<br/>acdbOpenObject(pPline,eId,AcDb::kForRead);<br/>AcDbObjectIterator *pVertIter1=pPline->vertexIterator();<br/>for(j=0;!pVertIter->done();j++,pVertIter->step()) {<br/> vertexObjId = pVertIter->objectId();<br/> acdbOpenObject(pVertex, vertexObjId,AcDb::kForWrite);<br/> location=(A+N)->x;<br/> location=(A+N)->y;<br/> location=(A+N)->z;<br/> pVertex->setPosition(location);<br/> pVertex->close();<br/> N=N-1; <br/>}<br/>delete pVertIter1;<br/>pPline->close();<br/>acdbOpenObject(pPline,eId,AcDb::kForWrite);<br/> if(type==0)//还原拟合类型<br/> pPline->convertToPolyType(AcDb::k2dSimplePoly);<br/>else if(type==1)<br/> pPline->convertToPolyType(AcDb::k2dFitCurvePoly);<br/>else if(type==2)<br/> pPline->convertToPolyType(AcDb::k2dQuadSplinePoly);<br/>else if(type==3)<br/> pPline->convertToPolyType(AcDb::k2dCubicSplinePoly);<br/>pPline->close();<br/>pObj->close();<br/> }<br/> acedSSFree(ss);<br/> free(A);<br/> 收藏下了,多谢分享 曲线走向会变的!;;;LWPOLYLINE线型换向,不能对POLYLINE线型换向,拟合过的线条都是POLYLINE线。
(DEFUN c:lwpolyline_reverse (/ ss1 num data one points tempnum tempent)
(PRINC "\n\t请选择要换向的线条:")
(SETQ ss1 (SSGET (LIST (CONS 0 "lwpolyline"))))
(SETQ num 0)
(REPEAT (IF ss1
(SSLENGTH ss1)
0
)
(SETQ data (ENTGET (SSNAME ss1 num))
num(1+ num)
)
(SETQ points nil)
(FOREACH one data
(PROGN (IF (= (CAR one) 10)
(SETQ points (APPEND points (LIST one)))
)
)
)
(SETQ points (REVERSE points))
(SETQ tempnum 0)
(SETQ tempent nil)
(FOREACH one data
(PROGN (IF (= (CAR one) 10)
(SETQ tempent (APPEND tempent (LIST (NTH tempnum points)))
tempnum (1+ tempnum)
)
(SETQ tempent (APPEND tempent (LIST one)))
)
)
)
(IF (NOT (ENTMOD tempent))
(ALERT "错误:\n\t不能更新实体数据!\t")
)
)
(PRINC)
)
你这是L我只会A,看不懂! 呵呵,来个VBA的(以前贴过)
Sub RevPline()
Dim ent As AcadEntity
Dim pnt As Variant
Dim NewCoord() As Double
Dim i As Integer
On Error Resume Next
Do
ThisDrawing.Utility.GetEntity ent, pnt, "选择多段线:"
If Err Then Exit Sub
If TypeName(ent) Like "IAcad*Polyline" Then Exit Do
Loop
Dim Coord As Variant
Dim CoordCount As Integer
Dim Bulge() As Double
If TypeName(ent) = "IAcadLWPolyline" Then
Coord = ent.Coordinates
CoordCount = (UBound(Coord) + 1) / 2
ReDim NewCoord(UBound(Coord)) As Double
For i = 0 To UBound(Coord) - 1 Step 2
NewCoord(UBound(Coord) - i - 1) = Coord(i)
NewCoord(UBound(Coord) - i) = Coord(i + 1)
Next
ReDim Bulge(CoordCount - 1) As Double
For i = 0 To CoordCount - 1
Bulge(i) = ent.GetBulge(i)
Next
ent.Coordinates = NewCoord
For i = 0 To CoordCount - 2
ent.SetBulge i, -Bulge(CoordCount - 2 - i)
Next
ThisDrawing.Regen acActiveViewport
ElseIf TypeName(ent) = "IAcadPolyline" Then
Coord = ent.Coordinates
CoordCount = (UBound(Coord) + 1) / 3
ReDim NewCoord(UBound(Coord)) As Double
For i = 0 To UBound(Coord) - 1 Step 3
NewCoord(UBound(Coord) - i - 2) = Coord(i)
NewCoord(UBound(Coord) - i - 1) = Coord(i + 1)
NewCoord(UBound(Coord) - i) = Coord(i + 2)
Next
If ent.Type = acSimplePoly Then
ReDim Bulge(CoordCount - 1) As Double
For i = 0 To CoordCount - 1
Bulge(i) = ent.GetBulge(i)
Next
End If
ent.Coordinates = NewCoord
If ent.Type = acSimplePoly Then
For i = 0 To CoordCount - 2
ent.SetBulge i, -Bulge(CoordCount - 2 - i)
Next
End If
ThisDrawing.Regen acActiveViewport
End If
End Sub VBA的能看懂! 算法应该是一样的吧~~~~~
今天正好碰到线型换向的问题
<p>把lockmyeye的程序参考进去了,不敢独享,贴上来供诸位高手拍砖<br/><br/>;DDL: Copyright By WWZ,2003-12-3<br/>;颠倒直线的两端点,即交换实体对象组代码10和11,<br/>;用于解决直线、dimension、多段线的线型换向问题</p><p>(defun C:ddl(/ tmp ed ent m n endpt1 endpt2 newline name)<br/>(princ "\n交换直线、多段线或标注的起点和终点.请选择直线、多段线或标注:\n") <br/>;选择直线或标注,注意逻辑组的使用<br/>(setq tmp (ssget (list (cons -4 " (if tmp<br/> (progn<br/> (setq n (sslength tmp) m 0)<br/> (repeat n<br/> (setq ent (ssname tmp m))<br/> (setq ed (entget ent)) <br/> ;(ts "\nent=")<br/> ;(ts ent)<br/> (setq name (cdr (assoc 0 ed)))<br/> (if (= name "LWPOLYLINE")<br/> (lwpolyline_reverse ent ed)<br/> (progn <br/> (setq endpt1 (cons 11 (cdr (assoc 10 ed) ))) <br/> (setq endpt2 (cons 10 (cdr (assoc 11 ed) ))) <br/> (setq ed (subst endpt1 (assoc 11 ed) ed)) <br/> (setq ed (subst endpt2 (assoc 10 ed) ed))<br/> (setq newline ed) <br/> ;删除原对象并生成相同句柄的新对象,注意:<br/> ;enddel 对象名称ent不是对象数据表ed<br/> ;endmod entmake 的不是对象名称ent是对象数据表ed<br/> (entdel ent)<br/> (entmake newline) <br/> )<br/> );end if <br/> (setq m (1+ m)) <br/> );end repeat<br/> )<br/>);end if tmp<br/>(princ "\n共处理了")<br/>(if m (princ m) (princ "0"))<br/>(princ "条直线(多段线、标注)。")<br/>(princ)<br/> <br/>);end C:ddl </p><p>;--------------------------------------------------------------------------- <br/>;多段线的换向程序,修改自明经通道<br/>(DEFUN lwpolyline_reverse (lwpent data / num data one points tempnum tempent)<br/> <br/> (SETQ points nil)<br/> (FOREACH one data<br/> (PROGN (IF (= (CAR one) 10)<br/> (SETQ points (APPEND points (LIST one)))<br/> )<br/> )<br/> )<br/> <br/> (SETQ points (REVERSE points))<br/> (SETQ tempnum 0)<br/> (SETQ tempent nil)<br/> <br/> (FOREACH one data<br/> (PROGN (IF (= (CAR one) 10)<br/> (SETQ tempent (APPEND tempent (LIST (NTH tempnum points)))<br/> tempnum (1+ tempnum)<br/> )<br/> (SETQ tempent (APPEND tempent (LIST one)))<br/> )<br/> )<br/> ) <br/> (entdel lwpent)<br/> (entmake tempent) <br/> <br/> (PRINC)<br/>);end lwpolyline_reverse<br/></p> 好像没有考虑到spline,或者圆弧之类的反向 明总那个我用了,特别的方便! 插有文字的圆弧(向上凸)文字都是上下颠倒的!换向也不能解决!各位有何高招?