Author Topic: [Topology-Region]REGION entities (+ topological capabilities) function set(14)  (Read 1045 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 514
ACAD's REGION and VLISP do not provide enough function processing. Even ARX only provides the ability to traverse. There is no topological relationship between LOOPs. It can only be encapsulated through the combination of ARX's AcBr API and AcDbMpolygon class related methods. He has complete "topology" analysis capabilities.


The following introduces API related functions about REGION entities.

1.
Region ---> Curves


1). (xdrx_region->curve region [mode])
mode ---- 0 (native curve), 1 (closed polyline), 2 (closed SPLINE)
Default 1

2).
(xdrx_region->polyline region)

3).
(xdrx_region->spline region)



Legend implementation code:
Depending on the options, generate native curves, polylines and SPLINEs

Implementation code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (xdrx_begin)
  3.    (xdrx_initget "0 1 2")
  4.    (setq val (getkword "\n[0-native curve/1-closed polyline/2-SPLINE]:"))
  5.    (if (and (setq e (car (xdrx_entsel "\nPick REGION<Exit>:" '((0 . "REGION")))))
  6.             (xdrx_entity_copy e)
  7.             (setq ss (xdrx_region->curve (entlast) (atoi val)));Region generates Curve
  8.        )
  9.      (progn
  10.        (mapcar '(lambda(x)(setq clr (xdrx_math_rand 0 8))
  11.                   (xdrx_setpropertyvalue x "color" clr))(setq ents (xdrx_pickset->ents ss)))
  12.        (xd::drag:simplemove ents "\nInsertion point:" 5 t);Drag entities
  13.      )
  14.    )
  15.    (xdrx_end)
  16.    (princ)
  17. )

2.
Region ---> Hatch


(xdrx_region->hatch region [t])
Give the t parameter and retain the original region



Implementation code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (xdrx_begin)
  3.    (if (and (setq e (car (xdrx_entsel "\nPick REGION<Exit>:" '((0 . "REGION")))))
  4.             (setq ss (xdrx_region->hatch e t)
  5.        ))
  6.      (progn
  7.        (setq ss1 (xd::pickset:getsub ss '((0 . "HATCH"))));;Get sub-selection set
  8.        (xdrx_entity_setproperty ss1 "color" 1);Assign color to the selection set
  9.        (xd::drag:simplemove ss "\nInsertion point:" 5 t);Move drag
  10.      )
  11.    )
  12.    (xdrx_end)
  13.    (princ)
  14. )

3.
Region ---> MPolygon


(xdrx_region->mpolygon region [t])
Give the t parameter and retain the original region



Implementation code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (xdrx_begin)
  3.    (if (and (setq e (car (xdrx_entsel "\nPick REGION<Exit>:" '((0 . "REGION")))))
  4.             (setq ss (xdrx_region->mpolygon e t);;region generates mpolygon
  5.        ))
  6.      (progn
  7.        (xdrx_entity_setproperty ss "color" 1)
  8.        (xd::drag:simplemove ss "\nInsertion point:" 5 t)
  9.      )
  10.    )
  11.    (xdrx_end)
  12.    (princ)
  13. )
  14.  

4. Region ---> Detachment

(xdrx_region_detach region)



5.
Region ---> LIST


(xdrx_region->list region)
Returns the boundary LOOP geometric entity table (with topology subtable)

Command: (setq a (xdrx-region->list (entlast)))
((<图元名: 2a1fe41b920> <图元名: 2a1fe41b360> <图元名: 2a1fe41b620>))
Command: (setq b (caar a))
<图元名: 2a1fe41b920>

命令: (xdrx-object-isa b)
"kLineSeg3d"

6.
Region ---> Boolean (intersection, union, difference)


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 -- curve, region, MPOLYGON, Hatch

5. (xdrx_get_intersect r1 ent)
ent -- curve, region, MPOLYGON, Hatch

6. (xdrx_get_subtract r1 ent)
ent -- curve, region, MPOLYGON, Hatch

7. Region ---> Extract sub-REGIONs with independent ROOT near the specified point

 (xdrx_getpropertyvalue region "extractloop" <pnt or ent or inx>)




Implementation code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (xdrx_begin)
  3.    (if (and (setq e (car (xdrx_entsel "\nPick REGION<Exit>:" '((0 . "REGION")))))
  4.             (setq pt (getpoint "\nClick a little near the sub-LOOP <Exit>:"))
  5.             (setq ss (xdrx_getpropertyvalue e "extractloop" pt)))
  6.  
  7.      (progn
  8.        (xdrx_entity_setproperty ss "color" (xdrx_math_rand 0 8))
  9.        (xd::drag:simplemove ss "\nInsertion point:" 5 t)
  10.      )
  11.    )
  12.    (xdrx_end)
  13.    (princ)
  14. )
  15.  

8.
Region ---> Extract all ROOT boundaries


(xdrx_getpropertyvalue region "rootloops" [t])
Give the T parameter and return the GE geometric entity table

No, return the integer index table



Implementation code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (xdrx_begin)
  3.    (if (and (setq e (car (xdrx_entsel "\nPick REGION<Exit>:" '((0 . "REGION")))))
  4.             (setq ss (xdrx_getpropertyvalue e "rootloops" t))
  5.        )
  6.      (progn
  7.        (setq ents nil)
  8.        (mapcar '(lambda(x)
  9.                   (setq e1 (xdge::entity:make x)
  10.                         ents (cons e1 ents))
  11.                   (xdge::free x))ss)
  12.        (xd::drag:simplemove ents "\nInsertion point:" 5 t)
  13.      )
  14.    )
  15.    (xdrx_end)
  16.    (princ)
  17. )

9.
Region ---> Get the number of boundary LOOPs


(xdrx_getpropertyvalue region "NumLoops")

Return integer.

exp:
Command: (xdrx_getpropertyvalue (entlast) "NumLoops")
3

10.
Region ---> Get the LOOP at the specified index


(xdrx_getpropertyvalue region "GetloopAt" <inx>)

Returns the geometric entity name.

11.
Region ---> Get the sub-LOOP at the specified point, near the entity, and at the index


(xdrx_getpropertyvalue region "ChildLoops" <ent or pnt or inx> [t])
Give T, return the geometric entity table
Otherwise, return the index table



Implementation code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (xdrx_begin)
  3.    (if (and (setq e (car (xdrx_entsel "\nPick REGION<Exit>:" '((0 . "REGION")))))
  4.             (setq pt (getpoint "\nPick point<exit>:"))
  5.             (setq ss (xdrx_getpropertyvalue e "childloops" pt t))
  6.        )
  7.      (progn (setq ents nil)
  8.             (mapcar '(lambda (x)
  9.                        (setq e1 (xdge::entity:make x)
  10.                              ents (cons e1 ents)
  11.                        )
  12.                        (xdrx_setpropertyvalue e1 "color" 1)
  13.                        (xdge::free x)
  14.                      )
  15.                     ss
  16.             )
  17.             (xd::drag:simplemove ents "\nInsertion point:" 5 t)
  18.      )
  19.    )
  20.    (xdrx_end)
  21.    (princ)
  22. )
  23.  

12.
Region ---> Get the parent LOOP at the specified point, near the entity, and at the index


(xdrx_getpropertyvalue region "ParentLoop" <ent or pnt or inx> [t])

Give T, return the geometric entity table
Otherwise, return the index table



Implementation code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (xdrx_begin)
  3.    (if (and (setq e (car (xdrx_entsel "\nPick REGION<Exit>:" '((0 . "REGION")))))
  4.             (setq pt (getpoint "\nPick point<exit>:"))
  5.             (setq ss (xdrx_getpropertyvalue e "parentloop" pt t))
  6.        )
  7.      (progn (setq ents nil)
  8.             (mapcar '(lambda (x)
  9.                        (setq e1 (xdge::entity:make x)
  10.                              ents (cons e1 ents)
  11.                        )
  12.                        (xdrx_setpropertyvalue e1 "color" 1)
  13.                        (xdge::free x)
  14.                      )
  15.                     ss
  16.             )
  17.             (xd::drag:simplemove ents "\nInsertion point:" 5 t)
  18.      )
  19.    )
  20.    (xdrx_end)
  21.    (princ)
  22. )

13.
Region ---> Get the root LOOP at the specified point, near the entity, and at the index


(xdrx_getpropertyvalue region "RootLoopAt" <ent or pnt or inx> [t])
(xdrx_getpropertyvalue region "RootLoop" <ent or pnt or inx> [t])

Give T, return geometric entity
Otherwise, return the index



Implementation code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (xdrx_begin)
  3.    (if (and (setq e (car (xdrx_entsel "\nPick REGION<Exit>:" '((0 . "REGION")))))
  4.             (setq pt (getpoint "\nPick point<exit>:"))
  5.             (setq ss (xdrx_getpropertyvalue e "rootloopat" pt t))
  6.        )
  7.      (progn (setq e1 (xdge::entity:make ss))
  8.             (xdrx_setpropertyvalue e1 "color" 1)
  9.             (xdge::freess)
  10.             (xd::drag:simplemove e1 "\nInsertion point:" 5 t)
  11.      )
  12.    )
  13.    (xdrx_end)
  14.    (princ)
  15. )

14. Region ---> Obtain the topological relationship table of REGION

(xdrx-get-topology region)
returns a binary tree table

example:
Command: (xdrx-get-topology (car (entsel)))
Select objects: ((3 (2 (0)) (1)) (7 (6 (4)) (5)) (10 (9) (8)))


REGION entity general query function xdrx_getpropertyvalue is used as follows:

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

=============

The above LISP code uses the XDRX-API, which can be downloaded from https://github.com/xdcad/XDrx-API

The XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.

The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net