Author Topic: Move point perpendicular to line  (Read 190 times)

0 Members and 1 Guest are viewing this topic.

lkrkck

  • Mosquito
  • Posts: 2
Move point perpendicular to line
« on: September 12, 2017, 07:29:03 am »
Hello,

I've this code to move some AcadPoints tPerpendicular of one 2DPoliline.
The problem: I've this points with Z value, when i run the code this points goes perpendicular to line but with Z=0.

Code: [Select]
(defun c:SnapToObj ( / en obj pts_ss ss_len c pten ptobj pted pt pt2)
(setq en (car (entsel "\nSelect Object: ")))
(setq obj (vlax-ename->vla-object en))
(princ "\nSelect points: ")
(setq pts_ss (ssget (list (cons 0 "POINT"))))
(setq ss_len (sslength pts_ss))
(setq c 0)
(while (< c ss_len)
(setq pten (ssname pts_ss c))
(setq ptobj (vlax-ename->vla-object pten))
(setq pted (entget pten))
(setq pt (cdr (assoc 10 pted)))
(setq pt2 (vlax-curve-getClosestPointTo obj pt))
(vla-move ptobj (vlax-3d-point pt) (vlax-3d-point pt2))
(setq c (+ c 1))
)
(princ)
)


roy_043

  • Swamp Rat
  • Posts: 1493
  • BricsCAD 16

ronjonp

  • Needs a day job
  • Posts: 6403
Re: Move point perpendicular to line
« Reply #3 on: September 12, 2017, 09:20:59 am »
The point Z value should equal whatever elevation the polyline it is snapping to ?  Here's a quick one to retain the original Z value:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:s2o (/ e el p p2 s)
  2.  ;; RJP - 9/12/2017
  3.  (if (and (setq e (car (entsel "\nSelect Object: ")))
  4.   (princ "\nSelect points: ")
  5.   (setq s (ssget ":L" (list '(0 . "POINT"))))
  6.      )
  7.    (foreach pt (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  8.      (setq p (cdr (assoc 10 (setq el (entget pt)))))
  9.      (entmod (append el (list (cons 10 (list (car p2) (cadr p2) (caddr p))))))
  10.    )
  11.  )
  12.  (princ)
  13. )
« Last Edit: September 12, 2017, 09:26:32 am by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2018

Custom Build PC

lkrkck

  • Mosquito
  • Posts: 2
Re: Move point perpendicular to line
« Reply #4 on: September 12, 2017, 09:25:34 am »
Good Job ronjonp!
Thank you...

The point Z value should equal whatever elevation the polyline it is snapping to ?  Here's a quick one to retain the original Z value:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:s2o (/ e el p p2 s)
  2.  ;; RJP - 9/12/2017
  3.  (if (and (setq e (car (entsel "\nSelect Object: ")))
  4.   (princ "\nSelect points: ")
  5.   (setq s (ssget ":L" (list '(0 . "POINT"))))
  6.      )
  7.    (foreach pt (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  8.      (setq p (cdr (assoc 10 (setq el (entget pt)))))
  9.      (entmod (subst (cons 10 (list (car p2) (cadr p2) (caddr p))) (assoc 10 el) el))
  10.    )
  11.  )
  12.  (princ)
  13. )

ronjonp

  • Needs a day job
  • Posts: 6403
Re: Move point perpendicular to line
« Reply #5 on: September 12, 2017, 09:29:45 am »
Glad to help :) .. btw I updated the code above to make sure the object picked to snap to is actually a curve object.

Windows 10 x64 - AutoCAD /C3D 2018

Custom Build PC