Author Topic: Perpendicular Points to Another Polyline  (Read 1451 times)

0 Members and 1 Guest are viewing this topic.

rodolfo_palma

  • Mosquito
  • Posts: 5
Perpendicular Points to Another Polyline
« on: September 21, 2020, 12:59:58 PM »
Hello everyone,

I need help to find the best method to do the following:
I have a list of points along a polyline. I also have a second polyline.
I want to orthogonally project my list of points to this second polyline.

The attached image helps to visualize the problem:
- Red points: the existing list of points;
- Pink points: the desired list of points;

Thanks!
Rodolfo Palma.

HOSNEYALAA

  • Newt
  • Posts: 103
Re: Perpendicular Points to Another Polyline
« Reply #1 on: September 21, 2020, 03:14:27 PM »
Code: [Select]
;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vertical-lines-between-two-poly-line-points/td-p/8894065


(defun c:vline (/ *error* c_doc ms e_obj f_obj ent ans cnt e_p s_pt e_pt x_obj i_pt)

  (defun *error* ( msg )
    (mapcar 'setvar sv_lst sv_vals)
    (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
    (princ)
  );_end_*error*_defun
 
  (setq sv_lst (list 'cmdecho 'osmode)
        sv_vals (mapcar 'getvar sv_lst)
        c_doc (vla-get-activedocument (vlax-get-acad-object))
        ms (vla-get-modelspace c_doc)
        e_obj (vlax-ename->vla-object (car (entsel "\nSelect Extents Polyline : ")))
        f_obj (vlax-ename->vla-object (setq ent (car (entsel "\nSelect From Polyline : "))))
  );end_setq
 
  (initget "All Select")
  (setq ans (cond ( (getkword "\nLine from All Vertices of Polyline or Selected Points [All/Select] <All> : ")) ("All")))
 
  (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
  (vla-startundomark c_doc)
 
  (cond ( (= ans "All")
          (setq cnt 1.0
                e_p (vlax-curve-getendparam ent)
          );end_setq
          (while (< 0.0 cnt e_p)
            (setq s_pt (vlax-curve-getpointatparam ent cnt)
                  e_pt (mapcar '+ s_pt (list 0.0 1.0 0.0))
                  x_obj (vla-addray ms (vlax-3D-point s_pt) (vlax-3D-point e_pt))
                  i_pt (vlax-invoke x_obj 'intersectwith e_obj acextendnone)
                  cnt (1+ cnt)
            );end_setq
            (cond (i_pt (setq l_obj (vla-addline ms (vlax-3d-point s_pt) (vlax-3d-point i_pt)))))
            (vla-delete x_obj)
          );end_while
        )
        (t
          (mapcar 'setvar sv_lst (list 0 545))
          (while (setq s_pt (getpoint "\nSelect Line Start Point : "))
            (cond ( (not (equal 0.0 (distance s_pt (vlax-curve-getclosestpointto ent s_pt)) 0.001))
                    (setq e_pt (mapcar '+ s_pt (list 0.0 -1.0 0.0))
                          x_obj (vla-addray ms (vlax-3D-point s_pt) (vlax-3D-point e_pt))
                          i_pt (vlax-invoke x_obj 'intersectwith f_obj acextendnone)
                    );end_setq
                  )
                  (t
                    (setq e_pt (mapcar '+ s_pt (list 0.0 1.0 0.0))
                          x_obj (vla-addray ms (vlax-3D-point s_pt) (vlax-3D-point e_pt))
                          i_pt (vlax-invoke x_obj 'intersectwith e_obj acextendnone)
                    );end_setq
                  )
            );end_cond
            (cond (i_pt (setq l_obj (vla-addline ms (vlax-3d-point s_pt) (vlax-3d-point i_pt)))))
            (vla-delete x_obj)
          );end_while
        )
  );end_cond
 
  (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
  (mapcar 'setvar sv_lst sv_vals)
);end_defun 
 



HOSNEYALAA

  • Newt
  • Posts: 103
Re: Perpendicular Points to Another Polyline
« Reply #2 on: September 21, 2020, 03:18:00 PM »
hi

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: Perpendicular Points to Another Polyline
« Reply #3 on: September 21, 2020, 07:06:20 PM »
The obvious 3rd option is the extra points at fixed interval.
A man who never made a mistake never made anything

HOSNEYALAA

  • Newt
  • Posts: 103
Re: Perpendicular Points to Another Polyline
« Reply #4 on: September 22, 2020, 03:33:44 AM »
yes  BIGAL

For better understanding, and, maybe, get further help, please upload such sample.dwg

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: Perpendicular Points to Another Polyline
« Reply #5 on: September 22, 2020, 08:08:55 PM »
Suggested that as an option to your code. Have more than enough solutions already 40 years with cad.
A man who never made a mistake never made anything

HOSNEYALAA

  • Newt
  • Posts: 103
Re: Perpendicular Points to Another Polyline
« Reply #6 on: September 24, 2020, 02:51:18 AM »
HI BIGAL

Thank you
I did not write the LISP, I copied it from the address above
;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vertical-lines-between-two-poly-line-points/td-p/8894065

I don't have enough experience
I follow you as you write from the LISP
I learn from you