Author Topic: [XDrX-PlugIn(5)] Merge two color blocks (HATCH)  (Read 865 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 514
[XDrX-PlugIn(5)] Merge two color blocks (HATCH)
« on: November 26, 2023, 04:08:15 PM »
The code written in the forum is mainly to demonstrate the usage of the main functions to be introduced. There may be a better or direct way to implement it.

The following code mainly introduces the AcGe geometry library function and uses the MPOLYGON object to UNION the HATCH entities.



(xdrx-hatch->mpolygon e1 t)
(xdrx-hatch->mpolygon e2 t)
(xdrx-mpolygon-union e1 e2)
(xdrx-mpolygon->hatch e1)

The above function combination can be replaced by the following function, which supports any combination of MPOLYGON, HATCH, and REGION.

(xdrx-get-union e1 e2)

Code - Auto/Visual Lisp: [Select]
  1. (defun c:XDTB-HatchUnion (/ e1 e2)
  2.   ;| Use the AcGe geometry library to determine whether it intersects|;
  3.   (defun _hasInterPnts (e1 e2 / g1 g2 intv ret)
  4.     (setq ret
  5.            (and (setq g1 (xdrx-getpropertyvalue e1 "rootloopat" 0))
  6.                 (setq g2 (xdrx-getpropertyvalue e2 "rootloopat" 0))
  7.                 (setq intv (xdge::getpropertyvalue g1 "getinterval" g2))
  8.            )
  9.     )
  10.     (xdrx-object-release g1 g2 intv)
  11.     ret
  12.   )
  13.   (if (and
  14.         (setq e1 (car (xdrx-entsel "\nSelect main color block<Exit>:" '((0 . "HATCH")))))
  15.         (xdrx-pickset-redraw e1 3)
  16.         (setq e2 (car (xdrx-entsel "\nSelect the color blocks to be merged<Exit>:" '((0 . "HATCH")))))
  17.         (not (eq e1 e2))
  18.       )
  19.     (progn
  20.       (xdrx-begin)
  21.       (if (_hasInterPnts e1 e2)
  22.         (progn
  23.           (xdrx-hatch->mpolygon e1 t)
  24.           (xdrx-hatch->mpolygon e2 t)
  25.  
  26.           (xdrx-mpolygon-union e1 e2)
  27.           (xdrx-mpolygon->hatch e1)
  28.  
  29.           (xdrx-prompt "\nTwo color blocks were successfully merged.")
  30.         )
  31.       )
  32.       (xdrx-end)
  33.     )
  34.   )
  35.   (princ)
  36. )
« Last Edit: November 26, 2023, 05:35:02 PM by xdcad »
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