Author Topic: [AcBr Library(1)] Obtain the boundary curve of REGION and BOX  (Read 994 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Bull Frog
  • Posts: 424
[AcBr Library(1)] Obtain the boundary curve of REGION and BOX
« on: November 14, 2023, 09:31:09 PM »
XDRX API provides LISP packaging of the ObjectARX AcBr API library starting from 2018.0508.


What is "ACBR API"?


AcBr API is ARX's application development interface for processing topological objects. It is used to process the topological relationships of three-dimensional geometric entities such as AcDbRegion, AcDb3DSolid, and AcDbBody.
Except for ARX, other development interfaces such as VLISP do not provide encapsulated interfaces.


Through this API, you can easily query the data and topological relationships of "volumes, surfaces, rings, edges, and points" of geometric model entities.
AcBrEntity is the base class of this interface and cannot be instantiated by itself. It derives subclasses such as AcBrBrep, AcBrFace, AcBrLoop, AcBrEdge, AcBrVertex and AcBrShell. And through the topology traverser AcBrTraverser class, the entire model entity is traversed in the order of body, surface, ring, edge, and point.


Below we introduce how to traverse an area entity through the ACBR API to obtain each boundary curve.


As shown in the figure, it is an area entity composed of SUBTRACT and UNION. From the perspective of ACBR, it consists of "two FACE", "three LOOP", and "three EDGE".
The topological hierarchy of ACBR's solid model is: BODY --->Face --->Path (LOOP) --->Edge --->Vertex


For example, a cube BOX has 6 faces, each face consists of a LOOP, each LOOP consists of four sides, and each side consists of two vertices.
Through the traverser, each element can be traversed from the root of the BOX. It is also possible to easily find the topological relationships of points, lines, and surfaces, the intersection points and intersections of points, lines, and surfaces, and query whether a point or straight line is on a line or surface, etc.



The white one is the Region, and the red one is the three boundary curves (circles) obtained.



In the above figure, each edge of 3DSOLID is obtained, in red.

The code is as follows: three-layer loop traversal structure

Code - Auto/Visual Lisp: [Select]
  1. ;Face (FACE) -> Path (LOOP) -> Edge (EDGE) three-layer traversal to obtain the REGION boundary curve
  2.  
  3. (defun c:tt ()
  4.    (if (and (setq e (car (entsel))) (setq br (xdbr::constructor e)))
  5.      (progn (setq tr (xdbr::constructor "brepfacetraverser" br))
  6.             (setq xents nil)
  7.             ;;FACE traversal
  8.             (while (not (xdbr::traverser:done tr))
  9.               (setq face (xdbr::getpropertyvalue tr "face"))
  10.               (setq faceloop (xdbr::constructor "facelooptraverser" face))
  11.               (xdrx_object_release face)
  12.               (setq fents nil)
  13.               ;LOOP traversal under FACE
  14.               (while (not (xdbr::traverser:done faceloop));;The traverser has not reached the end, the loop
  15.                 (setq loop (xdbr::getpropertyvalue faceloop "loop"))
  16.                 (setq loopedge (xdbr::constructor "loopedgetraverser" loop))
  17.                 (xdrx_object_release loop)
  18.                 (setq ents nil)
  19.                 ;Edge traversal under LOOP
  20.                 (while (not (xdbr::traverser:done loopedge))
  21.                   (setq edge (xdbr::getpropertyvalue loopedge "edge"))
  22.                   (setq ents (cons edge ents));;The edge AcBrEdge is saved to the global table for later operations.
  23.                   (xdbr::traverser:next loopedge);;The traverser pointer points to the next edge
  24.                 )
  25.                 (xdrx_object_release loopedge)
  26.                 (setq fents (cons ents fents))
  27.                 (xdbr::traverser:next faceloop);;The traverser points to the next LOOP
  28.               )
  29.               (xdrx_object_release faceloop)
  30.               (setq xents (cons fents xents))
  31.               (xdbr::traverser:next tr);;The traverser points to the next face FACE
  32.             )
  33.             ;;AcBrEdge -> AcGe Curve
  34.             (setq ges (mapcar '(lambda (x) (xdbr::getpropertyvalue x "curve"))
  35.                               (xd::list:flat xents)
  36.                       )
  37.             )
  38.             (setq ss (xdge::entity:make ges)) ;;Create database curve
  39.             (xdrx_object_release tr br ges xents);;Release the intermediate ACBR object
  40.             (xdrx_entity_setproperty ss "color" 1);;Set color red
  41.             (xdrx_entity_redraw ss 1);;Pinch highlighted selection set
  42.      )
  43.    )
  44.    (princ)
  45. )
  46.  

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.
« Last Edit: November 14, 2023, 09:53:56 PM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
[XDrx-Sub Forum]
https://www.theswamp.org/index.php?board=78.0
https://github.com/xdcad/XDrx-API
http://bbs.xdcad.net

xdcad

  • Bull Frog
  • Posts: 424
Re: [AcBr Library(1)] Obtain the boundary curve of REGION and BOX
« Reply #1 on: November 15, 2023, 12:42:11 PM »

Through the above AcBr LISP program, all native curves in REGION can be extracted。
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
[XDrx-Sub Forum]
https://www.theswamp.org/index.php?board=78.0
https://github.com/xdcad/XDrx-API
http://bbs.xdcad.net