Insert block at given offset from point

Discussion in 'AutoCAD' started by Matjaz Udovc, Feb 6, 2004.

  1. Matjaz Udovc

    Matjaz Udovc Guest

    This will probably take less then a second to solve for someone who
    knows Lisp a bit...

    How do I complete this simple routine that will prompt for a basepoint
    (X,Y,Z), prompt for offset distance (d) and then insert a block at a
    point X-d,Y,Z.

    Here's how I've started it but I'm stuck at putting the insertion point
    into it:
    (defun c:rout1 ()

    (setq bp (getpoint "Basepoint : ")
    (setq of (getreal "Offset : "))
    (command "-insert" "myblock" (- bp (of 0 0)) "1" "1" "0")

    )
     
    Matjaz Udovc, Feb 6, 2004
    #1
  2. Matjaz Udovc

    Rune Wold Guest

    Err.. (polar bp (* pi 1.0) of) offsets the point along the X axis in
    negative direction. Is this waht you need?
     
    Rune Wold, Feb 6, 2004
    #2
  3. Matjaz Udovc

    ECCAD Guest

    Try this one:

    (defun c:rout1 ()
    (setq bp (getpoint "Basepoint : ")
    (setq of (getreal "Offset : "))
    (setq new_pt (list (- (car bp) of)(+ (cadr bp) 0.0)))
    (command "-insert" "myblock" new_pt "1""1""0")
    ;;;(command "-insert" "myblock" (- bp (of 0 0)) "1" "1" "0")
    )

    Bob
     
    ECCAD, Feb 6, 2004
    #3
  4. Matjaz Udovc

    Paul Turvill Guest

    Uhh ... wouldn't that be exactly the same as
    (polar bp pi of)
    ??
    ___
     
    Paul Turvill, Feb 6, 2004
    #4
  5. Matjaz Udovc

    Matjaz Udovc Guest

    Thanks for your help guys, but I still have problems.

    I tried both Bob's and Rune's suggestion and they both show some strange
    behaviour: if you draw a horizontal line and a vertical line that
    crosses the first one, and then run the routine
    1. if I pick the endpoint of each line the routine works just as planned
    2. if I pick the intersection of those two lines the routine inserts
    "myblock" at the endpoint of the horizontal line (the one closer to the
    intersection)

    both variants work this way
    (setq new_pt (polar bp (* pi 1.0) of))
    or
    (setq new_pt (list (- (car bp) of)(+ (cadr bp) 0.0)))

    how can this be mended?

    TIA
     
    Matjaz Udovc, Feb 6, 2004
    #5
  6. Matjaz Udovc

    Rudy Tovar Guest

    Do you have running osnaps?


     
    Rudy Tovar, Feb 6, 2004
    #6
  7. Matjaz Udovc

    Matjaz Udovc Guest

    Not certain that I know what you mean. Osnap is on and that's how I want
    it for the basic idea is that I want to insert "myblock" at an offset
    from intersection of two lines thus I need Osnap on.
     
    Matjaz Udovc, Feb 6, 2004
    #7
  8. Matjaz Udovc

    ECCAD Guest

    Matjaz,
    I would be helpful to more clearly define 'exactly' what you wanted to do, we need to toggle off the running Osnap, so it does not 'override' the new_pt location.
    Do:
    (defun c:rout1 ()
    (setq bp (getpoint "Basepoint : ")
    (setq OLD_SNAPMODE (getvar "OSMODE")); save settings
    (setq of (getreal "Offset : "))
    (setq new_pt (list (- (car bp) of)(+ (cadr bp) 0.0)))
    (command "-insert" "myblock" new_pt "1""1""0")
    (setvar "OSMODE" OLD_SNAPMODE); restore
    (princ)
    )

    Bob
     
    ECCAD, Feb 6, 2004
    #8
  9. Matjaz Udovc

    Matjaz Udovc Guest

    Aha, now I get it. When new_pt fell exactly on a horizontal line ACAD
    picked endpoit of that line instead using osnap.

    This routine is now working exactly like I wanted it to so I thank you
    all for two things:
    1. getting this routine together that will save me some time and even
    more important 2. understanding a tiny bit more about how Lisp works

    Thanks

    Matjaz
     
    Matjaz Udovc, Feb 7, 2004
    #9
  10. Matjaz Udovc

    Matjaz Udovc Guest

    (defun c:rout1 ()
    (setq bp (getpoint "Basepoint : "))
    (setq OLD_SNAPMODE (getvar "OSMODE")); save settings
    (setvar "OSMODE" 0); OSNAP off
    (setq of (getreal "Offset : "))
    (setq new_pt (list (- (car bp) of)(+ (cadr bp) 0.0)))
    (command "-insert" "myblock" new_pt "1""1""0")
    (setvar "OSMODE" OLD_SNAPMODE); restore
    (princ)
    )

    this is the routine that works like I planned (Had to add lne 4 to turn
    OSNAP off after saving the settings)

    Matjaz
     
    Matjaz Udovc, Feb 7, 2004
    #10
  11. Matjaz Udovc

    John Uhden Guest

    It's probably cleaner to avoid setting/resetting "Osmode" altogether since the
    user could *cancel* the function at the "Offset: " prompt. This can be done by
    overriding the current snap mode just before the point input in the command
    sequence. Also, things might be happier if the program didn't proceed on a null
    response...
    (defun c:rout1 ( / bp of new_pt)
    (and
    (setq bp (getpoint "Basepoint : "))
    (setq of (getreal "Offset : "))
    (setq new_pt (list (- (car bp) of)(+ (cadr bp) 0.0)))
    (command "-insert" "myblock" "_NON" new_pt "1""1""0")
    ;; ---------- override here ----------^
    )
    (princ)
    )
     
    John Uhden, Feb 8, 2004
    #11
  12. Matjaz Udovc

    OLD-CADaver Guest

    You'll need to turn OSNAP off somewhere int he routine to avoid the routine selecting the end of the existing lines. Another optionis have the routine place the block, then move it the specified distance.

    I, personally, would just redefine the block so that it's insertion point remained at the selected point, but the graphics were offest.
     
    OLD-CADaver, Feb 8, 2004
    #12
  13. Matjaz Udovc

    Matjaz Udovc Guest

    Thanks!
     
    Matjaz Udovc, Feb 9, 2004
    #13
  14. Matjaz Udovc

    Rune Wold Guest

    It would.
     
    Rune Wold, Feb 9, 2004
    #14
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.