Author Topic: Trim and Replace Line with One Pick  (Read 12337 times)

0 Members and 1 Guest are viewing this topic.

Pad

  • Bull Frog
  • Posts: 342
Re: Trim and Replace Line with One Pick
« Reply #15 on: September 26, 2013, 09:38:17 AM »
I cant get it to work on closed polylines

but let me know if this works any better:

Code - Auto/Visual Lisp: [Select]
  1. ;;
  2. ;;chlh_jd - http://www.theswamp.org/index.php?topic=40873.msg461337#msg461337
  3. ;;
  4. ;;20/09/13 Patrick Bourke 360geomatics.co.uk - modified to work with polylines
  5. ;;
  6.  
  7. (defun c:wt (/ e pt el l a b c p1 p2 p3 p4 p10 p11 oce pointlistb pointlistc)
  8. ;(defun c:wt (/)
  9.  
  10.   ;;trim and add new line for trim-space
  11.   ;; by GSLS(SS) 2012-2-9
  12.   (defun dxf (a l)
  13.     (cdr (assoc a l))
  14.   )
  15.   (defun mindis-pt (l pt)
  16.     (car
  17.       (vl-sort l
  18.                (function (lambda (e1 e2)
  19.                            (< (distance pt e1) (distance pt e2))
  20.                          )
  21.                )
  22.       )
  23.     )
  24.   )
  25.   (setq oce (getvar "cmdecho"))
  26.   (setvar "cmdecho" 0)
  27.   (setq e (entlast))
  28.   (prompt "Select a line :")
  29.   (command "Trim" "")  
  30.   (while (setq pt (entsel "\nSelect a line :"))
  31.     (command pt)    
  32.     (if (not (eq e (entlast)))
  33.       (progn
  34.         (setq e (entlast)
  35.               b   (entget (car pt))
  36.               c   (entget e)
  37.               PointListb (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) b))
  38.               PointListc (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) c))
  39.               p1  (car PointListb)
  40.               p2  (car (reverse PointListb))
  41.               p3  (car PointListc)
  42.               p4  (car (reverse PointListc))
  43. ;             p11 (mindis-pt (list p3 p4) p1)
  44. ;             p10 (mindis-pt (list p1 p2) p3)
  45.         )
  46. ;       (entmake
  47. ;         (list (cons 0 "LINE")
  48. ;               (cons 10 p10)
  49. ;               (cons 11 p11)
  50. ;               (cons 6 "DASHED");_LineType must be loaded
  51. ;               (cons 62 251)
  52.  
  53.  
  54.  
  55.         (entmake
  56.           (list (cons 0 "LINE") ;***
  57.                 (cons 6 "BYLAYER")
  58.                 (cons 8 "Walls")
  59.                 (cons 10 p2) ;***
  60.                 (cons 11 p3) ;***
  61.                 (cons 39 0.0)
  62.                 (cons 210 (list 0.0 0.0 1.0))
  63.           )
  64.         )
  65.         )
  66.       )    
  67.   )
  68.   (command "")
  69.  
  70.   (setvar "cmdecho" oce)
  71.   (princ)
  72. )

martinle

  • Newt
  • Posts: 22
Re: Trim and Replace Line with One Pick
« Reply #16 on: September 27, 2013, 12:26:09 AM »
Hello pad!

Thanks for your help.
It works with the neck of the polyline. There is no line, but then pulled the Dashed linetype.
Why is that?

Greetings Martin

Pad

  • Bull Frog
  • Posts: 342
Re: Trim and Replace Line with One Pick
« Reply #17 on: September 27, 2013, 12:56:19 PM »
for the dashed line type just change lines 46 to 62 to this:

Code - Auto/Visual Lisp: [Select]
  1.   (list (cons 0 "LINE")
  2.  (cons 10 p10)
  3.  (cons 11 p11)
  4.  (cons 6 "DASHED");_LineType must be loaded
  5.  (cons 62 251)
  6.  
  7.  
  8.  
  9. ;       (entmake
  10. ;        (list (cons 0 "LINE") ;***
  11. ;               (cons 6 "BYLAYER")
  12. ;               (cons 8 "Walls")
  13. ;               (cons 10 p2) ;***
  14. ;               (cons 11 p3) ;***
  15. ;               (cons 39 0.0)
  16. ;              (cons 210 (list 0.0 0.0 1.0))

Peter2

  • Swamp Rat
  • Posts: 650
Re: Trim and Replace Line with One Pick
« Reply #18 on: January 13, 2014, 09:54:55 AM »

Code - Auto/Visual Lisp: [Select]
  1. ;;
  2. ...
  3.               PointListb (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) b))
  4.               PointListc (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) c))
  5. ...
  6.  
Hi Patrick
at the moment I have no idea what's the algorithm behind these lines. If you have a little bit of time it would be great if you add some comments to your code  :-D

Thanks
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Trim and Replace Line with One Pick
« Reply #19 on: January 14, 2014, 03:44:34 PM »
Code - Auto/Visual Lisp: [Select]
  1.               PointListb (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) b))
  2.               PointListc (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) c))
If you have a little bit of time it would be great if you add some comments to your code  :-D

Assuming variables 'b' & 'c' point to DXF data for an LWPolyline entity, the above expressions will return a list of vertices for the polylines described by the supplied DXF data lists.

You can see this by stepping through the expressions one expression at a time:

In the following example, assume that the variable 'elist' contains the following LWPolyline DXF data:
Code - Auto/Visual Lisp: [Select]
  1. (
  2.   (-1 . <Entity name: 7ef03b88>)
  3.   (0 . "LWPOLYLINE")
  4.   (330 . <Entity name: 7ef01cf8>)
  5.   (5 . "359")
  6.   (100 . "AcDbEntity")
  7.   (67 . 0)
  8.   (410 . "Model")
  9.   (8 . "0")
  10.   (100 . "AcDbPolyline")
  11.   (90 . 4)
  12.   (70 . 0)
  13.   (43 . 0.0)
  14.   (38 . 0.0)
  15.   (39 . 0.0)
  16.   (10 17.3428 14.1773)
  17.   (40 . 0.0)
  18.   (41 . 0.0)
  19.   (42 . 0.0)
  20.   (91 . 0)
  21.   (10 19.951 16.9304)
  22.   (40 . 0.0)
  23.   (41 . 0.0)
  24.   (42 . 0.0)
  25.   (91 . 0)
  26.   (10 23.6196 14.0079)
  27.   (40 . 0.0)
  28.   (41 . 0.0)
  29.   (42 . 0.0)
  30.   (91 . 0)
  31.   (10 26.652 17.0151)
  32.   (40 . 0.0)
  33.   (41 . 0.0)
  34.   (42 . 0.0)
  35.   (91 . 0)
  36.   (210 0.0 0.0 1.0)
  37. )

Evaluating the vl-remove-if-not expression leaves only the DXF group 10 entries (you can read this literally from the expression: "remove if the first element of each list item is not equal to 10"):
Code - Auto/Visual Lisp: [Select]
  1. _$ (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) elist)
  2. (
  3.   (10 17.3428 14.1773)
  4.   (10 19.951 16.9304)
  5.   (10 23.6196 14.0079)
  6.   (10 26.652 17.0151)
  7. )

Now, the mapcar expression evaluates the cdr function on each of these DXF group 10 items, returning each list with the first item (the DXF group code) removed, thus returning the vertex coordinates:
Code - Auto/Visual Lisp: [Select]
  1. _$ (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) elist))
  2. (
  3.   (17.3428 14.1773)
  4.   (19.951 16.9304)
  5.   (23.6196 14.0079)
  6.   (26.652 17.0151)
  7. )

Peter2

  • Swamp Rat
  • Posts: 650
Re: Trim and Replace Line with One Pick
« Reply #20 on: January 16, 2014, 01:24:28 PM »
Thanks Lee

now I have a good base to study it (and later the rest of the code ..).
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Trim and Replace Line with One Pick
« Reply #21 on: January 16, 2014, 06:07:16 PM »
Thanks Lee

now I have a good base to study it (and later the rest of the code ..).

Excellent - you're welcome  :-)