Author Topic: [XDrX-PlugIn(15)] Split Block by Polyline via CLIP  (Read 997 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Bull Frog
  • Posts: 424
[XDrX-PlugIn(15)] Split Block by Polyline via CLIP
« on: November 27, 2023, 11:56:19 PM »
http://www.theswamp.org/index.php?topic=52402.0



The original post hopes to achieve this by cutting the entities within the block. I think it is not as convenient and versatile as the CLIP method.



Main Function:

1. xdrx-geom-searchregions
2. xdrx-entity-sortoncurve
3. xdrx-insert-clip


Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.   (if
  3.     (and (setq blkref1 (car (xdrx-entsel "\nSelect INSERT <Quit>:" '((0 . "insert")))))
  4.          (setq ln (car (xdrx-entsel "\nPick Curve<Quit>:" '((0 . "*line")))))
  5.          (setq box (xdrx-entity-box blkref1) ; insert bounding box
  6.                box (xd::pnts:close box) ; closed
  7.          )
  8.          (setq ints (xdrx-entity-intersectwith ln box))
  9.                                         ; find the intersection point
  10.     )
  11.      (progn
  12.        (xdrx-begin)
  13.        (setq ge  (xdge::constructor "kcompositecrv3d" box)
  14.                                         ;Construct LWPOLYLINE geometric object
  15.              crv (xdrx-entity-make ge)
  16.                  ;;Generate LWPOLYLINE
  17.        )
  18.        (if (setq regions (xdrx-geom-searchregions ln crv t))
  19.                                         ; Query to create closed regions
  20.          (progn
  21.            (setq regions (xdrx-pickset->ents regions)
  22.                  ents    (xdrx-entity-sortoncurve
  23.                                         ; Sort entities along the specified entity
  24.                            (list (car box) (cadr box))
  25.                            regions
  26.                          )
  27.                  blkref2 (xdrx-entity-copy blkref1)
  28.                                         ; Create an INSERT copy
  29.                  blkref2 (entlast)
  30.            )
  31.            (xdrx-insert-clip blkref1 (car ents)) ;Create XCLIP
  32.            (xdrx-insert-clip blkref2 (cadr ents)) ;Create XCLIP
  33.            (xdrx-entity-delete ents)
  34.            (xdrx-object-regen blkref2)  ;The object itself REGEN
  35.           ;(xdrx-entity-move blkref2 (car box) (cadr box))
  36.            (xd::drag:simplemove blkref2 "\nInsertion point:" 5 t)
  37.                                         ;Drag to move
  38.          )
  39.        )
  40.        (xdrx-end)
  41.      )
  42.   )
  43.   (princ)
  44. )
« Last Edit: November 27, 2023, 11:59:30 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