Jump to content

LISP Code to Draw A Line Perpendicular to Another Line


Bill Tillman

Recommended Posts

I created the attached file with a LISP program to draw a stair stringer. I've been trying to figure out how to add the dimension shown which will be the overall length of the stringer.

 

When I do this manually, I create a short line from the bottom of the stringer perpendicular to the top line of the stringer, then DIMALIGN from the two outer points. When I try to draw the short line segment I keep hitting a block.

(command "._LINE" spt5 "per" spt1

I've also drawn a temporary line between spt1 and spt2 along the top line and tried to use it as the target for perpendicularity but it just doesn't come together like I was hoping.

PerDimLisp.dwg

Link to comment
Share on other sites

I came up with a method for this using a little trig, but was wondering if there were any other bright ideas on how to do this out there.

Link to comment
Share on other sites

Some example:

(and
 (setq p1 (getpoint "\nFirst point"))
 (setq p2 (getpoint p1 "\nSecond point"))
 (progn
   (redraw)
   (grdraw p1 p2 1)                ; draw your line in red
   (grdraw                         ; draw the perpendicular line in yellow
     p1                            ; starting from p1
     (polar                        ; calculate the 2nd point
       p1                          ; starting from p1
       (+ (angle p1 p2) (/ PI 2.)) ; perpendicular angle, Pi/2 = 90 deg
       (distance p1 p2)            ; distance, same as the original line
     ); polar
     2
   ); grdraw
 ); progn 
); and

Link to comment
Share on other sites

BIGAL is right, using vlax-curve-getClosestPointTo is easier and avoids calculating the angles (when you already have drawn the line).

To visualise the result, using grread :

(defun C:test ( / e grr Stop )
 (if (setq e (car (entsel "\nSelect line, or curve: ")))
   (while (not Stop)
     (setq grr (grread T))
     (cond
       ( (= (car grr) 25) (setq Stop T) )
       ( (= (car grr) 5) (redraw) (grdraw (cadr grr) (vlax-curve-getClosestPointTo e (cadr grr) T) 2) )
       ( (= (car grr) 3) 
         (entmakex 
           (list (cons 0 "LINE") (cons 10 (cadr grr)) (cons 11 (vlax-curve-getClosestPointTo e (cadr grr) T)) )
         )
         (setq Stop T)
       )
     ); cond			
   ); while
 ); if
 (princ)
); defun

Link to comment
Share on other sites

Rotate the UCS to the Object, dimension, change UCS back to World. I have UO set up for UCS, Object. And UW set up for UCS, World. Very quick and easy, I find uses for those all the time. I have listed a few of the ones I have set up in my personal quick keys.lsp.

 

(DEFUN C:UO ()  (SETVAR "CMDECHO" 0)(COMMAND ".UCS" "OBJECT")(PRIN1))
(DEFUN C:UR ()  (SETVAR "CMDECHO" 0)(COMMAND ".UCS" "RIGHT")(PRIN1))
(DEFUN C:UT ()  (SETVAR "CMDECHO" 0)(COMMAND ".UCS" "TOP")(PRIN1))
(DEFUN C:UV ()  (SETVAR "CMDECHO" 0)(COMMAND ".UCS" "VIEW")(PRIN1))
(DEFUN C:UW ()  (SETVAR "CMDECHO" 0)(COMMAND ".UCS" "WORLD")(PRIN1))

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...