Adding a transparent command

Discussion in 'AutoCAD' started by TCEBob, Dec 10, 2004.

  1. TCEBob

    TCEBob Guest

    I'm over my head. Here's what I have:

    (defun btw( / p1 p2 p3) ;point between two pick points
    (setq p1(getpoint "\nFirst point: "))
    (setq p2(getpoint p1 "\nSecond point: "))
    (setq p3(polar p1 (angle p1 p2) (distance p1 p2)))
    (princ)) ;defun

    (vlax-add-cmd "btw" 'btw "ACRX_CMD_TRANSPARENT")

    What I'd REALLY like to do is add an osnap. But keying in 'btw will do.

    help.

    rs
     
    TCEBob, Dec 10, 2004
    #1
  2. TCEBob

    TCEBob Guest

    Oops, here it is, corrected:

    (defun btw( / p1 p2 p3) ;point between two pick points
    (setq p1(getpoint "\nFirst point: "))
    (setq p2(getpoint p1 "\nSecond point: "))
    (setq p3(polar p1 (angle p1 p2) (/ (distance p1 p2) 2)))
    (princ)) ;defun
    (vlax-add-cmd "btw" 'btw "ACRX_CMD_TRANSPARENT")
     
    TCEBob, Dec 10, 2004
    #2
  3. TCEBob

    TCEBob Guest

    Ok, scratch that. Here it is corrected correctly:

    (defun btw( / ) ;point between two pick points
    (setq p1(getpoint "\nFirst point: "))
    (setq p2(getpoint p1 "\nSecond point: "))
    (polar p1 (angle p1 p2) (/ (distance p1 p2) 2))
    ) ;defun

    (vlax-add-cmd "btw" 'btw "ACRX_CMD_TRANSPARENT")
     
    TCEBob, Dec 10, 2004
    #3
  4. Simpler way: add this into the **SNAP section of the ***POP0 part of the
    menu (reassemble into one line):

    ID_OsnapMid2 [Mid of &2]^P(list (/ (+ (car (setq A (getpoint "1st POINT:
    "))) (car (setq B (getpoint "2nd POINT: ")))) 2) (/ (+ (cadr A) (cadr B))
    2)) ^P

    I put it just after the Midpoint line. Doesn't require typing anything in.
    Just bring up the on-the-spot Osnap list, and there it is. I also have one
    that does a fractional distance between two points (if you want to use, for
    instance, 3/4 of the way from one point to another -- you tell it what
    fraction), if you're interested.
     
    Kent Cooper, AIA, Dec 10, 2004
    #4
  5. TCEBob

    Tom Smith Guest

    Simpler way: add this into the **SNAP section of the ***POP0

    Kent, that looks like a great approach, but does this override running
    osnaps? I once used a function much like krispy's, but without the temporary
    osmode=0. It worked fine as long as I was designating a point in empty
    space, but if the "midpoint" happened to fall on an object, running osnaps
    could cause a different point to be selected -- for instance if an endpoint,
    midpoint, or quadrant happened to fall withing snapable distance. I had to
    add the temporary osmode=0 to prevent this.
     
    Tom Smith, Dec 10, 2004
    #5
  6. What version of AutoCAD are you running?
    AutoCAD 2005 has mid2 and m2p built in.
     
    Jason Piercey, Dec 10, 2004
    #6
  7. TCEBob

    GaryDF Guest

    I have 2005...please tell me how to use it.
    I get ; error: no function definition: MID2

    Gary
     
    GaryDF, Dec 10, 2004
    #7
  8. That is odd, works fine here.

    Command: l
    LINE Specify first point: mid2
    First point of mid:

    Command: l
    LINE Specify first point: m2p
    First point of mid:

    Any customization getting in the way?
     
    Jason Piercey, Dec 10, 2004
    #8
  9. You're right, you have to be aware of that. This routine goes way back,
    long before running Osnaps. I've been lazy enough to not "fix" it, but have
    just gotten used to hitting F3 before I pick the second point, if I have
    running Osnaps on. And I'd be inclined, rather than to temporarily do
    Osmode=0, to add that value to OSMODE (I forget what it is without looking
    it up) that is the equivalent of hitting F3 (disables the running mode
    without changing your set combination). Some day....
     
    Kent Cooper, AIA, Dec 10, 2004
    #9
  10. TCEBob

    Tom Smith Guest

    add that value to OSMODE (I forget what it is ...

    LOL I've got a few myself that I keep meaning to update with the "F3
    number" -- but I think it takes a bit of logand business, and that always
    requires a little refresher too. "Some day" maybe I'll figure it out and
    tuck it away as a library routine for the occasions when I want it.
     
    Tom Smith, Dec 10, 2004
    #10
  11. TCEBob

    GaryDF Guest

    Man, learn something everyday.
    Works fine...I was just doing it wrong..

    Gary
     
    GaryDF, Dec 10, 2004
    #11
  12. TCEBob

    GaryDF Guest

    Stupid me I was using (mid2)

    I'm still on my second cup....stayed up too late.

    Gary
     
    GaryDF, Dec 10, 2004
    #12
  13. Glad it works, but... what were you doing to get
    the "no function definition" error? If anything, I
    would think you'd get an "unknown command".
     
    Jason Piercey, Dec 10, 2004
    #13
  14. TCEBob

    TCEBob Guest

    Thank you all. Don't know whether I want to add it to the osnap list yet.

    Krispy, you have caused an epiphany; it never occurred to me to deliver a point
    to a command via (Command). Ya live and learn. Point of order: why do you not
    need to use !midxy, as you would from the keyboard?

    So, what about
    (vlax-add-cmd "btw" 'btw "ACRX_CMD_TRANSPARENT")?
    Is that excess baggage -- or am I even using it correctly?

    rs
     
    TCEBob, Dec 10, 2004
    #14
  15. TCEBob

    krispy Guest

    Sorry... don't know much about all the vlax commands, I went straight from basic lisp stuff to VBA.
    As to the other... when your "in" the lisp you are passing the variable, so that AutoCAD doesn't see "(command midxy)" but sees "command: xx,yy,zz" with whatever the point is. When you are at the command line AutoCAD doesn't know whether you are going to type the point or a variable name, so it assumes you are giving it the point. We have to tell AutoCAD that we are going to give a variable name but prefixing it with an exclamation point.
    Hope that helps and doesn't confuse instead. :)
     
    krispy, Dec 12, 2004
    #15
  16. TCEBob

    James Allen Guest

    But watch out if you have polar tracking turned on! If your resulting point
    is 'close enough' (determined by aperture) to one of your tracking angles,
    it will 'snap' to it. Just FYI.
     
    James Allen, Dec 12, 2004
    #16
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.