Author Topic: Trace polyline  (Read 1727 times)

0 Members and 1 Guest are viewing this topic.

blahdc

  • Mosquito
  • Posts: 2
Trace polyline
« on: December 16, 2017, 10:12:30 PM »
Hi All,

Is there any command or LSP that would allow me to trace a polyline. I would like it to ask which vertex to start at and which vertex to end at. It would then create a new polyline from those two locations. Bonus would be to allow me to continue drawing the polyline. Anything out there that would do this?

Thanks

Lee Mac

  • Seagull
  • Posts: 12671
  • London, England
Re: Trace polyline
« Reply #1 on: December 17, 2017, 05:38:01 AM »
You can use this and comment lines 131-133.

ribarm

  • Gator
  • Posts: 2701
  • Marko Ribar, architect
Re: Trace polyline
« Reply #2 on: December 17, 2017, 03:24:17 PM »
Try this (open and not splined POLYLINES... :( ) :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tracepline ( / s sp ep spar epar dxf70 pl lw par )
  2.  
  3.  
  4.   (prompt "\nPick OPEN 2d or 3d POLYLINE...")
  5.   (setq s (ssget "_+.:E:S" '((0 . "*POLYLINE") (-4 . "<not") (-4 . "&") (70 . 1) (-4 . "not>"))))
  6.   (if s
  7.     (progn
  8.       (setq sp (getpoint "\nPick or specify start point on selected POLYLINE : "))
  9.       (setq ep (getpoint "\nPick or specify end point on selected POLYLINE : "))
  10.       (if (or (not (setq spar (vlax-curve-getparamatpoint (ssname s 0) (trans sp 1 0)))) (not (setq epar (vlax-curve-getparamatpoint (ssname s 0) (trans ep 1 0)))))
  11.         (progn
  12.           (prompt "\nPicked or specified point(s) don't belong to selected POLYLINE... Quitting...")
  13.           (exit)
  14.         )
  15.       )
  16.       (cond
  17.         ( (= (cdr (assoc 0 (entget (ssname s 0)))) "LWPOLYLINE")
  18.           (if (< epar spar)
  19.             (progn
  20.               (vl-cmdf "_.REVERSE" (ssname s 0) "")
  21.               (setq spar (vlax-curve-getparamatpoint (ssname s 0) (trans sp 1 0)) epar (vlax-curve-getparamatpoint (ssname s 0) (trans ep 1 0)))
  22.               (setq par (1+ (fix spar)))
  23.               (vl-cmdf "_.PLINE")
  24.               (vl-cmdf "_non" sp)
  25.               (while (< par epar)
  26.                 (if (/= (vla-getbulge (vlax-ename->vla-object (ssname s 0)) (1- par)) 0.0)
  27.                   (progn
  28.                     (vl-cmdf "_A" "_S" "_non" (trans (vlax-curve-getpointatparam (ssname s 0) (- par 1e-3)) 0 1))
  29.                     (vl-cmdf "_non" (trans (vlax-curve-getpointatparam (ssname s 0) par) 0 1) "_LI")
  30.                   )
  31.                   (vl-cmdf "_non" (trans (vlax-curve-getpointatparam (ssname s 0) par) 0 1))
  32.                 )
  33.                 (setq par (1+ par))
  34.               )
  35.               (if (/= (vla-getbulge (vlax-ename->vla-object (ssname s 0)) (1- epar)) 0.0)
  36.                 (progn
  37.                   (vl-cmdf "_A" "_S" "_non" (trans (vlax-curve-getpointatparam (ssname s 0) (- epar 1e-3)) 0 1))
  38.                   (vl-cmdf "_non" (trans (vlax-curve-getpointatparam (ssname s 0) epar) 0 1))
  39.                 )
  40.                 (vl-cmdf "_non" (trans (vlax-curve-getpointatparam (ssname s 0) epar) 0 1))
  41.               )
  42.               (while (< 0 (getvar 'cmdactive)) (vl-cmdf "\\"))
  43.               (vl-cmdf "_.REVERSE" (ssname s 0) "")
  44.             )
  45.             (progn
  46.               (setq par (1+ (fix spar)))
  47.               (vl-cmdf "_.PLINE")
  48.               (vl-cmdf "_non" sp)
  49.               (while (< par epar)
  50.                 (if (/= (vla-getbulge (vlax-ename->vla-object (ssname s 0)) (1- par)) 0.0)
  51.                   (progn
  52.                     (vl-cmdf "_A" "_S" "_non" (trans (vlax-curve-getpointatparam (ssname s 0) (- par 1e-3)) 0 1))
  53.                     (vl-cmdf "_non" (trans (vlax-curve-getpointatparam (ssname s 0) par) 0 1) "_LI")
  54.                   )
  55.                   (vl-cmdf "_non" (trans (vlax-curve-getpointatparam (ssname s 0) par) 0 1))
  56.                 )
  57.                 (setq par (1+ par))
  58.               )
  59.               (if (/= (vla-getbulge (vlax-ename->vla-object (ssname s 0)) (1- epar)) 0.0)
  60.                 (progn
  61.                   (vl-cmdf "_A" "_S" "_non" (trans (vlax-curve-getpointatparam (ssname s 0) (- epar 1e-3)) 0 1))
  62.                   (vl-cmdf "_non" (trans (vlax-curve-getpointatparam (ssname s 0) epar) 0 1))
  63.                 )
  64.                 (vl-cmdf "_non" (trans (vlax-curve-getpointatparam (ssname s 0) epar) 0 1))
  65.               )
  66.               (while (< 0 (getvar 'cmdactive)) (vl-cmdf "\\"))
  67.             )
  68.           )
  69.         )
  70.         ( (= (cdr (assoc 100 (reverse (entget (ssname s 0))))) "AcDb2dPolyline")
  71.           (setq dxf70 (cdr (assoc 70 (entget (ssname s 0)))))
  72.           (if (not (or (= 0 dxf70) (= 2 dxf70) (= 128 dxf70) (= 130 dxf70)))
  73.             (progn
  74.               (prompt "\nPicked old heavy 2d POLYLINE is splined and tracing not supported... Quitting...")
  75.               (exit)
  76.             )
  77.           )
  78.           (setq pl (vlax-vla-object->ename (vla-copy (vlax-ename->vla-object (ssname s 0)))))
  79.           (vl-cmdf "_.EXPLODE" pl)
  80.           (while (< 0 (getvar 'cmdactive)) (vl-cmdf ""))
  81.           (if (= (getvar 'peditaccept) 1)
  82.             (progn
  83.               (vl-cmdf "_.PEDIT" "_M" (ssget "_P") "" "_J")
  84.               (while (< 0 (getvar 'cmdactive)) (vl-cmdf ""))
  85.             )
  86.             (progn
  87.               (vl-cmdf "_.PEDIT" "_M" (ssget "_P") "" "_Y" "_J")
  88.               (while (< 0 (getvar 'cmdactive)) (vl-cmdf ""))
  89.             )
  90.           )
  91.           (setq lw (entlast))
  92.           (setq spar (vlax-curve-getparamatpoint lw (trans sp 1 0)) epar (vlax-curve-getparamatpoint lw (trans ep 1 0)))
  93.           (if (or (= 0 dxf70) (= 128 dxf70))
  94.             (progn
  95.               (if (< epar spar)
  96.                 (progn
  97.                   (vl-cmdf "_.REVERSE" lw "")
  98.                   (setq spar (vlax-curve-getparamatpoint lw (trans sp 1 0)) epar (vlax-curve-getparamatpoint lw (trans ep 1 0)))
  99.                   (setq par (1+ (fix spar)))
  100.                   (vl-cmdf "_.PLINE")
  101.                   (vl-cmdf "_non" sp)
  102.                   (while (< par epar)
  103.                     (if (/= (vla-getbulge (vlax-ename->vla-object lw) (1- par)) 0.0)
  104.                       (progn
  105.                         (vl-cmdf "_A" "_S" "_non" (trans (vlax-curve-getpointatparam lw (- par 1e-3)) 0 1))
  106.                         (vl-cmdf "_non" (trans (vlax-curve-getpointatparam lw par) 0 1) "_LI")
  107.                       )
  108.                       (vl-cmdf "_non" (trans (vlax-curve-getpointatparam lw par) 0 1))
  109.                     )
  110.                     (setq par (1+ par))
  111.                   )
  112.                   (if (/= (vla-getbulge (vlax-ename->vla-object lw) (1- epar)) 0.0)
  113.                     (progn
  114.                       (vl-cmdf "_A" "_S" "_non" (trans (vlax-curve-getpointatparam lw (- epar 1e-3)) 0 1))
  115.                       (vl-cmdf "_non" (trans (vlax-curve-getpointatparam lw epar) 0 1))
  116.                     )
  117.                     (vl-cmdf "_non" (trans (vlax-curve-getpointatparam lw epar) 0 1))
  118.                   )
  119.                   (while (< 0 (getvar 'cmdactive)) (vl-cmdf "\\"))
  120.                   (vl-cmdf "_.REVERSE" lw "")
  121.                 )
  122.                 (progn
  123.                   (setq par (1+ (fix spar)))
  124.                   (vl-cmdf "_.PLINE")
  125.                   (vl-cmdf "_non" sp)
  126.                   (while (< par epar)
  127.                     (if (/= (vla-getbulge (vlax-ename->vla-object lw) (1- par)) 0.0)
  128.                       (progn
  129.                         (vl-cmdf "_A" "_S" "_non" (trans (vlax-curve-getpointatparam lw (- par 1e-3)) 0 1))
  130.                         (vl-cmdf "_non" (trans (vlax-curve-getpointatparam lw par) 0 1) "_LI")
  131.                       )
  132.                       (vl-cmdf "_non" (trans (vlax-curve-getpointatparam lw par) 0 1))
  133.                     )
  134.                     (setq par (1+ par))
  135.                   )
  136.                   (if (/= (vla-getbulge (vlax-ename->vla-object lw) (1- epar)) 0.0)
  137.                     (progn
  138.                       (vl-cmdf "_A" "_S" "_non" (trans (vlax-curve-getpointatparam lw (- epar 1e-3)) 0 1))
  139.                       (vl-cmdf "_non" (trans (vlax-curve-getpointatparam lw epar) 0 1))
  140.                     )
  141.                     (vl-cmdf "_non" (trans (vlax-curve-getpointatparam lw epar) 0 1))
  142.                   )
  143.                   (while (< 0 (getvar 'cmdactive)) (vl-cmdf "\\"))
  144.                 )
  145.               )
  146.             )
  147.             (progn
  148.               (if (< epar spar)
  149.                 (progn
  150.                   (vl-cmdf "_.REVERSE" lw "")
  151.                   (setq spar (vlax-curve-getparamatpoint lw (trans sp 1 0)) epar (vlax-curve-getparamatpoint lw (trans ep 1 0)))
  152.                   (setq par (1+ (fix spar)))
  153.                   (vl-cmdf "_.PLINE")
  154.                   (vl-cmdf "_non" sp "_A")
  155.                   (while (< par epar)
  156.                     (vl-cmdf "_S" "_non" (trans (vlax-curve-getpointatparam lw (- par 1e-3)) 0 1))
  157.                     (vl-cmdf "_non" (trans (vlax-curve-getpointatparam lw par) 0 1))
  158.                     (setq par (1+ par))
  159.                   )
  160.                   (vl-cmdf "_S" "_non" (trans (vlax-curve-getpointatparam lw (- epar 1e-3)) 0 1))
  161.                   (vl-cmdf "_non" (trans (vlax-curve-getpointatparam lw epar) 0 1))
  162.                   (while (< 0 (getvar 'cmdactive)) (vl-cmdf "\\"))
  163.                   (vl-cmdf "_.REVERSE" (ssname s 0) "")
  164.                 )
  165.                 (progn
  166.                   (setq par (1+ (fix spar)))
  167.                   (vl-cmdf "_.PLINE")
  168.                   (vl-cmdf "_non" sp "_A")
  169.                   (while (< par epar)
  170.                     (vl-cmdf "_S" "_non" (trans (vlax-curve-getpointatparam lw (- par 1e-3)) 0 1))
  171.                     (vl-cmdf "_non" (trans (vlax-curve-getpointatparam lw par) 0 1))
  172.                     (setq par (1+ par))
  173.                   )
  174.                   (vl-cmdf "_S" "_non" (trans (vlax-curve-getpointatparam lw (- epar 1e-3)) 0 1))
  175.                   (vl-cmdf "_non" (trans (vlax-curve-getpointatparam lw epar) 0 1))
  176.                   (while (< 0 (getvar 'cmdactive)) (vl-cmdf "\\"))
  177.                 )
  178.               )
  179.             )
  180.           )
  181.           (entdel lw)
  182.         )
  183.         ( (= (cdr (assoc 100 (reverse (entget (ssname s 0))))) "AcDb3dPolyline")
  184.           (if (< epar spar)
  185.             (progn
  186.               (vl-cmdf "_.REVERSE" (ssname s 0) "")
  187.               (setq spar (vlax-curve-getparamatpoint (ssname s 0) (trans sp 1 0)) epar (vlax-curve-getparamatpoint (ssname s 0) (trans ep 1 0)))
  188.               (setq par (1+ (fix spar)))
  189.               (vl-cmdf "_.3DPOLY")
  190.               (vl-cmdf "_non" sp)
  191.               (while (< par epar)
  192.                 (vl-cmdf "_non" (trans (vlax-curve-getpointatparam (ssname s 0) par) 0 1))
  193.                 (setq par (1+ par))
  194.               )
  195.               (vl-cmdf "_non" (trans (vlax-curve-getpointatparam (ssname s 0) epar) 0 1))
  196.               (while (< 0 (getvar 'cmdactive)) (vl-cmdf "\\"))
  197.               (vl-cmdf "_.REVERSE" (ssname s 0) "")
  198.             )
  199.             (progn
  200.               (setq par (1+ (fix spar)))
  201.               (vl-cmdf "_.3DPOLY")
  202.               (vl-cmdf "_non" sp)
  203.               (while (< par epar)
  204.                 (vl-cmdf "_non" (trans (vlax-curve-getpointatparam (ssname s 0) par) 0 1))
  205.                 (setq par (1+ par))
  206.               )
  207.               (vl-cmdf "_non" (trans (vlax-curve-getpointatparam (ssname s 0) epar) 0 1))
  208.               (while (< 0 (getvar 'cmdactive)) (vl-cmdf "\\"))
  209.             )
  210.           )
  211.         )
  212.       )
  213.     )
  214.   )
  215.   (princ)
  216. )
  217.  

Regards, M.R.
« Last Edit: December 17, 2017, 03:43:29 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

blahdc

  • Mosquito
  • Posts: 2
Re: Trace polyline
« Reply #3 on: December 18, 2017, 03:05:30 PM »
Thanks guys! Exactly what I was looking for.

Batil

  • Mosquito
  • Posts: 1
Re: Trace polyline
« Reply #4 on: March 08, 2021, 09:14:24 PM »
Hello and good day! Would this be possible with multiple polylines?

User input would be:
1. Pick 1st point
2. Pick 2nd point
3. Select polylines (some polylines may have a bulge)

Please see photo for reference. Thanks!


BIGAL

  • Swamp Rat
  • Posts: 989
  • 40 + years of using Autocad
Re: Trace polyline
« Reply #5 on: March 09, 2021, 11:13:33 PM »
Suggestion made over at Cadtutor. Set osmode to 544 then just pick points so fast no need for code probably same amount of picks.
A man who never made a mistake never made anything

ribarm

  • Gator
  • Posts: 2701
  • Marko Ribar, architect
Re: Trace polyline
« Reply #6 on: June 28, 2022, 12:26:17 AM »
Polyline trace, much better, but trace for tracing !!! <<<
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube