Jump to content

Bisect Line and draw perpendicular line at midpoint


Baber62

Recommended Posts

Looking for a quick fix. I need to bisect a line and draw a perpendicular line from the mid-point of the measure line. It would be great if this could be dynamically done i.e. the perpendicular can be drawn either side of the line and to any length.

 

Any assists will abe appreciated.

Link to comment
Share on other sites

In your OSNAPs set midpoint and perpendicular. Turn dynamic input on. Press F11 to toggle "object snap trace" on (I think that's what its called in English versions, if not look in the bottem left of the screen and observe and you'll see an icon go on and off, make sure that it is on). Start the line command and snap to the mid point of the line and as you move your cursor away you will get a dotted line and you just need to enter the length of the line and you have exactly what you wished for.

Link to comment
Share on other sites

Just follow Tyke's instructions and you will be a very happy camper. :beer:

The 3 ICONS which are circled in the image are those to which Tyke refers

they are OBJECT SNAPS, OBJECT SNAP TRACKING and DYNAMIC INPUT from left to right.

 

They can be left clicked to turn them on or off,

or they can be toggled on and off with F3, F11 & F12 respectively.

turn on circled icons.JPG

Link to comment
Share on other sites

Use this old program and click the midpoint:

 

(defun c:per ( / *error* e o p )
   (defun *error* ( m )
       (if o (progn (setvar 'orthomode o) (command "_.ucs" "_p")))
       (princ)
   )
   (if (and
           (setq p (getpoint "\nSpecify first point: "))
           (setq e (car (nentselp p)))
       )
       (progn
           (setq p (trans p 1 0))
           (command "_.ucs" "_ob" e)
           (setq o (getvar 'orthomode))
           (setvar 'orthomode 1)
           (command "_.line" "_non" (trans p 0 1))
           (while (< 0 (getvar 'cmdactive)) (command "\\"))
           (setvar 'orthomode o)
           (command "_.ucs" "_p")
       )
   )
   (princ)
)

perpshortcut.gif

Link to comment
Share on other sites

Use this old program and click the midpoint:

 

(defun c:per ( / *error* e o p )
   (defun *error* ( m )
       (if o (progn (setvar 'orthomode o) (command "_.ucs" "_p")))
       (princ)
   )
   (if (and
           (setq p (getpoint "\nSpecify first point: "))
           (setq e (car (nentselp p)))
       )
       (progn
           (setq p (trans p 1 0))
           (command "_.ucs" "_ob" e)
           (setq o (getvar 'orthomode))
           (setvar 'orthomode 1)
           (command "_.line" "_non" (trans p 0 1))
           (while (< 0 (getvar 'cmdactive)) (command "\\"))
           (setvar 'orthomode o)
           (command "_.ucs" "_p")
       )
   )
   (princ)
)

perpshortcut.gif

 

That's neat Lee. :thumbsup: With Dynamic Input turned on can you type in the line length?

Link to comment
Share on other sites

Alternatively,

 

(defun c:per ( / e p q )
   (if (setq e (ssget "_+.:E:S" '((0 . "LINE"))))
       (progn
           (setq e (entget (ssname e 0))
                 p (trans (cdr (assoc 10 e)) 0 1)
                 q (trans (cdr (assoc 11 e)) 0 1)
           )
           (vl-cmdf "_.line" "_non"
               (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) p q)
               (strcat "<" (angtos (+ (angle p q) (/ pi 2.0))))
               "\\" ""
           )
       )
   )
   (princ)
)

Link to comment
Share on other sites

Another with grread and grdraw functions . just for fun . :)

 

(defun c:Test (/ s p ang g st nd pt)
;;; Tharwat 25. Jan. 2013 ;;;
 (if (and (setq s (car (entsel "\n Select line :")))
          (eq (cdr (assoc 0 (entget s))) "LINE")
     )
   (progn
     (setq p   (mapcar (function (lambda (j k) (/ (+ j k) 2.)))
                       (setq st (cdr (assoc 10 (entget s))))
                       (setq nd (cdr (assoc 11 (entget s))))
               )
           ang (angle st nd)
     )
     (while (eq (car (setq g (grread t 15 0))) 5)
       (redraw)
       (grdraw p
               (setq pt (polar p
                               (+ ang (* pi 0.5))
                               (if (> 0 (sin (- (angle st (cadr g)) ang)))
                                 (- (distance p (cadr g)))
                                 (distance p (cadr g))
                               )
                        )
               )
               1
               0
       )
     )
     (if (or (eq (car g) 3)
             (eq (car g) 25)
         )
       (entmakex
         (list '(0 . "LINE") (cons 10 (trans p 1 0)) (cons 11 pt))
       )
     )
   )
 )
 (redraw)
 (princ)
)

Edited by Tharwat
small problem with the angle modified with the help of Lee
Link to comment
Share on other sites

Another with grread and grdraw functions . just for fun . :)

 

(defun c:Test (/ s p g st nd pt) 
< ... >

 

Good attempt Tharwat, but not quite:

 

dynerror.gif

 

Consider perhaps something like:

([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] a b d e g m p q )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] e ([color=BLUE]ssget[/color] [color=MAROON]"_+.:E:S"[/color] '((0 . [color=MAROON]"LINE"[/color]))))
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] e ([color=BLUE]entget[/color] ([color=BLUE]ssname[/color] e 0))
                 p ([color=BLUE]trans[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 10 e)) 0 1)
                 q ([color=BLUE]trans[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 11 e)) 0 1)
                 m ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( a b ) ([color=BLUE]/[/color] ([color=BLUE]+[/color] a b) 2.0)) p q)
                 a ([color=BLUE]angle[/color] p q)
                 b ([color=BLUE]+[/color] a ([color=BLUE]/[/color] [color=BLUE]pi[/color] 2.0))
           )
           ([color=BLUE]while[/color] ([color=BLUE]=[/color] 5 ([color=BLUE]car[/color] ([color=BLUE]setq[/color] g ([color=BLUE]grread[/color] [color=BLUE]t[/color] 13 0))))
               ([color=BLUE]redraw[/color])
               ([color=BLUE]setq[/color] g ([color=BLUE]cadr[/color] g)
                     d ([color=BLUE]distance[/color] m g)
                     q ([color=BLUE]polar[/color] m b ([color=BLUE]if[/color] ([color=BLUE]<[/color] 0 ([color=BLUE]sin[/color] ([color=BLUE]-[/color] ([color=BLUE]angle[/color] p g) a))) d ([color=BLUE]-[/color] d)))
               )
               ([color=BLUE]grdraw[/color] m q -1)
           )
           ([color=BLUE]if[/color] ([color=BLUE]=[/color] 3 ([color=BLUE]car[/color] g))
               ([color=BLUE]entmake[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"LINE"[/color]) ([color=BLUE]cons[/color] 10 ([color=BLUE]trans[/color] m 1 0)) ([color=BLUE]cons[/color] 11 ([color=BLUE]trans[/color] q 1 0))))
           )
       )
   )
   ([color=BLUE]redraw[/color]) ([color=BLUE]princ[/color])
)

Link to comment
Share on other sites

  • 2 years later...

A simple macro to rotate the UCS to the line is a very simple way to do all the above.

 

^C^CUCS Object

 

And another to put it back

 

^C^CUCS World

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