LISP Code for drawing perpendicular lines individually for the selected polyline from the selected set of points. so finally number points in the selection is equal to the number of lines generated.

LISP Code for drawing perpendicular lines individually for the selected polyline from the selected set of points. so finally number points in the selection is equal to the number of lines generated.

pankaj
Contributor Contributor
1,242 Views
3 Replies
Message 1 of 4

LISP Code for drawing perpendicular lines individually for the selected polyline from the selected set of points. so finally number points in the selection is equal to the number of lines generated.

pankaj
Contributor
Contributor

Hello Everyone,
I am Pankaj. I am Civil Engineer not from Programming background with lot of exploring mindset the below LISP code was drafted by me with the help of few open source knowledge and few debugging and correction process with the help of ChatGPT for drawing perpendicular lines to the selected polyline from the selected points. 

 

(defun c:DLPP ()
;DLPP-Draw perpendicular lines for the selected polyline from the selected points
  (setq poly (car (nentsel "\nSelect polyline: ")))
  (setq poly-obj (vlax-ename->vla-object poly))

  (setq ss (ssget "_:L" '((0 . "POINT"))))
  (setq points (list))
  
  (if ss
    (progn
      (setq numPoints (sslength ss))
      (setq i 0)
      (while (< i numPoints)
        (setq pt (cdr (assoc 10 (entget (ssname ss i)))))
        (setq points (cons pt points))
        (setq i (1+ i))
      )
    )
  )

  (foreach pt points
    (setq perp-point (vlax-curve-getClosestPointTo poly-obj pt))
    (command "line" pt perp-point "")
  )

  (princ)
)

 

 I am not sure what is the problem with this code i have tried all the possible debugging process but the perpendicular lines drawing process works only in few versions of the Autocad.
I am Using AUTOCAD 2024 in which it works as per my requirement.
But in another PC AUTOCAD 2023 in which certain start points are not taken correctly and it takes vertexes and mid between two vertexes as the start point which is resulting in not meeting the requirement.

Please help me out with my code debugging process.
If needed please suggest me with the new approach of this LISP code for my idea of DLPP-Drawing Perpendicular lines for the selected polyline from the selected points.

Thanks in Advance,
regards,
Pankaj

0 Likes
Accepted solutions (1)
1,243 Views
3 Replies
Replies (3)
Message 2 of 4

cadffm
Consultant
Consultant
Accepted solution

Hi,

 

2023<>2024

Different setting? Check your osnapcoord

 

But you can also edit your code:

(command "line" "non" pt "non" perp-point "")

Sebastian

0 Likes
Message 3 of 4

pankaj
Contributor
Contributor
Thanks for you quick response.
I have checked as per suggestion "OSNAPCOORD" Both the Autocad versions has 2 as its value
Anyhow it had now worked in the both the versions with your modification line.
Thanks once again for your support.
0 Likes
Message 4 of 4

cadffm
Consultant
Consultant

"Both the Autocad versions has 2 as its value"

 

In this case, you just had luck that it worked well, dependend on the current view!!!

 (Pan/Zoom).

 

So it was also possible that it run fine in 2023, but not in your 2024,

Coincidence.

Osnapcoord=2 means: Your activated  running osnaps are ignored for (real)keyboard input, but is used for automated input - like script macro or (send)commands

 

I changed the command-statement 2x to not use osnaps for the next coordinate input

 

 

Sebastian

0 Likes