Jump to content

Auto lisp routine to bisect a line and draw a line perpendicular from midpoint


rvalusa22

Recommended Posts

Hello All,

 

I need to bisect a line and draw a line perpendicular from mid point and with user defined length using AUTO LISP routine? Your help is very much appreciated.

 

Thanks

rajesh

Link to comment
Share on other sites

This?

 

(defun c:Test (/ l s e 1p 2p 3p ang c g)
 ;; Tharwat 23.Dec.2015 ;;
 (if (and (setq l (getdist "\nSpecify length of line :"))
          (setq s (car (entsel "\nSelect Line :")))
          (eq (cdr (assoc 0 (setq e (entget s)))) "LINE")
          (setq 1p  (cdr (assoc 10 e))
                2p  (cdr (assoc 11 e))
                ang (angle 1p 2p)
                c   (mapcar '(lambda (q p) (/ (+ q p) 2.)) 1p 2p)
          )
          (princ "\nSpecify distination :")
     )
   (progn
     (while (eq 5 (car (setq g (grread t 13 0))))
       (redraw)
       (grdraw c
               (setq 3p
                      (polar c
                             (apply (if (> 0 (sin (- ang (angle 1p (cadr g)))))
                                      '+
                                      '-
                                    )
                                    (list ang (* pi 0.5))
                             )
                             l
                      )
               )
               -1
               0
       )
     )
     (if (member (car g) '(2 3 25))
       (entmake
         (list '(0 . "LINE") (cons 10 c) (cons 11 3p))
       )
     )
   )
 )
 (redraw)
 (princ)
)

Link to comment
Share on other sites

  • 9 months later...

Read Lee Mac's post just above yours and then go to the thread he indicates and try his first code. I think it will work fine as long as your polylines have only 2 vertices.

Link to comment
Share on other sites

Read Lee Mac's post just above yours and then go to the thread he indicates and try his first code. I think it will work fine as long as your polylines have only 2 vertices.

 

BKT there are ways of picking a section of a pline, so in this case this would give the answer of between 2 points. Lee ?

 

Here is a modified version compatible with both lines & 2D polylines:

(defun c:per ( / ent enx par pt1 pt2 sel )
   (while
       (progn (setvar 'errno 0) (setq sel (entsel "\nSelect line or polyline segment: "))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null sel) nil)
               (   (progn
                       (setq ent (car sel)
                             enx (entget ent)
                       )
                       (not (wcmatch (cdr (assoc 0 enx)) "LINE,LWPOLYLINE"))
                   )
                   (princ "\nSelected object is not a line or polyline.")
               )
               (   (if (= "LINE" (cdr (assoc 0 enx)))
                       (setq pt1 (trans (cdr (assoc 10 enx)) 0 1)
                             pt2 (trans (cdr (assoc 11 enx)) 0 1)
                       )
                       (setq par (fix (+ 1e-8 (vlax-curve-getparamatpoint ent (vlax-curve-getclosestpointto ent (trans (cadr sel) 1 0)))))
                             pt1 (vlax-curve-getpointatparam ent par)
                             pt2 (vlax-curve-getpointatparam ent (1+ par))
                       )
                   )
                   (vl-cmdf "_.line" "_non"
                       (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) pt1 pt2)
                       (strcat "<" (angtos (+ (angle pt1 pt2) (/ pi 2.0))))
                       "\\" ""
                   )
               )
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)

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