Author Topic: [XDrX-PlugIn(10)] Trim Extend to Polyline boundry  (Read 940 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 527
[XDrX-PlugIn(10)] Trim Extend to Polyline boundry
« on: November 27, 2023, 03:55:08 AM »
I saw a friend’s request and wrote one




The idea is:
1. Find the two intersection points of the inner polyline and the outer frame,
2. The two intersection points and other vertices of the polyline are sorted along this polyline.
3. Extract the sub-table between the intersection points of the sorted point table, which is the vertex table of the polyline we want.
4. Generate polyline

Main functions used:
1. (xdrx-points-sortoncurve curve intpnts)
Along the curve, sort the point table intpnts

2. (xdrx-setpropertyvalue pline "set" vertexs)
Reset polyline PLINE according to vertex table



Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.   (if
  3.     (and (setq
  4.            e1 (car
  5.                 (xdrx-entsel
  6.                   "\nPick polyline 1<Exit>:"
  7.                   '((0 . "*polyline"))
  8.                 )
  9.               )
  10.          )
  11.          (setq
  12.            ss (xdrx-ssget
  13.                 "\nPick internal polyline <exit>:"
  14.                 '((0 . "*polyline"))
  15.               )
  16.          )
  17.     )
  18.      (progn
  19.        (xdrx-begin)
  20.        (mapcar '(lambda (x)
  21.                   (setq ints (xdrx-entity-intersectwith x e1 3))
  22.                   (if ints
  23.                     (progn
  24.                       (setq verts     (xdrx-getpropertyvalue x "vertices")
  25.                             sortpnts1 (xdrx-points-sortoncurve x ints t)
  26.                             sortpnts1 (mapcar 'cadr sortpnts1)
  27.                             sortpnts2 (xdrx-points-sortoncurve
  28.                                         x
  29.                                         (append ints verts)
  30.                                         t
  31.                                       )
  32.                             sortpnts2 (mapcar 'cadr sortpnts2)
  33.                             sortpnts  (reverse
  34.                                         (member
  35.                                           (cadr sortpnts1)
  36.                                           (reverse (member (car sortpnts1) sortpnts2)
  37.                                           )
  38.                                         )
  39.                                       )
  40.                             pl        (xdrx-polyline-make)
  41.                       )
  42.                       (xdrx-setpropertyvalue pl "set" sortpnts)
  43.                       (setq pl (xdrx-entity-make pl))
  44.                       (xdrx-entity-matchprop x pl)
  45.                       (xdrx-object-swapid x pl)
  46.                       (xdrx-entity-delete pl)
  47.                     )
  48.                   )
  49.                 )
  50.  
  51.                (xdrx-pickset->ents ss)
  52.        )
  53.        (xdrx-end)
  54.      )
  55.   )
  56.   (princ)
  57. )
  58.  
« Last Edit: November 27, 2023, 04:01:27 AM 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