### 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
##### Re: Move point perpendicular to line
« Reply #1 on: September 12, 2017, 09:14:01 am »

#### roy_043

• Swamp Rat
• Posts: 1493
##### Re: Move point perpendicular to line
« Reply #2 on: September 12, 2017, 09:15:57 am »

#### 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]
`(defun c:s2o (/ e el p p2 s)  ;; RJP - 9/12/2017  (if (and (setq e (car (entsel "\nSelect Object: ")))	   (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getendparam (list e))))	   (princ "\nSelect points: ")	   (setq s (ssget ":L" (list '(0 . "POINT"))))      )    (foreach pt	(vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))      (setq p (cdr (assoc 10 (setq el (entget pt)))))      (setq p2 (vlax-curve-getclosestpointto e p))      (entmod (append el (list (cons 10 (list (car p2) (cadr p2) (caddr p))))))    )  )  (princ))`
« 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]
`(defun c:s2o (/ e el p p2 s)  ;; RJP - 9/12/2017  (if (and (setq e (car (entsel "\nSelect Object: ")))	   (princ "\nSelect points: ")	   (setq s (ssget ":L" (list '(0 . "POINT"))))      )    (foreach pt	(vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))      (setq p (cdr (assoc 10 (setq el (entget pt)))))      (setq p2 (vlax-curve-getclosestpointto e p))      (entmod (subst (cons 10 (list (car p2) (cadr p2) (caddr p))) (assoc 10 el) el))    )  )  (princ))`

#### 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