Author Topic: [XDrX-PlugIn(22)]Cut Hatch with curve (*line,arc,ellipse)  (Read 1066 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Bull Frog
  • Posts: 424
[XDrX-PlugIn(22)]Cut Hatch with curve (*line,arc,ellipse)
« on: November 29, 2023, 11:03:56 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (if (and (setq ha (xdrx-entsel
  3.                        "\nSelect The Hatch<Exit>:"
  4.                        '((0 . "hatch"))
  5.                      )
  6.             )
  7.             (setq pt (cadr ha)
  8.                   ha (car ha)
  9.             )
  10.             (setq ss (xdrx-ssget
  11.                        "\nSelect The Curve Through<Exit>:"
  12.                        '((0 . "*line,arc,ellipse"))
  13.                      )
  14.             )
  15.        )
  16.      (progn
  17.        (xdrx-begin)
  18.        (setq ents (xdrx-pickset->ents ss)
  19.              assocLoops (xdrx-getpropertyvalue ha "assocobjids")
  20.              rootloop (xdrx-getpropertyvalue ha "rootloopat" pt)
  21.        )
  22.        (xdrx-setpropertyvalue ha "removeassocobjids")
  23.        (setq pl (xdrx-entity-make rootloop)
  24.              ents (cons pl ents)
  25.        )
  26.        (if (setq
  27.              ss1 (xdrx-geom-searchregions ents t)
  28.            )
  29.          (progn
  30.            (setq l (mapcar '(lambda (x)
  31.                               (list (xdrx-object-clone ha) x)
  32.                             )
  33.                            (xdrx-pickset->ents ss1)
  34.                    )
  35.            )
  36.            (foreach n l
  37.              (if (setq has (apply 'xdrx-get-intersect n))
  38.                (progn
  39.                  (setq assobj (xdrx-getpropertyvalue (car n) "assocobjids"))
  40.                  (xdrx-entity-matchprop (car assocloops) assobj)
  41.                  (xdrx-entity-setcolor (car n) (xdrx-math-rand 1 10))
  42.                )
  43.              )
  44.            )
  45.            (xdrx-entity-delete assocLoops)
  46.            (xdrx-entity-delete ha)
  47.          )
  48.        )
  49.        (xdrx-end)
  50.      )
  51.    )
  52.   (princ)
  53. )
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

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: [XDrX-PlugIn(22)]Cut Hatch with curve (*line,arc,ellipse)
« Reply #1 on: November 30, 2023, 11:21:03 AM »
... and then acad closes without any further warnings ...
« Last Edit: November 30, 2023, 12:21:04 PM by domenicomaria »

xdcad

  • Bull Frog
  • Posts: 424
Re: [XDrX-PlugIn(22)]Cut Hatch with curve (*line,arc,ellipse)
« Reply #2 on: November 30, 2023, 08:37:33 PM »
... and then acad closes without any further warnings ...

In my case, when I used your DWG, there was no error.
I'm not sure. The API has been updated. Please download the latest one and try it.
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

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: [XDrX-PlugIn(22)]Cut Hatch with curve (*line,arc,ellipse)
« Reply #3 on: December 01, 2023, 01:03:22 AM »
Yes
with the latest updated API, it works.
But, it could be improved ...
... because if I select all the curves,
it draws more clones of the original hatch ...

... but substantially it works

https://drive.google.com/file/d/1MIAP6_2WPBX0NnTY1LjBWJQMW2grLrLm/view?usp=sharing

xdcad

  • Bull Frog
  • Posts: 424
Re: [XDrX-PlugIn(22)]Cut Hatch with curve (*line,arc,ellipse)
« Reply #4 on: December 01, 2023, 03:11:15 AM »
Yes
with the latest updated API, it works.
But, it could be improved ...
... because if I select all the curves,
it draws more clones of the original hatch ...

... but substantially it works

https://drive.google.com/file/d/1MIAP6_2WPBX0NnTY1LjBWJQMW2grLrLm/view?usp=sharing

LISP programs need improvement
You can also try not to involve the internal boundaries in the xdrx-geom-searchregions search and creation process, and only look for the outermost ROOT LOOP and divided curves of HATCH.
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

xdcad

  • Bull Frog
  • Posts: 424
Re: [XDrX-PlugIn(22)]Cut Hatch with curve (*line,arc,ellipse)
« Reply #5 on: December 01, 2023, 03:58:43 AM »
Yes
with the latest updated API, it works.
But, it could be improved ...
... because if I select all the curves,
it draws more clones of the original hatch ...

... but substantially it works

https://drive.google.com/file/d/1MIAP6_2WPBX0NnTY1LjBWJQMW2grLrLm/view?usp=sharing

The main thing is:
When (apply 'xdrx-get-intersect n) == NIL, the cloned HATCH should be deleted and that's it.

Code - Auto/Visual Lisp: [Select]
  1.            (if (setq has (apply 'xdrx-get-intersect n))
  2.                 (progn
  3.                   (setq assobj (xdrx-getpropertyvalue (car n) "assocobjids"))
  4.                   (xdrx-entity-matchprop (car assocloops) assobj)
  5.                   (xdrx-entity-setcolor (car n) (xdrx-math-rand 1 10))
  6.                 )
  7.                 (progn
  8.                   (xdrx-entity-delete n) ;; add this
  9.                 )
  10.              )
  11.  
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

xdcad

  • Bull Frog
  • Posts: 424
Re: [XDrX-PlugIn(22)]Cut Hatch with curve (*line,arc,ellipse)
« Reply #6 on: December 01, 2023, 04:45:37 AM »
Yes
with the latest updated API, it works.
But, it could be improved ...
... because if I select all the curves,
it draws more clones of the original hatch ...

... but substantially it works

https://drive.google.com/file/d/1MIAP6_2WPBX0NnTY1LjBWJQMW2grLrLm/view?usp=sharing

Corrected code,pls try it.
1. Added a collection of curves that intersect with the outermost LOOP of HATCH.
2. When xdrx-get-intersect returns NIL, delete the cloned HATCH entity and curve boundary

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.   (if (and (setq ha (xdrx-entsel
  3.                       "\nSelect The Hatch<Exit>:"
  4.                       '((0 . "hatch"))
  5.                     )
  6.            )
  7.            (setq pt (cadr ha)
  8.                  ha (car ha)
  9.            )
  10.            (xdrx-entity-redraw ha 3)
  11.            (setq ss (xdrx-ssget
  12.                       "\nSelect The Curve Through<Exit>:"
  13.                       '((0 . "*line,arc,ellipse"))
  14.                     )
  15.            )
  16.       )
  17.     (progn
  18.       (xdrx-begin)
  19.       (setq ents       (xdrx-pickset->ents ss)
  20.             assocLoops (xdrx-getpropertyvalue ha "assocobjids")
  21.             assobj (car assocloops)
  22.             rootloop   (xdrx-getpropertyvalue ha "rootloopat" pt)
  23.             #area1 (xdrx-getpropertyvalue rootloop "area")
  24.       )
  25.       (setq ents1 nil)
  26.       (foreach n ents
  27.         (setq #area2 (xdrx-getpropertyvalue n "area"))
  28.         (if (not (equal #area1 #area2 1e-3))
  29.            (progn
  30.              (if (setq ints (xdrx-entity-intersectwith n rootloop))
  31.                (setq ents1 (cons n ents1))
  32.              )
  33.            )
  34.            (setq assobj n
  35.                    assocloops (cons n assocloops)
  36.            )
  37.         )
  38.       )
  39.       (xdrx-setpropertyvalue ha "removeassocobjids")
  40.       (setq pl    (xdrx-entity-make rootloop)
  41.             ents1 (cons pl ents1)
  42.       )
  43.       (if (setq ss1     (xdrx-geom-searchregions ents1 t))
  44.         (progn
  45.           (setq l (mapcar '(lambda (x)
  46.                              (if (not (member x assocloops))
  47.                                (list (xdrx-object-clone ha) x)
  48.                              )
  49.                            )
  50.                           (xdrx-pickset->ents ss1)
  51.                   )
  52.           )
  53.           (foreach n l
  54.             (if (setq has (apply 'xdrx-get-intersect n))
  55.               (progn
  56.                 (setq assobj1 (xdrx-getpropertyvalue (car n) "assocobjids"))
  57.                 (xdrx-entity-matchprop assobj assobj1)
  58.                 (xdrx-entity-setcolor (car n) (xdrx-math-rand 1 10))
  59.               )
  60.               (progn
  61.                 (xdrx-entity-delete n)
  62.               )
  63.             )
  64.           )
  65.           (xdrx-entity-delete assocLoops)
  66.           (xdrx-entity-delete ha)
  67.         )
  68.       )
  69.       (xdrx-end)
  70.     )
  71.   )
  72.   (princ)
  73. )
  74.  
« Last Edit: December 01, 2023, 04:49:00 AM 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

ribarm

  • Gator
  • Posts: 3187
  • Marko Ribar, architect
Re: [XDrX-PlugIn(22)]Cut Hatch with curve (*line,arc,ellipse)
« Reply #7 on: December 01, 2023, 05:13:30 AM »
Hatch is trimable entity, but suppose that this isn't true... You can convert it to block and trim it with this code coded in normal ALISP...

https://www.theswamp.org/index.php?topic=52402.msg617476#msg617476
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

xdcad

  • Bull Frog
  • Posts: 424
Re: [XDrX-PlugIn(22)]Cut Hatch with curve (*line,arc,ellipse)
« Reply #8 on: December 01, 2023, 05:35:29 AM »
Hatch is trimable entity, but suppose that this isn't true... You can convert it to block and trim it with this code coded in normal ALISP...

https://www.theswamp.org/index.php?topic=52402.msg617476#msg617476

The so-called clipping HATCH is, in essence, a clipped boundary LOOP, and then regenerating the HATCH based on the new boundary.
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