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 Subtract the HATCH,MPOLYGON,REGION entities.(any combination)
(defun c:XDTB
-Subtract
(/ 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,REGION,MPOLYGON"))))) (setq e2
(car (xdrx
-entsel "\nSelect the color blocks to be Subtract.<Exit>:" '
((0 .
"HATCH,REGION,MPOLYGON"))))) )
(xdrx-begin)
(if (_hasInterPnts e1 e2
) (xdrx-get-subtract e1 e2)
(xdrx
-prompt "\nTwo color blocks were successfully Subtract.") )
)
(xdrx-end)
)
)
)