马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 newer 于 2018-5-16 16:10 编辑
ACAD的REGION,VLISP是没提供足够的函数处理的,即使ARX,也仅仅提供了遍历的能力,LOOP间并没有拓扑关系,只有通过ARX的AcBr API和AcDbMpolygon类相关方法组合,进行封装,才能使他具有完备的“拓扑”解析能力。
下面介绍API关于REGION实体的相关函数
一、Region ---> Curves
1、(xdrx_region->curve region [mode])
mode ---- 0(原生曲线),1(封闭的多段线),2(封闭的SPLINE)
默认1
2、(xdrx_region->polyline region)
3、(xdrx_region->spline region)
图例实现代码:
根据选项,生成 原生曲线、多段线和SPLINE
 - (defun c:tt ()
- (xdrx_begin)
- (xdrx_initget "0 1 2")
- (setq val (getkword "\n[0-原生曲线/1-封闭多段线/2-SPLINE]:"))
- (if (and (setq e (car (xdrx_entsel "\n拾取REGION<退出>:" '((0 . "REGION")))))
- (xdrx_entity_copy e)
- (setq ss (xdrx_region->curve (entlast) (atoi val)))
- )
- (progn
- (mapcar '(lambda(x)(setq clr (xdrx_math_rand 0 8))
- (xdrx_setpropertyvalue x "color" clr))(setq ents (xdrx_pickset->ents ss)))
- (xd::drag:simplemove ents "\n插入点:" 5 t)
- )
- )
- (xdrx_end)
- (princ)
- )
二、Region ---> Hatch
(xdrx_region->hatch region [t])
给t参数,保留原region
 - (defun c:tt ()
- (xdrx_begin)
- (if (and (setq e (car (xdrx_entsel "\n拾取REGION<退出>:" '((0 . "REGION")))))
- (setq ss (xdrx_region->hatch e t)
- ))
- (progn
- (setq ss1 (xd::pickset:getsub ss '((0 . "HATCH"))))
- (xdrx_entity_setproperty ss1 "color" 1)
- (xd::drag:simplemove ss "\n插入点:" 5 t)
- )
- )
- (xdrx_end)
- (princ)
- )
三、Region ---> MPolygon
(xdrx_region->mpolygon region [t])
给t参数,保留原region
 - (defun c:tt ()
- (xdrx_begin)
- (if (and (setq e (car (xdrx_entsel "\n拾取REGION<退出>:" '((0 . "REGION")))))
- (setq ss (xdrx_region->mpolygon e t)
- ))
- (progn
- (xdrx_entity_setproperty ss "color" 1)
- (xd::drag:simplemove ss "\n插入点:" 5 t)
- )
- )
- (xdrx_end)
- (princ)
- )
四、Region ---> 拆离
(xdrx_region_detach region)
五、Region ---> LIST
(xdrx_region->list region)
返回边界LOOP几何实体表(带拓扑结构子表)
六、Region ---> 布尔(交、并、差)
1、(xdrx_region_union r1 r2)
2、(xdrx_region_intersect r1 r2)
3、(xdrx_region_subtract r1 r2)
4、(xdrx_get_union r1 ent)
ent -- 曲线、region、MPOLYGON、Hatch
5、(xdrx_get_intersect r1 ent)
ent -- 曲线、region、MPOLYGON、Hatch
6、(xdrx_get_subtract r1 ent)
ent -- 曲线、region、MPOLYGON、Hatch
七、Region ---> 提取指定点附近的 有独立的ROOT的子REGION
(xdrx_getpropertyvalue region "extractloop" <pnt or ent or inx>)
实现代码:
八、Region ---> 提取所有的ROOT边界
(xdrx_getpropertyvalue region "rootloops" [t])
给T参数,返回GE几何实体表
否,返回整数索引表
命令: (xdrx_getpropertyvalue (entlast))
实现代码:
 - (defun c:tt ()
- (xdrx_begin)
- (if (and (setq e (car (xdrx_entsel "\n拾取REGION<退出>:" '((0 . "REGION")))))
- (setq ss (xdrx_getpropertyvalue e "rootloops" t))
- )
- (progn
- (setq ents nil)
- (mapcar '(lambda(x)
- (setq e1 (xdge::entity:make x)
- ents (cons e1 ents))
- (xdge::free x))ss)
- (xd::drag:simplemove ents "\n插入点:" 5 t)
- )
- )
- (xdrx_end)
- (princ)
- )
九、Region ---> 获取边界LOOP数
(xdrx_getpropertyvalue region "NumLoops")
返回整数
十、Region ---> 获取指定索引处的LOOP
(xdrx_getpropertyvalue region "GetloopAt" <inx>)
返回几何实体名
十一、Region ---> 获取指定点、实体附近、索引处的子LOOP
(xdrx_getpropertyvalue region "ChildLoops" <ent or pnt or inx> [t])
给T,返回几何实体表
否则,返回索引表
 - (defun c:tt ()
- (xdrx_begin)
- (if (and (setq e (car (xdrx_entsel "\n拾取REGION<退出>:" '((0 . "REGION")))))
- (setq pt (getpoint "\n拾取点<退出>:"))
- (setq ss (xdrx_getpropertyvalue e "childloops" pt t))
- )
- (progn (setq ents nil)
- (mapcar '(lambda (x)
- (setq e1 (xdge::entity:make x)
- ents (cons e1 ents)
- )
- (xdrx_setpropertyvalue e1 "color" 1)
- (xdge::free x)
- )
- ss
- )
- (xd::drag:simplemove ents "\n插入点:" 5 t)
- )
- )
- (xdrx_end)
- (princ)
- )
十二、Region ---> 获取指定点、实体附近、索引处的父LOOP
(xdrx_getpropertyvalue region "ParentLoop" <ent or pnt or inx> [t])
给T,返回几何实体表
否则,返回索引表
实现代码如下:
 - (defun c:tt ()
- (xdrx_begin)
- (if (and (setq e (car (xdrx_entsel "\n拾取REGION<退出>:" '((0 . "REGION")))))
- (setq pt (getpoint "\n拾取点<退出>:"))
- (setq ss (xdrx_getpropertyvalue e "parentloop" pt t))
- )
- (progn (setq ents nil)
- (mapcar '(lambda (x)
- (setq e1 (xdge::entity:make x)
- ents (cons e1 ents)
- )
- (xdrx_setpropertyvalue e1 "color" 1)
- (xdge::free x)
- )
- ss
- )
- (xd::drag:simplemove ents "\n插入点:" 5 t)
- )
- )
- (xdrx_end)
- (princ)
- )
十三、Region ---> 获取指定点、实体附近、索引处的根LOOP
(xdrx_getpropertyvalue region "RootLoopAt" <ent or pnt or inx> [t])
(xdrx_getpropertyvalue region "RootLoop" <ent or pnt or inx> [t])
给T,返回几何实体
否则,返回索引
实现代码如下:
 - (defun c:tt ()
- (xdrx_begin)
- (if (and (setq e (car (xdrx_entsel "\n拾取REGION<退出>:" '((0 . "REGION")))))
- (setq pt (getpoint "\n拾取点<退出>:"))
- (setq ss (xdrx_getpropertyvalue e "rootloopat" pt t))
- )
- (progn (setq e1 (xdge::entity:make ss))
- (xdrx_setpropertyvalue e1 "color" 1)
- (xdge::free ss)
- (xd::drag:simplemove e1 "\n插入点:" 5 t)
- )
- )
- (xdrx_end)
- (princ)
- )
十四、Region ---> 获取REGION的拓扑关系表
(xdrx-get-topology region)返回二叉树型的表
例子:
命令: (xdrx-get-topology (car (entsel)))
选择对象: ((3 (2 (0)) (1)) (7 (6 (4)) (5)) (10 (9) (8)))
REGION实体通用查询函数 xdrx_getpropertyvalue 用法如下:
Class AcDbRegion:
├─Area
├─Detach
├─ExtractLoop
├─Perimeter
├─Centroid
├─GeEntities
├─MomInertia
├─Plane
├─ProdInertia
├─Perimeter
├─Length
├─PrinMoments
├─PrinAxes
├─RadiiGyration
├─ExtentsLow
├─ExtentsHigh
├─Normal
├─NumChanges
├─IsNull
├─Normal
├─NumChanges
├─IsNull
Loops Class:
├─ClosestLoopTo or LoopIndexAt
├─GetLoops
├─GetLoopAt
├─RootLoop
├─RootLoops
├─ParentLoop
├─ChildLoops
├─NumLoops
|