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)
(defun c:XDTB
-HatchUnion
(/ e1 e2
) ;| Use the AcGe geometry library to determine whether it intersects|;
(defun _hasInterPnts
(e1 e2
/ g1 g2 intv ret
) (and (setq g1
(xdrx
-getpropertyvalue e1
"rootloopat" 0)) (setq g2
(xdrx
-getpropertyvalue e2
"rootloopat" 0)) (setq intv
(xdge::getpropertyvalue g1
"getinterval" g2
)) )
)
(xdrx-object-release g1 g2 intv)
ret
)
(setq e1
(car (xdrx
-entsel "\nSelect main color block<Exit>:" '
((0 .
"HATCH"))))) (setq e2
(car (xdrx
-entsel "\nSelect the color blocks to be merged<Exit>:" '
((0 .
"HATCH"))))) )
(xdrx-begin)
(if (_hasInterPnts e1 e2
) (xdrx-hatch->mpolygon e1 t)
(xdrx-hatch->mpolygon e2 t)
(xdrx-mpolygon-union e1 e2)
(xdrx-mpolygon->hatch e1)
(xdrx
-prompt "\nTwo color blocks were successfully merged.") )
)
(xdrx-end)
)
)
)