明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 16226|回复: 24

线形换向原码[附图]

  [复制链接]
发表于 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[X];<br/>   (A+j)-&gt;y=lp[Y];<br/>  }<br/>  kv=N;<br/>  for(j=0;j   kv=kv-1;<br/>   lp[X]=(A+kv)-&gt;x;<br/>   lp[Y]=(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[X];<br/>   (A+N)-&gt;y=location[Y];<br/>   (A+N)-&gt;z=location[Z];<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[X]=(A+N)-&gt;x;<br/>   location[Y]=(A+N)-&gt;y;<br/>   location[Z]=(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/>

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2021-1-9 23:26:05 来自手机 | 显示全部楼层
收藏下了,多谢分享
发表于 2019-12-12 11:02:08 | 显示全部楼层
曲线走向会变的!
发表于 2003-11-22 12:48:00 | 显示全部楼层


  1. ;;;LWPOLYLINE线型换向,不能对POLYLINE线型换向,拟合过的线条都是POLYLINE线。
  2. (DEFUN c:lwpolyline_reverse (/ ss1 num data one points tempnum tempent)
  3.     (PRINC "\n\t请选择要换向的线条:")
  4.     (SETQ ss1 (SSGET (LIST (CONS 0 "lwpolyline"))))
  5.     (SETQ num 0)
  6.     (REPEAT (IF ss1
  7.                 (SSLENGTH ss1)
  8.                 0
  9.             )
  10.         (SETQ data (ENTGET (SSNAME ss1 num))
  11.               num  (1+ num)
  12.         )
  13.         (SETQ points nil)
  14.         (FOREACH one data
  15.             (PROGN (IF (= (CAR one) 10)
  16.                        (SETQ points (APPEND points (LIST one)))
  17.                    )
  18.             )
  19.         )
  20.         (SETQ points (REVERSE points))
  21.         (SETQ tempnum 0)
  22.         (SETQ tempent nil)
  23.         (FOREACH one data
  24.             (PROGN (IF (= (CAR one) 10)
  25.                        (SETQ tempent (APPEND tempent (LIST (NTH tempnum points)))
  26.                              tempnum (1+ tempnum)
  27.                        )
  28.                        (SETQ tempent (APPEND tempent (LIST one)))
  29.                    )
  30.             )
  31.         )
  32.         (IF (NOT (ENTMOD tempent))
  33.             (ALERT "错误:\n\t不能更新实体数据!\t")
  34.         )
  35.     )
  36.     (PRINC)
  37. )
复制代码
 楼主| 发表于 2003-11-22 13:22:00 | 显示全部楼层
你这是L我只会A,看不懂!
发表于 2003-11-22 14:38:00 | 显示全部楼层
呵呵,来个VBA的(以前贴过)
  1. Sub RevPline()
  2.     Dim ent As AcadEntity
  3.     Dim pnt As Variant
  4.     Dim NewCoord() As Double
  5.     Dim i As Integer
  6.     On Error Resume Next
  7.     Do
  8.         ThisDrawing.Utility.GetEntity ent, pnt, "选择多段线:"
  9.         If Err Then Exit Sub
  10.         If TypeName(ent) Like "IAcad*Polyline" Then Exit Do
  11.     Loop
  12.     Dim Coord As Variant
  13.     Dim CoordCount As Integer
  14.     Dim Bulge() As Double
  15.     If TypeName(ent) = "IAcadLWPolyline" Then
  16.         Coord = ent.Coordinates
  17.         CoordCount = (UBound(Coord) + 1) / 2
  18.         ReDim NewCoord(UBound(Coord)) As Double
  19.         For i = 0 To UBound(Coord) - 1 Step 2
  20.             NewCoord(UBound(Coord) - i - 1) = Coord(i)
  21.             NewCoord(UBound(Coord) - i) = Coord(i + 1)
  22.         Next
  23.         ReDim Bulge(CoordCount - 1) As Double
  24.         For i = 0 To CoordCount - 1
  25.             Bulge(i) = ent.GetBulge(i)
  26.         Next
  27.         ent.Coordinates = NewCoord
  28.         For i = 0 To CoordCount - 2
  29.             ent.SetBulge i, -Bulge(CoordCount - 2 - i)
  30.         Next
  31.         ThisDrawing.Regen acActiveViewport
  32.     ElseIf TypeName(ent) = "IAcadPolyline" Then
  33.         Coord = ent.Coordinates
  34.         CoordCount = (UBound(Coord) + 1) / 3
  35.         ReDim NewCoord(UBound(Coord)) As Double
  36.         For i = 0 To UBound(Coord) - 1 Step 3
  37.             NewCoord(UBound(Coord) - i - 2) = Coord(i)
  38.             NewCoord(UBound(Coord) - i - 1) = Coord(i + 1)
  39.             NewCoord(UBound(Coord) - i) = Coord(i + 2)
  40.         Next
  41.         If ent.Type = acSimplePoly Then
  42.             ReDim Bulge(CoordCount - 1) As Double
  43.             For i = 0 To CoordCount - 1
  44.                 Bulge(i) = ent.GetBulge(i)
  45.             Next
  46.         End If
  47.         ent.Coordinates = NewCoord
  48.         If ent.Type = acSimplePoly Then
  49.             For i = 0 To CoordCount - 2
  50.                 ent.SetBulge i, -Bulge(CoordCount - 2 - i)
  51.             Next
  52.         End If
  53.        ThisDrawing.Regen acActiveViewport
  54.     End If
  55.    
  56. End Sub
 楼主| 发表于 2003-11-22 14:41:00 | 显示全部楼层
VBA的能看懂!
发表于 2003-12-3 09:47:00 | 显示全部楼层
算法应该是一样的吧~~~~~
发表于 2003-12-3 15:01:00 | 显示全部楼层

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

把lockmyeye的程序参考进去了,不敢独享,贴上来供诸位高手拍砖

;DDL: Copyright By WWZ,2003-12-3
;颠倒直线的两端点,即交换实体对象组代码10和11,
;用于解决直线、dimension、多段线的线型换向问题

(defun C:ddl(/ tmp ed ent m n endpt1 endpt2 newline name)
(princ "\n交换直线、多段线或标注的起点和终点.请选择直线、多段线或标注:\n")  
;选择直线或标注,注意逻辑组的使用
(setq tmp (ssget (list (cons -4 " (if tmp
   (progn
     (setq n (sslength tmp) m 0)
     (repeat n
         (setq ent (ssname tmp m))
         (setq ed  (entget ent))     
         ;(ts "\nent=")
         ;(ts ent)
         (setq name (cdr (assoc 0 ed)))
         (if (= name "LWPOLYLINE")
           (lwpolyline_reverse ent ed)
           (progn               
             (setq endpt1 (cons 11 (cdr (assoc 10 ed) )))        
             (setq endpt2 (cons 10 (cdr (assoc 11  ed) )))                  
             (setq ed (subst endpt1 (assoc 11 ed) ed))   
             (setq ed (subst endpt2 (assoc 10 ed) ed))
             (setq newline ed)
             ;删除原对象并生成相同句柄的新对象,注意:
             ;enddel 对象名称ent不是对象数据表ed
             ;endmod entmake 的不是对象名称ent是对象数据表ed
             (entdel  ent)
             (entmake newline)                         
          )
         );end if  
         (setq m (1+ m))
     );end repeat
   )
);end if tmp
(princ "\n共处理了")
(if m (princ m) (princ "0"))
(princ "条直线(多段线、标注)。")
(princ)
 
);end C:ddl

;---------------------------------------------------------------------------
;多段线的换向程序,修改自明经通道
(DEFUN lwpolyline_reverse (lwpent data / num data one points tempnum tempent)
 
       (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)))
                   )
            )
        )     
        (entdel  lwpent)
        (entmake tempent)
       
        (PRINC)
);end lwpolyline_reverse

发表于 2003-12-16 10:17:00 | 显示全部楼层
好像没有考虑到

spline,或者圆弧之类的反向
发表于 2003-12-16 19:57:00 | 显示全部楼层
明总那个我用了,特别的方便!
发表于 2004-1-2 14:39:00 | 显示全部楼层
插有文字的圆弧(向上凸)文字都是上下颠倒的!换向也不能解决!各位有何高招?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-9-30 22:17 , Processed in 0.197528 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表