yfy2003 发表于 2003-11-22 10:31:00

线形换向原码[附图]

<br/><br/><br/>原码:<br/>取出AcDb2dPolyline实体中的点数组,而且将AcDb2dPolyline实体中的点反向<br/>A=(student *)malloc(3000*sizeof(student));<br/> acedSSGet(NULL,NULL,NULL,NULL,ss);//选择实体<br/> acedSSLength(ss,&amp;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-&gt;isKindOf(AcDbPolyline::desc())) {//AcDbPolyline换向<br/>N=AcDbPolyline::cast(pObj)-&gt;numVerts();<br/>for(j=0; j   AcDbPolyline::cast(pObj)-&gt;getPointAt(j, lp);<br/>   (A+j)-&gt;x=lp;<br/>   (A+j)-&gt;y=lp;<br/>}<br/>kv=N;<br/>for(j=0;j   kv=kv-1;<br/>   lp=(A+kv)-&gt;x;<br/>   lp=(A+kv)-&gt;y;<br/>   AcDbPolyline::cast(pObj)-&gt;setPointAt(j, lp);<br/>}<br/>pObj-&gt;close();<br/> }else if(pObj-&gt;isKindOf(AcDb2dPolyline::desc())) {//AcDb2dPolyline换向<br/>AcDb2dPolyline *pPline;<br/>acdbOpenObject(pPline, eId, AcDb::kForRead);<br/>type=pPline-&gt;polyType();//拟合类型<br/>pPline-&gt;close();<br/>acdbOpenObject(pPline,eId,AcDb::kForWrite);<br/>pPline-&gt;convertToPolyType(AcDb::k2dSimplePoly);//改成不拟合<br/>pPline-&gt;close();<br/>acdbOpenObject(pPline,eId,AcDb::kForRead);<br/>AcDbObjectIterator *pVertIter=pPline-&gt;vertexIterator();<br/>AcDb2dVertex *pVertex;<br/>AcGePoint3d location;<br/>AcDbObjectId vertexObjId;<br/>N=0;<br/>for(j=0;!pVertIter-&gt;done();j++,pVertIter-&gt;step()) {//遍历坐标<br/>   vertexObjId=pVertIter-&gt;objectId();<br/>   acdbOpenObject(pVertex,vertexObjId,AcDb::kForRead);<br/>   location = pVertex-&gt;position();<br/>   N=N+1;<br/>   (A+N)-&gt;x=location;<br/>   (A+N)-&gt;y=location;<br/>   (A+N)-&gt;z=location;<br/>   pVertex-&gt;close();<br/>}<br/>delete pVertIter;<br/>pPline-&gt;close();<br/>acdbOpenObject(pPline,eId,AcDb::kForRead);<br/>AcDbObjectIterator *pVertIter1=pPline-&gt;vertexIterator();<br/>for(j=0;!pVertIter-&gt;done();j++,pVertIter-&gt;step()) {<br/>   vertexObjId = pVertIter-&gt;objectId();<br/>   acdbOpenObject(pVertex, vertexObjId,AcDb::kForWrite);<br/>   location=(A+N)-&gt;x;<br/>   location=(A+N)-&gt;y;<br/>   location=(A+N)-&gt;z;<br/>   pVertex-&gt;setPosition(location);<br/>   pVertex-&gt;close();<br/>   N=N-1;   <br/>}<br/>delete pVertIter1;<br/>pPline-&gt;close();<br/>acdbOpenObject(pPline,eId,AcDb::kForWrite);<br/>      if(type==0)//还原拟合类型<br/>   pPline-&gt;convertToPolyType(AcDb::k2dSimplePoly);<br/>else if(type==1)<br/>   pPline-&gt;convertToPolyType(AcDb::k2dFitCurvePoly);<br/>else if(type==2)<br/>   pPline-&gt;convertToPolyType(AcDb::k2dQuadSplinePoly);<br/>else if(type==3)<br/>   pPline-&gt;convertToPolyType(AcDb::k2dCubicSplinePoly);<br/>pPline-&gt;close();<br/>pObj-&gt;close();<br/> }<br/> acedSSFree(ss);<br/> free(A);<br/>

guankuiwu 发表于 2021-1-9 23:26:05

收藏下了,多谢分享

guankuiwu 发表于 2019-12-12 11:02:08

曲线走向会变的!

lockmyeye 发表于 2003-11-22 12:48:00



;;;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)
)

yfy2003 发表于 2003-11-22 13:22:00

你这是L我只会A,看不懂!

mccad 发表于 2003-11-22 14:38:00

呵呵,来个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

yfy2003 发表于 2003-11-22 14:41:00

VBA的能看懂!

今晚打老虎 发表于 2003-12-3 09:47:00

算法应该是一样的吧~~~~~

xbbcad 发表于 2003-12-3 15:01:00

今天正好碰到线型换向的问题

<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")&nbsp;&nbsp; <br/>;选择直线或标注,注意逻辑组的使用<br/>(setq tmp (ssget (list (cons -4 " (if tmp<br/>&nbsp;&nbsp; (progn<br/>&nbsp;&nbsp;&nbsp;&nbsp; (setq n (sslength tmp) m 0)<br/>&nbsp;&nbsp;&nbsp;&nbsp; (repeat n<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq ent (ssname tmp m))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq ed&nbsp; (entget ent))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;(ts "\nent=")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;(ts ent)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq name (cdr (assoc 0 ed)))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (if (= name "LWPOLYLINE")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (lwpolyline_reverse ent ed)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (progn&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq endpt1 (cons 11 (cdr (assoc 10 ed) )))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq endpt2 (cons 10 (cdr (assoc 11&nbsp; ed) )))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq ed (subst endpt1 (assoc 11 ed) ed))&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq ed (subst endpt2 (assoc 10 ed) ed))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq newline ed) <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;删除原对象并生成相同句柄的新对象,注意:<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;enddel 对象名称ent不是对象数据表ed<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;endmod entmake 的不是对象名称ent是对象数据表ed<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (entdel&nbsp; ent)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (entmake newline)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );end if&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq m (1+ m)) <br/>&nbsp;&nbsp;&nbsp;&nbsp; );end repeat<br/>&nbsp;&nbsp; )<br/>);end if tmp<br/>(princ "\n共处理了")<br/>(if m (princ m) (princ "0"))<br/>(princ "条直线(多段线、标注)。")<br/>(princ)<br/>&nbsp; <br/>);end C:ddl </p><p>;--------------------------------------------------------------------------- <br/>;多段线的换向程序,修改自明经通道<br/>(DEFUN lwpolyline_reverse (lwpent data / num data one points tempnum tempent)<br/>&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SETQ points nil)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (FOREACH one data<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (PROGN (IF (= (CAR one) 10)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SETQ points (APPEND points (LIST one)))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SETQ points (REVERSE points))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SETQ tempnum 0)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SETQ tempent nil)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbs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p;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (entdel&nbsp; lwpent)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (entmake tempent) <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (PRINC)<br/>);end lwpolyline_reverse<br/></p>

topirol 发表于 2003-12-16 10:17:00

好像没有考虑到

spline,或者圆弧之类的反向

myfreemind 发表于 2003-12-16 19:57:00

明总那个我用了,特别的方便!

yybu 发表于 2004-1-2 14:39:00

插有文字的圆弧(向上凸)文字都是上下颠倒的!换向也不能解决!各位有何高招?
页: [1] 2 3
查看完整版本: 线形换向原码[附图]