Author Topic: Make solid hatch from given plines  (Read 5000 times)

0 Members and 1 Guest are viewing this topic.

ziele_o2k

  • Newt
  • Posts: 49
Make solid hatch from given plines
« on: July 04, 2016, 09:55:01 AM »
Please see attached dwg.

I have boudary (pline on Layer_1) and internal plines (on Layer_2)
I would like to get list of points to make solid hatch for every area.
For hatch I'm using this function:
Code: [Select]
;; By ElpanovEvgeniy
 ;; 03.04.2007 10:03:51:
(defun entmakex-hatch (L)
 (entmakex
  (apply
   'append
   (list
    (list '(0 . "HATCH")
          '(100 . "AcDbEntity")
          '(410 . "Model")
          '(100 . "AcDbHatch")
          '(10 0.0 0.0 0.0)
          '(210 0.0 0.0 1.0)
          '(2 . "SOLID")
          '(70 . 1)
          '(71 . 0)
          (cons 91 (length l))
    ) ;_  list
    (apply 'append
    (mapcar '(lambda (a)
             (apply 'append
                    (list (list '(92 . 7) '(72 . 0) '(73 . 1) (cons 93 (length a)))
                          (mapcar '(lambda (b) (cons 10 b)) a)
                          '((97 . 0))
                    ) ;_  list
             ) ;_  apply
            ) ;_  lambda
            l
    ) ;_  mapcar
    )
    '((75 . 0)
      (76 . 1)
      (47 . 1.)
      (98 . 2)
      (10 0. 0. 0.0)
      (10 0. 0. 0.0)
      (451 . 0)
      (460 . 0.0)
      (461 . 0.0)
      (452 . 1)
      (462 . 1.0)
      (453 . 2)
      (463 . 0.0)
      (463 . 1.0)
      (470 . "LINEAR")
     )
   ) ;_  list
  ) ;_  apply
 ) ;_  entmakex
); _
1)I would like to do that only with ssget plines on layer 1 and layer 2.
2)Second option is to ssget these plines and pick internal point for every area.
Any ideas how to do that?

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Make solid hatch from given plines
« Reply #1 on: July 04, 2016, 10:14:38 AM »
Does your polylines have arced segments? If so, then you can't use point list for (entmake) hatch - you have to do it through command "_.HATCH" or "_.BHATCH"... If your polylines have only straight segments, you can get point list with something like this :

(setq L (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= (car x) 10)) (entget lwpolyline))))
;;; lwpolyline = ename of desired LWPOLYLINE
;;; for ex.
(setq ss (ssget '((0 . "LWPOLYLINE") (8 . "Layer1")))) ;;; <--- you are prompted to select lwpolyline entities that reside on layer "Layer1" no matter if layer is locked or not...
(repeat (setq i (sslength ss))
  (setq lwpolyline (ssname ss (setq i (1- i))))
  (setq L (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= (car x) 10)) (entget lwpolyline))))
  (entmakex-hatch L)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ziele_o2k

  • Newt
  • Posts: 49
Re: Make solid hatch from given plines
« Reply #2 on: July 04, 2016, 10:46:23 AM »
My plines have only straight segments.
I know also how to get point list of lwpline.
Problem is, how to get list of points to make one hatch for every area?

ziele_o2k

  • Newt
  • Posts: 49
Re: Make solid hatch from given plines
« Reply #3 on: July 04, 2016, 11:33:07 AM »
In the meantime I found This post,
How to modify bbpoly for my purposes ?

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Make solid hatch from given plines
« Reply #4 on: July 04, 2016, 12:42:43 PM »
Evgeniy's code isn't quite appropriate for the task...
Here, try with this - tested on your DWG :

Code: [Select]
;; Batch BPoly  -  Lee Mac
;; Generates polylines for every region formed by a selection of lines & polylines
;; Restricted to LWPolylines with linear segments only.
;; Region generation based on a method by Stefan M.
;; Mod by M.R. to add ability for hatching resulting LWPOLYLINES

