| 思路是 1、由填充实体,获取边界LOOP
 
 2、由填充实体的包围盒,构建CP曲线选择集,把可能的边界曲线都构建到选择集中
 3、循环处理比较,条件可以是同时满足,长度相等,平行、距离=0,满足的保存到表中
 
 处理完,保存表里面的曲线就是边界了。
 
 下面用API写个函数和测试的工具,函数里面该注释的地方都注释了,方便你理解。
 
 
   
 
  (defun c:tt ()
  (while (and
        (setq e (car (xdrx_entsel "\n点取填充<退出>:" '((0 . "HATCH")))))
        (setq ents (xd::hatch:getloopents e))
      )
    (progn
      (XD::Pickset:GripDisplay ents)
    )
  )
  (princ)
)
 
  (defun XD::Hatch:GetLoopEnts (ha / box dis e ents ge2d ge3d ges loops loops1 n ss tf tf1 x)
  (if (xdrx_object_isa ha "AcDbHatch")
    (progn
      (setq ents (xdrx_getpropertyvalue ha "AssocObjIds")) ; 如果是关联的直接返回曲线
      (if (not ents)
        (progn
          (setq ges (xdrx_getpropertyvalue ha "getloops" t) ; 获得所有的边LOOP几何实体
                ges (mapcar
                      '(lambda (x)
                         (if (= (xdge::type x) "kCompositeCrv2d")
                           (list x (xdge::getpropertyvalue x "getcurvelist"))
                           (if (= (type x) 'LIST)
                             (cons (xdge::constructor "kCompositecrv2d" x) x)
                             x
                           )
                         )
                       )
                      ges
                    )
                ges (xd::list:flat ges)
                box (xdrx_entity_box ha)
          )
          (setq tf1 (XD::Doc:SafeZoom box)) ; 确保边界范围显示在屏幕内
          (if (setq ss (ssget "cp" box '((0 . "LINE,POLYLINE,LWPOLYLINE,SPLINE,ARC,CIRCLE,ELLIPSE")))) ; 构建CP曲线选择集
            (progn
              (setq loops (xdrx_pickset->ents ss))
              (foreach n ges
                (setq tf t
                      loops1 loops
                )
                (while (and
                         tf
                         (setq e (car loops1))
                       )
                  (setq ge3d (xdge::constructor e)
                        ge2d (xdge::entity:3d->2d ge3d)
                  )
                  (if (and
                        (if (/= (xdge::type n) "kCompositeCrv2d")
                          (xdge::getpropertyvalue n "isparallelto" ge2d)
                          t
                        )
                        (equal (xdge::getpropertyvalue n "length")
                               (xdge::getpropertyvalue ge2d "length") 1e-2
                        )
                        (equal (setq dis (xdge::getpropertyvalue n "distanceto"
                                                                 ge2d
                                         )
                               )
                               0.0 1e-2
                        )
                      )                       ; 判断是否平行、长度相同、距离=0
                    (setq ents (cons e ents)
                          tf nil
                    )
                  )
                  (setq loops1 (cdr loops1))
                  (xdge::free ge2d ge3d)
                )
              )
              (setq ents (reverse ents))
            )
          )
          (if tf1
            (xdrx_document_zoomprevious) ; 如果ZOOM,恢复原来的显示
          )
          (xdge::free ges)
        )
      )
    )
  )
  ents
)
 
 
 |