Mid between two points

Hi.  Just getting started with bricscad and I'm already stumped....How can I snap a dimension to the middle of two points similar to Autocad(shift + rght click).  This is essential for dimensioning walls in a floor plan.  Any help is appreciated

thanx

Matt

Comments

  • Found this LISP...

     

    (defun MidPnt (p1 p2)(mapcar '(lambda (a b) (/ (+ a b) 2.0)) p1 p2))(defun c:mp (/ MdPt pt1 pt2)(setq pt1 (getpoint "\nFirst ENDPOINT:"))(setq pt2 (getpoint pt1 "\nSecond ENDPOINT:"))(setq os (getvar "osmode"))(setvar "osmode" 0)(setq MdPt (MidPnt pt1 pt2))(setvar "osmode" os)  MdPt)

    ...here http://discussion.autodesk.com/forums/thread.jspa?threadID=416112. which should do the trick.  Just call it with an apostrophe in front to make the call transparent.  Like this 'mp. Alternatively add the 'mp command to a keyboard shortcut to save you typing it everytime

    Regards,

    Daniel

     

  • I have been using a similar solution mapped to a keystroke for quite some time now. I found the resulting point is now used to snap again so my routine does not work as intended with the lates beta version. Perhaps Bricscad will provide a mid brtween snap for us... is this something that has changed to work like some other cad package?

     

  • Greg: I don't have access to beta-versions but the variable osnapcoord may be something to look at. However, Using BC 10.2.13 I find that it doesn't affect the behaviour of either Daniel's lisp or my own (virtmid) lisp ;-)

  • Roy, good thought with the OSNAPCOORD variable but it does not affect this behaviour for me. My code works great in 10.2 releases also but not the beta. I use mid between quite often so I have it bound to Ctrl-B key.

    Here is what I have in on_doc_load.lsp:

     

    ;; This function is called from a keystroke (CTRL-B) as mapped in REF.CUI
    (defun midbetween ( )
    (setvar "LASTPOINT" (getpoint "\nMid between first point: "))
    (mapcar
    (function
    (lambda(x y)
    (/ (+ x y) 2.0))
    )
    (getvar "LASTPOINT")
    (getpoint "\nto point: " (getvar "LASTPOINT"))
    )
    )

     

     

  • I guess I was not wording my question very clearly. I can't test what Autocad does in this use case easily right now so I am not sure if I should expect the new or old behaviour.

    Eg: Currently, if I use the (midbetween) function above while selecting a point for a LINE command with the snaps active it does not matter if there is a possible snap from the calculated point, the line command will get the calculated point.

    Does Autocad snap or use the calc point?

  • Greg: try this:

    (defun midbetween ( / newPt oldOsmode)
    (setq newPt
    (mapcar
    '(lambda (x y) (/ (+ x y) 2.0))
    (setvar "lastpoint" (getpoint "\nMid between first point: "))
    (getpoint "\nto point: " (getvar "lastpoint"))
    )
    )
    (setq oldOsmode (getvar "osmode"))
    (setvar "osmode" 0)
    (command newPt)
    (setvar "osmode" oldOsmode)
    (princ)
    )
  • Oops?
    I see that I have followed Greg's example for the order of the (getpoint) arguments. According to BC7  Help this should be: (getpoint [point] [prompt]).
    No protest from BC10 though...

  • Ha! Good catch on the order of arguments ;-)

    Thanks!

  • Greg: have you tested the code from post #7, and does it solve your problem?

  • @Roy: No, not working: but I have been politely asked to not speak about the beta :-(

  • Stangely enough this one seems to do the trick:

    (defun VirtMid ( / pt oldOsmode)
    (setq pt
    (mapcar
    '(lambda (a b) (/ (+ a b) 2.0))
    (setvar "lastpoint" (getpoint "\nSnap to virtual midpoint of: first point: "))
    (getpoint (getvar "lastpoint") "\nSnap to virtual midpoint of: second point: ")
    )
    )
    (setq oldOsmode (getvar "osmode"))
    ; (setvar "osmode" 0) ; this doesn't work
    ; (command pt) ; this doesn't work
    (command "_none" pt)
    (setvar "osmode" oldOsmode)
    (princ)
    )
  • My lisp for that still works (load it at startup and run !(half) to make it transparent).

    But some of mine which find points, stopped working properly recently if Osnap is set to other than None because Osnap applies to any or all points in the routine, the result varying depending what the Osnap setting is. Apparently this is now consistent with Acad behavior.

    (Defun HALF (/ a b)
    (SETQ A (GETPOINT "\nFirst Point ")
    B (GETPOINT A "\nOther Point "))
    (POLAR A (ANGLE A B)(/ (DISTANCE A B) 2)))

  • @ John Gaunt:
    Have you tried the code from post #12? As I said: it seems to solve the "osnap-problem".

  • I hadn't tried it Roy, I assumed it does work because it resets Osnap to None... and it does work.

    Actually Daniel's initial code just produces an endless loop for me when I paste it on the command line.

    In fact my code looks like one which might NOT work with Osnap other than 0, but it still seems to.

    My comment was more general directed at any similar lisp which might not work because of Osnap's influence - I have a number of these.

    I can F3 Osnap temporarily off or reset it as you have done here, but that loses my Osnap setting unless the routine resets it at the end.

    That works unless the routine is interrupted, then Osnap settings are lost again.

    Just alerting to the new Acad-like behavior and suggesting it as a possible reason why this and similar code might now have trouble.

  • I'm using this routine for similar tasks:

    (defun kf-calcpt (pt1; first point
    pt2; second point
    dist_co; distance coefficient - from first point
    / )

    (polar pt1 (angle pt1 pt2) (* (distance pt1 pt2) dist_co))
    )

    ;example for midpoint:
    (kf-calcpt '(0 0 0) '(10 0 0) 0.5)
    Get your points and pass them to this routine using dist_co parameter as 0.5
This discussion has been closed.