Author Topic: [Topology-Hatch]Topological relationships of HATCH Boundaries(1) (LOOP)  (Read 907 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 505


The following code finds the father (PARENTLOOP) and current ancestor (ROOTLOOP) of the LOOP near the specified point

In the picture demonstrated above, the upper and lower parts are a single padding with two outer rings (ROOT). Our code

1. Pick up point
2. The LOOP near the point is displayed in magenta, the father is displayed in yellow, and the direct ancestor (ROOT) is displayed in red (the ancestor in this picture has two branches)

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (if (and (setq e (xdrx_entsel "\nPick a Hatch<exit>:" '((0 . "HATCH"))))
  3.             (xdrx_pickset_redraw e)
  4.             (setq p (getpoint "\nClick a little near the HATCH Ring <Exit>:"))
  5.        )
  6.      (progn
  7.        (xdrx_begin)
  8.        (setq mp (xdrx_hatch->mpolygon e)
  9.              mp (entlast)
  10.        )
  11.        (if (and (setq closestLoop
  12.                        (xdrx_getpropertyvalue mp "ClosestLoopTo" p)
  13.                 )
  14.                 (setq parentloop
  15.                        (xdrx_getpropertyvalue
  16.                          mp
  17.                          "parentloop"
  18.                          closestloop
  19.                        )
  20.                 )
  21.                 (setq roots
  22.                        (xdrx_getpropertyvalue
  23.                          mp
  24.                          "rootloops"
  25.                          closestloop
  26.                        )
  27.                 )
  28.            )
  29.          (progn
  30.            (setq loopdata (xdrx_getpropertyvalue
  31.                             mp
  32.                             "MPolygonLoopAt"
  33.                             closestloop
  34.                           )
  35.            )
  36.            (xdrx_polyline_make loopdata)
  37.            (xdrx_setpropertyvalue
  38.              (entlast)
  39.              "constantwidth"
  40.              20.0
  41.              "color"
  42.              6
  43.            )
  44.            (setq parentdata
  45.                   (xdrx_getpropertyvalue
  46.                     mp
  47.                     "MPolygonLoopAt"
  48.                     parentloop
  49.                   )
  50.            )
  51.            (xdrx_polyline_make parentdata)
  52.            (xdrx_setpropertyvalue
  53.              (entlast)
  54.              "constantwidth"
  55.              20.0
  56.              "color"
  57.              2
  58.            )
  59.            (if (> (length roots) 1)
  60.              (progn
  61.                (vl-some
  62.                  '(lambda (x)
  63.                     (setq
  64.                       child (xdrx_getpropertyvalue mp "childloops" x)
  65.                     )
  66.                     (if (member closestloop child)
  67.                       (setq rootloop x)
  68.                     )
  69.                   )
  70.                  roots
  71.                )
  72.              )
  73.              (setq rootloop (car roots))
  74.            )
  75.            (setq rootdata
  76.                   (xdrx_getpropertyvalue
  77.                     mp
  78.                     "MPolygonLoopAt"
  79.                     rootloop
  80.                   )
  81.            )
  82.            (xdrx_polyline_make rootdata)
  83.            (xdrx_setpropertyvalue
  84.              (entlast)
  85.              "constantwidth"
  86.              20.0
  87.              "color"
  88.              1
  89.            )
  90.          )
  91.        )
  92.        (xdrx_entity_delete mp)
  93.        (xdrx_pickset_redraw e t)
  94.        (xdrx_end)
  95.      )
  96.    )
  97.    (princ)
  98. )

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

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