;; By ElpanovEvgeniy
;; 03.04.2007 10:03:51:
(defun entmakex-hatch (L)
 (entmakex
  (apply
   'append
   (list
    (list '(0 . "HATCH")
          '(100 . "AcDbEntity")
          '(410 . "Model")
          '(100 . "AcDbHatch")
          '(10 0.0 0.0 0.0)
          '(210 0.0 0.0 1.0)
          '(2 . "SOLID")
          '(70 . 1)
          '(71 . 0)
          '(91 . 1)
    ) ;_  list
    (apply 'append
      (list (list '(92 . 7) '(72 . 0) '(73 . 1) (cons 93 (length L)))
      (mapcar '(lambda (b) (cons 10 b)) L)
      '((97 . 0))
      ) ;_  list
    ) ;_  apply
    '((75 . 0)
      (76 . 1)
      (47 . 1.)
      (98 . 2)
      (10 0. 0. 0.0)
      (10 0. 0. 0.0)
      (451 . 0)
      (460 . 0.0)
      (461 . 0.0)
      (452 . 1)
      (462 . 1.0)
      (453 . 2)
      (463 . 0.0)
      (463 . 1.0)
      (470 . "LINEAR")
     )
   ) ;_  list
  ) ;_  apply
 ) ;_  entmakex
); _

(defun c:bbpoly&hatch ( / *error* big ent enx idx int lst pt1 pt2 rtn sel spc tmp tot val var vtx entl )

    (defun *error* ( msg )
        (foreach obj rtn
            (if (and (vlax-write-enabled-p obj) (not (vlax-erased-p obj)))
                (vla-delete obj)
            )
        )
        (mapcar 'setvar var val)
        (LM:endundo (LM:acdoc))
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )

    (LM:startundo (LM:acdoc))
    (cond
        (   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (getvar 'clayer))))))
            (princ "\nCurrent layer locked.")
        )
        (   (setq sel
                (LM:ssget "\nSelect Lines & Polylines: "
                    (list
                        (list
                           '(-4 . "<OR")
                               '(0 . "LINE")
                               '(-4 . "<AND")
                                   '(0 . "LWPOLYLINE")
                                   '(-4 . "<NOT")
                                       '(-4 . "<>")
                                       '(42 . 0.0)
                                   '(-4 . "NOT>")
                               '(-4 . "AND>")
                           '(-4 . "OR>")
                            (if (= 1 (getvar 'cvport))
                                (cons 410 (getvar 'ctab))
                               '(410 . "Model")
                            )
                        )
                    )
                )
            )
            (setq spc
                (vlax-get-property (LM:acdoc)
                    (if (= 1 (getvar 'cvport))
                        'paperspace
                        'modelspace
                    )
                )
            )
            (repeat (setq idx (sslength sel))
                (if (= "LINE" (cdr (assoc 0 (setq enx (entget (ssname sel (setq idx (1- idx))))))))
                    (setq lst (cons (list (cdr (assoc 10 enx)) (cdr (assoc 11 enx))) lst))
                    (setq vtx (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) enx))
                          vtx (mapcar 'list vtx (if (= 1 (logand 1 (cdr (assoc 70 enx)))) (cons (last vtx) vtx) (cdr vtx)))
                          lst (append vtx lst)
                    )
                )
            )
            (foreach pl1 lst
                (setq pt1 (car  pl1)
                      pt2 (cadr pl1)
                )
                (foreach pl2 lst
                    (if
                        (and
                            (not (equal pl1 pl2 1e-8))
                            (setq int (inters pt1 pt2 (car pl2) (cadr pl2)))
                            (not (vl-member-if '(lambda ( pnt ) (equal pnt int 1e-8)) pl1))
                        )
                        (setq pl1 (cons int pl1))
                    )
                )
                (setq rtn
                    (append
                        (mapcar
                            (function
                                (lambda ( a b )
                                    (vla-addline spc
                                        (vlax-3D-point a)
                                        (vlax-3D-point b)
                                    )
                                )
                            )
                            (setq pl1
                                (vl-sort pl1
                                    (function
                                        (lambda ( a b )
                                            (< (distance pt1 a) (distance pt1 b))
                                        )
                                    )
                                )
                            )
                            (cdr pl1)
                        )
                        rtn
                    )
                )
            )
            (setq var '(cmdecho peditaccept)
                  val  (mapcar 'getvar var)
                  tot  0.0
            )
            (mapcar 'setvar var '(0 1))
            (foreach reg (vlax-invoke spc 'addregion rtn)
                (setq ent (entlast))
                (command "_.pedit" "_m")
                (apply 'command (mapcar 'vlax-vla-object->ename (vlax-invoke reg 'explode)))
                (command "" "_j" "" "")
                (if
                    (and
                        (not (eq ent (setq ent (entlast))))
                        (= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
                    )
                    (progn
                        (setq tmp (vlax-curve-getarea ent)
                              tot (+ tot tmp)
                              entl (cons ent entl)
                        )
                        (if (< (car big) tmp)
                            (setq big (list tmp ent))
                        )
                    )
                )
                (vla-delete reg)
            )
            (if (equal (car big) (/ tot 2.0) 1e-3) ;; Gian Paolo Cattaneo
                (entdel (cadr big))
            )
            (foreach obj rtn (vla-delete obj))
            (mapcar 'setvar var val)
        )
    )
    (foreach ent entl
      (if (not (vlax-erased-p ent))
        (progn
          (entmakex-hatch (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= (car x) 10)) (entget ent))))
          (entdel ent)
          (command "_.DRAWORDER" "_L" "" "_B")
        )
      )
    )
    (LM:endundo (LM:acdoc))
    (princ)
)

;; ssget  -  Lee Mac
;; A wrapper for the ssget function to permit the use of a custom selection prompt
;; msg - [str] selection prompt
;; arg - [lst] list of ssget arguments

(defun LM:ssget ( msg arg / sel )
    (princ msg)
    (setvar 'nomutt 1)
    (setq sel (vl-catch-all-apply 'ssget arg))
    (setvar 'nomutt 0)
    (if (not (vl-catch-all-error-p sel)) sel)
)

;; Start Undo  -  Lee Mac
;; Opens an Undo Group.

(defun LM:startundo ( doc )
    (LM:endundo doc)
    (vla-startundomark doc)
)

;; End Undo  -  Lee Mac
;; Closes an Undo Group.

(defun LM:endundo ( doc )
    (while (= 8 (logand 8 (getvar 'undoctl)))
        (vla-endundomark doc)
    )
)

;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object

(defun LM:acdoc nil
    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:acdoc)
)
(vl-load-com) (princ)

HTH
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ziele_o2k

  • Newt
  • Posts: 49
Re: Make solid hatch from given plines
« Reply #5 on: July 04, 2016, 04:47:56 PM »
Evgeniy's code isn't quite appropriate for the task...
Maybe this:
Code - Auto/Visual Lisp: [Select]
  1. (setq hobj (vla-addhatch spc achatchpatterntypepredefined "SOLID" :vlax-true achatchobject))
  2.     (vlax-make-variant
  3.         (vlax-make-safearray vlax-vbobject '(0 . 0))
  4.         (list (vlax-ename->vla-object ent))
  5.       )
  6.     )
  7.   )
in place of this
Code - Auto/Visual Lisp: [Select]
  1. (entmakex-hatch (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= (car x) 10)) (entget ent))))

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Make solid hatch from given plines
« Reply #6 on: July 04, 2016, 05:13:28 PM »
What I meant to say is that I've modified it slightly... Should be fine if you test my posted code with your DWG... Make sure you select appropriate polylines or make selection with (ssget '((0 . "LWPOLYLINE") (8 . "LAYER1,LAYER2")))... And then when asked for selection while routine, just pass "_Previous"... And that's it, new hatches should be created leaving boundaries unchanged (entdeleted bbpoly polylines)...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ziele_o2k

  • Newt
  • Posts: 49
Re: Make solid hatch from given plines
« Reply #7 on: July 05, 2016, 03:59:47 AM »
One more thing. Please see attached file.

Plines on layer_2 are with these Lee Mac function
And there is problem with small gaps when I whant to generate solids.
I have no idea where to start... any suggestions?

Function for makeing plines (to run this lisp you have to attached CADPL-Pack library:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tests2p ( / *error* ss in ent lst newent)
  2.   (defun *error* (msg / so)
  3.     (cond
  4.       ((not msg))
  5.       ((member msg '("Function cancelled" "quit / exit abort")))
  6.       (
  7.         (princ (strcat "\n  <!>  Error: " msg "  <!> "))
  8.         (cond (DebugMode (vl-bt)))
  9.       )
  10.     )  
  11.     (princ)
  12.   )
  13.   (cd:SYS_UndoBegin)
  14.   (if (setq ss (ssget '((0 . "SPLINE"))))
  15.     (repeat (setq in (sslength ss))
  16.       (setq
  17.         ent (ssname ss (setq in (1- in)))
  18.         lst
  19.         (mapcar
  20.           '(lambda (_1)
  21.             (print _1)
  22.             (list (car _1) (cadr _1))
  23.           )
  24.           (LM:Entity->PointList ent)
  25.         )
  26.       )
  27.       (setq newent (vlax-vla-object->ename (cd:ACX_AddLWPolyline (cd:ACX_ASpace) lst nil)))
  28.       (cd:ENT_SetDXF newent 8 (cdr (assoc 8 (entget ent))))
  29.       (if (cdr (assoc 48 (entget ent)))
  30.         (cd:ENT_SetDXF newent 48 (cdr (assoc 48 (entget ent))))
  31.       )
  32.       (cd:ENT_SetDXF newent 70 128)
  33.       (entdel ent)
  34.     )
  35.   )
  36.   (cd:SYS_UndoEnd)
  37. )

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Make solid hatch from given plines
« Reply #8 on: July 05, 2016, 06:16:58 AM »
You did first step correct - you converted splines to lwpolylines... Then I've found that small gap that had to be connected, then I applied (c:bbpoly&hatch)... It seems that its OK... See DWG in attachment...

BTW. With splined geometry, hatch is I suppose complex to (entmakex), so you'd probably have to use commands, and beside that SPLINES derived from boundaries don't look quite perfect - look around intersecting vertices... See DWG in attachment...

HTH, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ziele_o2k

  • Newt
  • Posts: 49
Re: Make solid hatch from given plines
« Reply #9 on: July 05, 2016, 07:40:40 AM »
Then I've found that small gap that had to be connected
My question is, how to connect these plines not manualy but in my lisp tests2p.

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Make solid hatch from given plines
« Reply #10 on: July 05, 2016, 08:59:52 AM »
Then I've found that small gap that had to be connected
My question is, how to connect these plines not manualy but in my lisp tests2p.

It's a little complicated, but everything is possible if you want to do it with strong wish... I'd firstly search for intersection points using 'intersectwith method with ending parameter acextendboth... Then I'd compare those points with start/end points of plines... If (vlax-curve-getparamatpoint pline intpoint) ;;; pline - lwpoly ename ;;; intpoint - checking point from 'intersectwith method; returns a value, it means that you don't need to do anything - pline is crossing other pline/entity; but if it returns nil, you have to use "_.EXTEND" command, or even better (entmod) function applied in combination with (subst), so you can change start/end point of pline to match intpoint... That way prepared DWG is ready for next processing like (c:bbpoly&hatch), or if you wish just (c:bbpoly) after which you can manually or again automatically process extrusions on resulting LWPOLYLINES that are closed...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Make solid hatch from given plines
« Reply #11 on: July 05, 2016, 11:33:07 AM »
Not to struggle too much, I've checked my library and I already have something that can help you... First you convert splines to lwpolylines like you know, then you use "plintav-adv.lsp" and then "weld2d.lsp" with fuzz 0.5... The DWG should be prepared for next (c:bbpoly&hatch) or (c:bbpoly)... Now if you want all to be automatic, all you have to do is figure out how to combine those lisps into single one you'll plan to use...

HTH, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ziele_o2k

  • Newt
  • Posts: 49
Re: Make solid hatch from given plines
« Reply #12 on: July 05, 2016, 02:23:36 PM »
I came up with something like this
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tee4 nil (PZ:FindPlinesToModify (ssget '((0 . "LWPOLYLINE")))))
  2. (defun PZ:FindPlinesToModify (ss / EntLst tmpLst)
  3.   (setq EntLst (LM:ss->ent ss))
  4.   (setq finalLst
  5.     (mapcar
  6.       '(lambda (_1)
  7.         (setq tmpLst
  8.           (list _1
  9.             (caar
  10.               (vl-sort
  11.                 (mapcar
  12.                   '(lambda (_2)
  13.                     (list
  14.                       ;_1
  15.                       _2
  16.                       (distance (vlax-curve-getClosestPointTo (vlax-ename->vla-object _2) (vlax-curve-getStartPoint _1)) (vlax-curve-getStartPoint _1))
  17.                     )
  18.                   )
  19.                   (LM:ListDifference EntLst (list _1))
  20.                 )
  21.                 (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))
  22.               )
  23.             )
  24.             (caar
  25.               (vl-sort
  26.                 (mapcar
  27.                   '(lambda (_2)
  28.                     (list
  29.                       ;_1
  30.                       _2
  31.                       (distance (vlax-curve-getClosestPointTo (vlax-ename->vla-object _2) (vlax-curve-getEndPoint _1)) (vlax-curve-getEndPoint _1))
  32.                     )
  33.                   )
  34.                   (LM:ListDifference EntLst (list _1))
  35.                 )
  36.                 (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))
  37.               )
  38.             )
  39.           )
  40.         )
  41.       )
  42.       EntLst
  43.     )
  44.   )
  45.   (princl finalLst)
  46. )
  47. ;; Print List  -  Lee Mac
  48. ;; Prints a supplied list to the command-line or to a given filename,
  49. ;; with nested lists displayed in a hierarchical format.
  50. ;; l - [lst] List to print
  51. ;; f - [str] Optional filename
  52. (defun LM:princl ( l f / _print _princ d r )
  53.    
  54.     (defun _print ( l i )
  55.         (if (and (= 'list (type l)) (vl-list-length l) (vl-some 'vl-consp l))
  56.             (progn
  57.                 (_princ (strcat "\n" i "("))
  58.                 (foreach x l (_print x (strcat i "    ")))
  59.                 (_princ (strcat "\n" i ")"))
  60.             )
  61.             (_princ (strcat "\n" i (vl-prin1-to-string l)))
  62.         )
  63.     )
  64.  
  65.     (eval
  66.         (list 'defun '_princ '( x )
  67.             (if (and (= 'str (type f)) (setq d (open f "w")))
  68.                 (list 'princ 'x d)
  69.                '(princ x)
  70.             )
  71.         )
  72.     )
  73.  
  74.     (setq r (vl-catch-all-apply '_print (list l "")))
  75.     (if (= 'file (type d))
  76.         (progn
  77.             (setq d (close d))
  78.             (startapp "notepad" f)
  79.         )
  80.     )
  81.         l
  82.     )
  83. )
  84. (defun princl ( l ) (LM:princl l nil) (princ))
  85. (defun princf ( l ) (LM:princl l (vl-filename-mktemp "list" (getvar 'dwgprefix) ".txt")) (princ))
  86. ;;-------------------=={ List Difference }==------------------;;
  87. ;;                                                            ;;
  88. ;;  Returns items appearing exclusively in one list but not   ;;
  89. ;;  another, i.e. the relative complement: l1 \ l2            ;;
  90. ;;------------------------------------------------------------;;
  91. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  92. ;;------------------------------------------------------------;;
  93. ;;  Arguments:                                                ;;
  94. ;;  l1,l2 - lists for which to return the difference          ;;
  95. ;;------------------------------------------------------------;;
  96. ;;  Returns:  List of items appearing exclusively in list l1  ;;
  97. ;;------------------------------------------------------------;;
  98. (defun LM:ListDifference ( l1 l2 )
  99.   (vl-remove-if '(lambda ( x ) (member x l2)) l1)
  100. )
  101. ;;--------------=={ SelectionSet -> Entities }==--------------;;
  102. ;;                                                            ;;
  103. ;;  Converts a SelectionSet to a list of Entities             ;;
  104. ;;------------------------------------------------------------;;
  105. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  106. ;;------------------------------------------------------------;;
  107. ;;  Arguments:                                                ;;
  108. ;;  ss - Valid SelectionSet (Pickset)                         ;;
  109. ;;------------------------------------------------------------;;
  110. ;;  Returns:  List of Entity names, else nil                  ;;
  111. ;;------------------------------------------------------------;;
  112. (defun LM:ss->ent ( ss / i l )
  113.     (if ss
  114.         (repeat (setq i (sslength ss))
  115.             (setq l (cons (ssname ss (setq i (1- i))) l))
  116.         )
  117.     )
  118. )
  119.  
My final list looks like this:
Code: [Select]
(
    (<Nazwa elementu: 7ffff9132c0> <Nazwa elementu: 7ffff913200> <Nazwa elementu: 7ffff9132b0>)
    (<Nazwa elementu: 7ffff9132b0> <Nazwa elementu: 7ffff913200> <Nazwa elementu: 7ffff913200>)
    (<Nazwa elementu: 7ffff9132a0> <Nazwa elementu: 7ffff913200> <Nazwa elementu: 7ffff913290>)
    (<Nazwa elementu: 7ffff913290> <Nazwa elementu: 7ffff913200> <Nazwa elementu: 7ffff913250>)
    (<Nazwa elementu: 7ffff913250> <Nazwa elementu: 7ffff913200> <Nazwa elementu: 7ffff913200>)
    (<Nazwa elementu: 7ffff913200> <Nazwa elementu: 7ffff9132a0> <Nazwa elementu: 7ffff913250>)
)
Where first element of sublist is entity of pline to extend, second is entity to which should be extended start point of pline to extend and third element is entity of pline to which should be extended end point of pline to extend.
Now I have to figure out how to do that....
I'm thinking to use something from Lee Mac page, but I have to add some coding for closest intersection of start and end point of polyline to extend.
Intersection with (depend on mode) can return to much intersection points.

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Make solid hatch from given plines
« Reply #13 on: July 05, 2016, 03:39:38 PM »
If I may comment your code... I don't quite see how do you plan to use it on your example - gap between start/end point of one pline and closest point of intersection on other pline somewhere on other pline - not start/end vertex... What I stated earlier is logical solution to this task IMHO and 'intersectwith method should be used - well it depends what parameter should you choose acextendthisentity, or acextendotherentity, or alternatively (but I am not 100% sure acextendboth) (acextendnone IMO you should avoid)... I know that my "plintav-adv.lsp" creates additional vertices that may be unnecessary, but you derive lwpolylines from splines anyway and some approximation is therefore applied from the very beginning of process... If I may ask : Do you really need plines? Can you use REGIONS instead? What do you plan to do after when routine is processed? Do you need hatching or extrusions for 3d modelling? Either way it looks that you can avoid all this by simply using BPOLY command with REGION option and then hatch manually or extrude or loft or sweep that region or revolve it or...? Am I right if I may say so that you're loosing time by coding something that could be done faster by manual using commands in command line?
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ziele_o2k

  • Newt
  • Posts: 49
Re: Make solid hatch from given plines
« Reply #14 on: July 05, 2016, 07:20:13 PM »
This is how I want to use this. This coding below has big bugs but this is my direction.

New function is PZ:ExtendPline

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tee4 nil (PZ:FindPlinesToModify (ssget '((0 . "LWPOLYLINE")))))
  2. (defun PZ:FindPlinesToModify (ss / *error* PZ:ExtendPline EntLst tmpLst)
  3.   (defun *error* (msg / so)
  4.     (cond
  5.       ((not msg))
  6.       ((member msg '("Function cancelled" "quit / exit abort")))
  7.       (
  8.         (princ (strcat "\n  <!>  Error : " msg "  <!> "))
  9.         (cond (DebugMode (vl-bt)))
  10.       )
  11.     )  
  12.     (princ)
  13.   )
  14.   (defun PZ:ExtendPline ( lst / vla_lst pl_m vla_pl_s vla_pl_e tmpLine_s tmpLine_e pts eds pte ede )
  15.     (setq
  16.       vla_lst (mapcar 'vlax-ename->vla-object lst)
  17.       pl_m (car lst)
  18.       vla_pl_s (cadr vla_lst)
  19.       vla_pl_e (caddr vla_lst)
  20.     )
  21.     (setq
  22.       tmpLine_s
  23.       (cd:ACX_AddLine
  24.         (cd:ACX_ASpace)
  25.         nil
  26.       )
  27.       tmpLine_e
  28.       (cd:ACX_AddLine
  29.         (cd:ACX_ASpace)
  30.         nil
  31.       )
  32.     )
  33.     (cond
  34.       (
  35.         (setq pts (car(LM:intersections tmpLine_s vla_pl_s acextendnone)))
  36.         (setq eds (subst (cons 10 (list (car pts) (cadr pts))) (assoc 10 (entget pl_m)) (entget pl_m)))
  37.       )
  38.       (
  39.         (setq pts (car(LM:intersections tmpLine_s vla_pl_s acextendthisentity)))
  40.         (setq eds (subst (cons 10 (list (car pts) (cadr pts))) (assoc 10 (entget pl_m)) (entget pl_m)))
  41.       )
  42.     )
  43.     (entmod eds)
  44.     (cond
  45.       (
  46.         (setq pte (car(LM:intersections tmpLine_e vla_pl_e acextendnone)))
  47.         (setq ede (subst (cons 10 (list (car pte) (cadr pte))) (assoc 10 (reverse(entget pl_m))) (entget pl_m)))
  48.       )
  49.       (
  50.         (setq pte (car(LM:intersections tmpLine_e vla_pl_e acextendthisentity)))
  51.         (setq ede (subst (cons 10 (list (car pte) (cadr pte))) (assoc 10 (reverse(entget pl_m))) (entget pl_m)))
  52.       )
  53.     )
  54.     (entmod ede)
  55.     (vla-Delete tmpLine_s)
  56.     (vla-Delete tmpLine_e)
  57.   )
  58.   (setq EntLst (LM:ss->ent ss))
  59.   (setq finalLst
  60.     (mapcar
  61.       '(lambda (_1)
  62.         (setq tmpLst
  63.           (list _1
  64.             (caar
  65.               (vl-sort
  66.                 (mapcar
  67.                   '(lambda (_2)
  68.                     (list
  69.                       ;_1
  70.                       _2
  71.                       (distance (vlax-curve-getClosestPointTo (vlax-ename->vla-object _2) (vlax-curve-getStartPoint _1)) (vlax-curve-getStartPoint _1))
  72.                     )
  73.                   )
  74.                   (LM:ListDifference EntLst (list _1))
  75.                 )
  76.                 (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))
  77.               )
  78.             )
  79.             (caar
  80.               (vl-sort
  81.                 (mapcar
  82.                   '(lambda (_2)
  83.                     (list
  84.                       ;_1
  85.                       _2
  86.                       (distance (vlax-curve-getClosestPointTo (vlax-ename->vla-object _2) (vlax-curve-getEndPoint _1)) (vlax-curve-getEndPoint _1))
  87.                     )
  88.                   )
  89.                   (LM:ListDifference EntLst (list _1))
  90.                 )
  91.                 (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))
  92.               )
  93.             )
  94.           )
  95.         )
  96.       )
  97.       EntLst
  98.     )
  99.   )
  100.   (foreach _n finalLst (PZ:ExtendPline _n))
  101.   (princl finalLst)
  102. )
  103. ;; Intersections  -  Lee Mac
  104. ;; Returns a list of all points of intersection between two objects
  105. ;; for the given intersection mode.
  106. ;; ob1,ob2 - [vla] VLA-Objects
  107. ;;     mod - [int] acextendoption enum of intersectwith method
  108.  
  109. (defun LM:intersections ( ob1 ob2 mod / lst rtn )
  110.     (setq lst (vlax-invoke ob1 'intersectwith ob2 mod))
  111.     (repeat (/ (length lst) 3)
  112.         (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
  113.               lst (cdddr lst)
  114.         )
  115.     )
  116.     (reverse rtn)
  117. )
  118. ;; Print List  -  Lee Mac
  119. ;; Prints a supplied list to the command-line or to a given filename,
  120. ;; with nested lists displayed in a hierarchical format.
  121. ;; l - [lst] List to print
  122. ;; f - [str] Optional filename
  123. (defun LM:princl ( l f / _print _princ d r )
  124.  
  125.     (defun _print ( l i )
  126.         (if (and (= 'list (type l)) (vl-list-length l) (vl-some 'vl-consp l))
  127.             (progn
  128.                 (_princ (strcat "\n" i "("))
  129.                 (foreach x l (_print x (strcat i "    ")))
  130.                 (_princ (strcat "\n" i ")"))
  131.             )
  132.             (_princ (strcat "\n" i (vl-prin1-to-string l)))
  133.         )
  134.     )
  135.  
  136.     (eval
  137.         (list 'defun '_princ '( x )
  138.             (if (and (= 'str (type f)) (setq d (open f "w")))
  139.                 (list 'princ 'x d)
  140.                '(princ x)
  141.             )
  142.         )
  143.     )
  144.  
  145.     (setq r (vl-catch-all-apply '_print (list l "")))
  146.     (if (= 'file (type d))
  147.         (progn
  148.             (setq d (close d))
  149.             (startapp "notepad" f)
  150.         )
  151.     )
  152.         l
  153.     )
  154. )
  155. (defun princl ( l ) (LM:princl l nil) (princ))
  156. (defun princf ( l ) (LM:princl l (vl-filename-mktemp "list" (getvar 'dwgprefix) ".txt")) (princ))
  157. ;;-------------------=={ List Difference }==------------------;;
  158. ;;                                                            ;;
  159. ;;  Returns items appearing exclusively in one list but not   ;;
  160. ;;  another, i.e. the relative complement: l1 \ l2            ;;
  161. ;;------------------------------------------------------------;;
  162. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  163. ;;------------------------------------------------------------;;
  164. ;;  Arguments:                                                ;;
  165. ;;  l1,l2 - lists for which to return the difference          ;;
  166. ;;------------------------------------------------------------;;
  167. ;;  Returns:  List of items appearing exclusively in list l1  ;;
  168. ;;------------------------------------------------------------;;
  169. (defun LM:ListDifference ( l1 l2 )
  170.   (vl-remove-if '(lambda ( x ) (member x l2)) l1)
  171. )
  172. ;;--------------=={ SelectionSet -> Entities }==--------------;;
  173. ;;                                                            ;;
  174. ;;  Converts a SelectionSet to a list of Entities             ;;
  175. ;;------------------------------------------------------------;;
  176. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  177. ;;------------------------------------------------------------;;
  178. ;;  Arguments:                                                ;;
  179. ;;  ss - Valid SelectionSet (Pickset)                         ;;
  180. ;;------------------------------------------------------------;;
  181. ;;  Returns:  List of Entity names, else nil                  ;;
  182. ;;------------------------------------------------------------;;
  183. (defun LM:ss->ent ( ss / i l )
  184.     (if ss
  185.         (repeat (setq i (sslength ss))
  186.             (setq l (cons (ssname ss (setq i (1- i))) l))
  187.         )
  188.     )
  189. )
« Last Edit: July 05, 2016, 07:24:50 PM by ziele-o2k »

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Make solid hatch from given plines
« Reply #15 on: July 06, 2016, 02:43:48 AM »
This is how would I do it, but I am still not sure why all this... You can simply get REGIONS with BPOLY command and with original SPLINE entities and then do whatever you like after... Also if you have open SPLINES like in your case, you may use CAB's BreakObjects.lsp posted here at www.theswamp.org at forum show your stuff, to break SPLINES after which you can simply use REGION command to extract REGIONS... Of course you remove biggest one, but that's actually all you have to do - the effect is the same as bbpoly by Lee Mac if not even better (SPLINES don't degrade when in REGIONS)... Anyway here is my version and it don't have bugs...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:extshortlwsaddv ( / *error* bbucs intersobj1obj2 add_vtx *adoc* ucsf ss i ent fuzz ll ur bbl ent1 ent2 ss-ent1 k intpts )
  2.  
  3.  
  4.   (defun *error* ( m )
  5.     (if ucsf
  6.       (command "_.UCS" "_P")
  7.     )
  8.     (vla-endundomark *adoc*)
  9.     (if m
  10.       (prompt m)
  11.     )
  12.     (princ)
  13.   )
  14.  
  15.   (defun bbucs ( ss / UCS2WCSMatrix WCS2UCSMatrix n ent minpt maxpt minptlst maxptlst minptbbx minptbby minptbbz minptbb maxptbbx maxptbby maxptbbz maxptbb )
  16.  
  17.     (vl-load-com)
  18.  
  19.     ;; Doug C. Broad, Jr.
  20.     ;; can be used with vla-transformby to
  21.     ;; transform objects from the UCS to the WCS
  22.     (defun UCS2WCSMatrix ()
  23.       (vlax-tmatrix
  24.         (append
  25.           (mapcar
  26.            '(lambda (vector origin)
  27.             (append (trans vector 1 0 t) (list origin))
  28.           )
  29.           (list '(1 0 0) '(0 1 0) '(0 0 1))
  30.           (trans '(0 0 0) 0 1)
  31.           )
  32.           (list '(0 0 0 1))
  33.         )
  34.       )
  35.     )
  36.     ;; transform objects from the WCS to the UCS
  37.     (defun WCS2UCSMatrix ()
  38.       (vlax-tmatrix
  39.         (append
  40.           (mapcar
  41.            '(lambda (vector origin)
  42.             (append (trans vector 0 1 t) (list origin))
  43.           )
  44.           (list '(1 0 0) '(0 1 0) '(0 0 1))
  45.           (trans '(0 0 0) 1 0)
  46.           )
  47.           (list '(0 0 0 1))
  48.         )
  49.       )
  50.     )
  51.  
  52.     (if ss
  53.       (progn
  54.         (repeat (setq n (sslength ss))
  55.           (setq ent (ssname ss (setq n (1- n))))
  56.           (vla-TransformBy (vlax-ename->vla-object ent) (UCS2WCSMatrix))
  57.           (vla-getboundingbox (vlax-ename->vla-object ent) 'minpoint 'maxpoint)
  58.           (vla-TransformBy (vlax-ename->vla-object ent) (WCS2UCSMatrix))
  59.           (setq minpt (vlax-safearray->list minpoint))
  60.           (setq maxpt (vlax-safearray->list maxpoint))
  61.           (setq minptlst (cons minpt minptlst))
  62.           (setq maxptlst (cons maxpt maxptlst))
  63.         )
  64.         (setq minptbbx (caar (vl-sort minptlst '(lambda (a b) (< (car a) (car b))))))
  65.         (setq minptbby (cadar (vl-sort minptlst '(lambda (a b) (< (cadr a) (cadr b))))))
  66.         (setq minptbbz (caddar (vl-sort minptlst '(lambda (a b) (< (caddr a) (caddr b))))))
  67.         (setq maxptbbx (caar (vl-sort maxptlst '(lambda (a b) (> (car a) (car b))))))
  68.         (setq maxptbby (cadar (vl-sort maxptlst '(lambda (a b) (> (cadr a) (cadr b))))))
  69.         (setq maxptbbz (caddar (vl-sort maxptlst '(lambda (a b) (> (caddr a) (caddr b))))))
  70.         (setq minptbb (list minptbbx minptbby minptbbz))
  71.         (setq maxptbb (list maxptbbx maxptbby maxptbbz))
  72.       )
  73.     )
  74.     (list minptbb maxptbb)
  75.   )
  76.  
  77.   (defun intersobj1obj2 ( obj1 obj2 / coords pt ptlst )
  78.     (if (eq (type obj1) 'ENAME) (setq obj1 (vlax-ename->vla-object obj1)))
  79.     (if (eq (type obj2) 'ENAME) (setq obj2 (vlax-ename->vla-object obj2)))
  80.     (setq coords (vl-catch-all-apply 'vlax-safearray->list (list (vl-catch-all-apply 'vlax-variant-value (list (vla-intersectwith obj1 obj2 AcExtendBoth))))))
  81.     (if (vl-catch-all-error-p coords)
  82.       (setq ptlst nil)
  83.       (repeat (/ (length coords) 3)
  84.         (setq pt (list (car coords) (cadr coords) (caddr coords)))
  85.         (setq ptlst (cons pt ptlst))
  86.         (setq coords (cdddr coords))
  87.       )
  88.     )
  89.     ptlst
  90.   )
  91.  
  92.   (defun add_vtx ( obj add_pt ent_name / bulg sw ew )
  93.       (vla-GetWidth obj (fix add_pt) 'sw 'ew)
  94.       (vla-addVertex
  95.           obj
  96.           (1+ (fix add_pt))
  97.           (vlax-make-variant
  98.               (vlax-safearray-fill
  99.                   (vlax-make-safearray vlax-vbdouble (cons 0 1))
  100.                       (list
  101.                           (car (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
  102.                           (cadr (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
  103.                       )
  104.               )
  105.           )
  106.       )
  107.       (setq bulg (vla-GetBulge obj (fix add_pt)))
  108.       (vla-SetBulge obj
  109.           (fix add_pt)
  110.           (/
  111.               (sin (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
  112.               (cos (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
  113.           )
  114.       )
  115.       (vla-SetBulge obj
  116.           (1+ (fix add_pt))
  117.           (/
  118.               (sin (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
  119.               (cos (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
  120.           )
  121.       )
  122.       (vla-SetWidth obj (fix add_pt) sw (+ sw (* (- ew sw) (- add_pt (fix add_pt)))))
  123.       (vla-SetWidth obj (1+ (fix add_pt)) (+ sw (* (- ew sw) (- add_pt (fix add_pt)))) ew)
  124.       (vla-update obj)
  125.   )
  126.  
  127.   (if (= (getvar 'worlducs) 0)
  128.     (progn
  129.       (command "_.UCS" "_W")
  130.       (setq ucsf t)
  131.     )
  132.   )
  133.   (setq ss (ssget "_:L" '((0 . "LWPOLYLINE"))))
  134.   (repeat (setq i (sslength ss))
  135.     (setq ent (ssname ss (setq i (1- i))))
  136.     (if (not (and (vlax-curve-isplanar ent) (equal (caddr (vlax-curve-getstartpoint ent)) 0.0 1e-6)))
  137.       (ssdel ent ss)
  138.     )
  139.   )
  140.   (setq fuzz 0.51)
  141.   (while (> fuzz 0.5)
  142.     (initget 6)
  143.     (setq fuzz (getdist "\nPick or specify fuzz distance <1e-2> - should not be greater than 0.5 : "))
  144.     (if (null fuzz)
  145.       (setq fuzz 1e-2)
  146.     )
  147.   )
  148.   (setq ll (car (bbucs ss)) ur (cadr (bbucs ss)))
  149.   (setq bbl (list ll (list (car ur) (cadr ll)) ur (list (car ll) (cadr ur))))
  150.   (repeat (setq i (sslength ss))
  151.     (setq ent1 (ssname ss (setq i (1- i))))
  152.     (vla-getboundingbox (vlax-ename->vla-object ent1) 'll 'ur)
  153.     (mapcar 'set '(ll ur) (mapcar 'vlax-safearray->list (list ll ur)))
  154.     (setq ss-ent1 (ssget "_CP" bbl '((0 . "LWPOLYLINE"))))
  155.     (ssdel ent1 ss-ent1)
  156.     (repeat (setq k (sslength ss-ent1))
  157.       (setq ent2 (ssname ss-ent1 (setq k (1- k))))
  158.       (setq intpts (intersobj1obj2 ent1 ent2))
  159.       (if intpts
  160.         (foreach pt intpts
  161.           (if
  162.             (or
  163.               (and
  164.                 (vlax-curve-getparamatpoint ent1 pt)
  165.                 (not (vlax-curve-getparamatpoint ent2 pt))
  166.               )
  167.               (and
  168.                 (not (vlax-curve-getparamatpoint ent1 pt))
  169.                 (vlax-curve-getparamatpoint ent2 pt)
  170.               )
  171.             )
  172.             (cond
  173.               ( (and (vlax-curve-getparamatpoint ent1 pt) (not (equal (vlax-curve-getparamatpoint ent1 pt) (vlax-curve-getstartparam ent1) 1e-5)) (not (equal (vlax-curve-getparamatpoint ent1 pt) (vlax-curve-getendparam ent1) 1e-5)) (or (<= (distance (vlax-curve-getstartpoint ent2) pt) fuzz) (<= (distance (vlax-curve-getendpoint ent2) pt) fuzz)))
  174.                 (add_vtx (vlax-ename->vla-object ent1) (vlax-curve-getparamatpoint ent1 pt) ent1)
  175.                 (cond
  176.                   ( (<= (distance (vlax-curve-getstartpoint ent2) pt) fuzz)
  177.                     (entupd (cdr (assoc -1 (entmod (subst (cons 10 (list (car pt) (cadr pt))) (assoc 10 (entget ent2)) (entget ent2))))))
  178.                   )
  179.                   ( (<= (distance (vlax-curve-getendpoint ent2) pt) fuzz)
  180.                     (entupd (cdr (assoc -1 (entmod (subst (cons 10 (list (car pt) (cadr pt))) (assoc 10 (reverse (entget ent2))) (entget ent2))))))
  181.                   )
  182.                 )
  183.               )
  184.               ( (and (vlax-curve-getparamatpoint ent2 pt) (not (equal (vlax-curve-getparamatpoint ent2 pt) (vlax-curve-getstartparam ent2) 1e-5)) (not (equal (vlax-curve-getparamatpoint ent2 pt) (vlax-curve-getendparam ent2) 1e-5)) (or (<= (distance (vlax-curve-getstartpoint ent1) pt) fuzz) (<= (distance (vlax-curve-getendpoint ent1) pt) fuzz)))
  185.                 (add_vtx (vlax-ename->vla-object ent2) (vlax-curve-getparamatpoint ent2 pt) ent2)
  186.                 (cond
  187.                   ( (<= (distance (vlax-curve-getstartpoint ent1) pt) fuzz)
  188.                     (entupd (cdr (assoc -1 (entmod (subst (cons 10 (list (car pt) (cadr pt))) (assoc 10 (entget ent1)) (entget ent1))))))
  189.                   )
  190.                   ( (<= (distance (vlax-curve-getendpoint ent1) pt) fuzz)
  191.                     (entupd (cdr (assoc -1 (entmod (subst (cons 10 (list (car pt) (cadr pt))) (assoc 10 (reverse (entget ent1))) (entget ent1))))))
  192.                   )
  193.                 )
  194.               )
  195.             )
  196.           )
  197.         )
  198.       )
  199.     )
  200.   )
  201.   (*error* nil)
  202. )
  203.  

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ziele_o2k

  • Newt
  • Posts: 49
Re: Make solid hatch from given plines
« Reply #16 on: July 06, 2016, 06:08:29 AM »
Hatching with splines boundary has big problems with displaying hatches (maybe not with SOLID but for exapmle with ANSI38 ) so I don't want to use _bpoly.
Problems occurs in most of cad programs (AutoCad; GstarCad; ZWCad).
Below my final version to extend/trim plines.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tee4 nil (PZ:FindPlinesToModify (ssget '((0 . "LWPOLYLINE")))))
  2. (defun PZ:FindPlinesToModify (ss / *error* PZ:ExtendPline EntLst tmpLst)
  3.   (defun *error* (msg / so)
  4.     (cond
  5.       ((not msg))
  6.       ((member msg '("Function cancelled" "quit / exit abort")))
  7.       (
  8.         (princ (strcat "\n  <!>  Error : " msg "  <!> "))
  9.         (cond (DebugMode (vl-bt)))
  10.       )
  11.     )  
  12.     (princ)
  13.   )
  14.   (defun PZ:ExtendPline ( lst / vla_lst pl_m vla_pl_s vla_pl_e tmpLine_s tmpLine_e pts eds pte ede )
  15.     (setq
  16.       vla_lst (mapcar 'vlax-ename->vla-object lst)
  17.       pl_m (car lst)
  18.       vla_pl_s (cadr vla_lst)
  19.       vla_pl_e (caddr vla_lst)
  20.     )
  21.     (setq
  22.       tmpLine_s
  23.       (cd:ACX_AddLine
  24.         (cd:ACX_ASpace)
  25.         nil
  26.       )
  27.       tmpLine_e
  28.       (cd:ACX_AddLine
  29.         (cd:ACX_ASpace)
  30.         nil
  31.       )
  32.     )
  33.     (cond
  34.       (
  35.         (eq (logand(cdr (assoc 70 (entget pl_m))) 1) 1);(eq (logand(cdr (assoc 70 (entget (car(entsel))))) 1) 1)
  36.         nil
  37.       );skip closed plines
  38.       (
  39.         (setq pts (car(LM:intersections tmpLine_s vla_pl_s acextendnone)))
  40.         (setq eds (subst (cons 10 (list (car pts) (cadr pts))) (assoc 10 (entget pl_m)) (entget pl_m)))
  41.       )
  42.       (
  43.         (setq pts
  44.           (caar
  45.             (vl-sort
  46.               (mapcar
  47.                 '(lambda (_1)
  48.                   (list _1 (distance _1 (vlax-curve-getPointAtParam pl_m (vlax-curve-getStartParam pl_m))))
  49.                 )
  50.                 (LM:intersections tmpLine_s vla_pl_s acextendthisentity)
  51.               )
  52.               (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))
  53.             )
  54.           )
  55.         )
  56.         (setq eds (subst (cons 10 (list (car pts) (cadr pts))) (assoc 10 (entget pl_m)) (entget pl_m)))
  57.       )
  58.     )
  59.     (entmod eds)
  60.     (cond
  61.       (
  62.         (eq (logand(cdr (assoc 70 (entget pl_m))) 1) 1)
  63.         nil
  64.       );skip closed plines
  65.       (
  66.         (setq pte (car(LM:intersections tmpLine_e vla_pl_e acextendnone)))
  67.         (setq ede (subst (cons 10 (list (car pte) (cadr pte))) (assoc 10 (reverse(entget pl_m))) (entget pl_m)))
  68.       )
  69.       (
  70.         (setq pte
  71.           (caar
  72.             (vl-sort
  73.               (mapcar
  74.                 '(lambda (_1)
  75.                   (list _1 (distance _1 (vlax-curve-getPointAtParam pl_m (vlax-curve-getEndParam pl_m))))
  76.                 )
  77.                 (LM:intersections tmpLine_e vla_pl_e acextendthisentity)
  78.               )
  79.               (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))
  80.             )
  81.           )
  82.         )
  83.         (setq ede (subst (cons 10 (list (car pte) (cadr pte))) (assoc 10 (reverse(entget pl_m))) (entget pl_m)))
  84.       )
  85.     )
  86.     (entmod ede)
  87.     (vla-Delete tmpLine_s)
  88.     (vla-Delete tmpLine_e)
  89.   )
  90.   (setq EntLst (LM:ss->ent ss))
  91.   (setq finalLst
  92.     (mapcar
  93.       '(lambda (_1)
  94.         (setq tmpLst
  95.           (list _1
  96.             (caar
  97.               (vl-sort
  98.                 (mapcar
  99.                   '(lambda (_2)
  100.                     (list
  101.                       ;_1
  102.                       _2
  103.                       (distance (vlax-curve-getClosestPointTo (vlax-ename->vla-object _2) (vlax-curve-getStartPoint _1)) (vlax-curve-getStartPoint _1))
  104.                     )
  105.                   )
  106.                   (LM:ListDifference EntLst (list _1))
  107.                 )
  108.                 (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))
  109.               )
  110.             )
  111.             (caar
  112.               (vl-sort
  113.                 (mapcar
  114.                   '(lambda (_2)
  115.                     (list
  116.                       ;_1
  117.                       _2
  118.                       (distance (vlax-curve-getClosestPointTo (vlax-ename->vla-object _2) (vlax-curve-getEndPoint _1)) (vlax-curve-getEndPoint _1))
  119.                     )
  120.                   )
  121.                   (LM:ListDifference EntLst (list _1))
  122.                 )
  123.                 (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))
  124.               )
  125.             )
  126.           )
  127.         )
  128.       )
  129.       EntLst
  130.     )
  131.   )
  132.   (foreach _n finalLst (PZ:ExtendPline _n))
  133.   (princ)
  134. )
  135. ;;-------------------=={ List Difference }==------------------;;
  136. ;;                                                            ;;
  137. ;;  Returns items appearing exclusively in one list but not   ;;
  138. ;;  another, i.e. the relative complement: l1 \ l2            ;;
  139. ;;------------------------------------------------------------;;
  140. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  141. ;;------------------------------------------------------------;;
  142. ;;  Arguments:                                                ;;
  143. ;;  l1,l2 - lists for which to return the difference          ;;
  144. ;;------------------------------------------------------------;;
  145. ;;  Returns:  List of items appearing exclusively in list l1  ;;
  146. ;;------------------------------------------------------------;;
  147. (defun LM:ListDifference ( l1 l2 )
  148.   (vl-remove-if '(lambda ( x ) (member x l2)) l1)
  149. )
  150. ;;--------------=={ SelectionSet -> Entities }==--------------;;
  151. ;;                                                            ;;
  152. ;;  Converts a SelectionSet to a list of Entities             ;;
  153. ;;------------------------------------------------------------;;
  154. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  155. ;;------------------------------------------------------------;;
  156. ;;  Arguments:                                                ;;
  157. ;;  ss - Valid SelectionSet (Pickset)                         ;;
  158. ;;------------------------------------------------------------;;
  159. ;;  Returns:  List of Entity names, else nil                  ;;
  160. ;;------------------------------------------------------------;;
  161. (defun LM:ss->ent ( ss / i l )
  162.     (if ss
  163.         (repeat (setq i (sslength ss))
  164.             (setq l (cons (ssname ss (setq i (1- i))) l))
  165.         )
  166.     )
  167. )
To run, please load CadPack functions from this post.

Thank you ribarm for help!