Auto insert block and trim

Discussion in 'AutoCAD' started by Big 'D', May 13, 2004.

  1. Big 'D'

    Big 'D' Guest

    I have a prospective program I am working on. I want to submit it in pieces so I can do as much of it myself as I can. But I am stumped here. I have attached what I have so far. At this point I simply want to be prompted for first and endpoint of a rectangle, ask if I want to add block bko, if not - do nothing else, if so - add a block (bko - which is a break symbol). If the symbol is added, it's insertion point will be the mid point of the bottom line of the rectangle. I am thinking of drawing lines with specific dimensions instead of the rectangle then I can add the block at the midpoint of the last entity (I think). What my routine does to now is draw the rectangle, prompt for insertion point of break, and prompt for entity to trim and the enpoints at which to trim it.
    Help past this point is much appreciated.
    D
    ; Define the function (the program).
    (defun c:ADD ( / OLDCE OLDERR OLDTE)
    ; Save the current value of cmdecho then redefine it.
    (setq OLDCE (getvar "cmdecho"))
    (setvar "cmdecho" 1)
    ; Save the current value of texteval then set it to 1
    (setq OLDTE (getvar "texteval"))
    (setvar "texteval" 1)
    ; Save the current value of the error handling subroutine then redefine it.
    (setq OLDERR *error*)
    (defun *error* (errmes)
    (princ (strcat "\nExecution of ADD halted by the following error: " ERRMES))
    (setvar "cmdecho" OLDCE)
    (setq *error* OLDERR)
    (prin1)
    )
    ;(setq *error* nil)
    ; NOTE: to turn error handling off, erase the semicolon in the line above.

    ; Input to AutoCAD's command line.
    (command
    "layer"
    "s"
    "obj"
    ""
    "rectangle" PAUSE PAUSE
    "osnap"
    "none"
    "osnap"
    "mid"
    "insert"
    "G:/Acad2000/cadstd/symlib/DC-10/bko" PAUSE
    "1"
    "1"
    "0"
    "osnap"
    "none"
    "osnap"
    "end"
    "break" PAUSE
    "f" PAUSE PAUSE
    "osnap"
    "none"
     
    Big 'D', May 13, 2004
    #1
  2. Big 'D'

    Big 'D' Guest

    Hey folks,
    Never mind on this. I am past this part now. For those of you who read it with interest, I just had my routine draw a p-line including the break.
     
    Big 'D', May 13, 2004
    #2
  3. I would take this approach:

    Instead of just getting the rectangle corners with two PAUSEs, save each of
    them as a point so you can use the corners to calculate the insertion point
    of the block and the break points for the rectangle, something like:

    "rectangle" (setq pt1 (getpoint "First corner: ")) PAUSE (setq pt2
    (getcorner pt1 "Opposite corner: ")) PAUSE

    Notice the (getcorner) instead of (getpoint) for the second one, which (with
    pt1 mentioned) will "rubber-band" the rectangle on-screen for you.

    Then compare the y coordinates of the two points to determine which is on
    the bottom edge, and set that value (here called ybase), something like:

    (if (< (cadr pt1) (cadr pt2)) (setq ybase (cadr pt1)) (setq ybase (cadr
    pt2)))

    Calculate the x coordinate of the midpoint of the bottom edge (here called
    xmidbase), something like:

    (setq xmidbase (/ (+ (car pt1) (car pt2)) 2))

    Assuming you know the size of the gap (here called "gap") you want to break
    in the bottom line, do it (BEFORE putting in the block, so the break command
    won't have any chance to "see" the block instead of the rectangle) by
    breaking from half-the-gap to the left of the midpoint to half-the-gap to
    the right of it, something like:

    "break" "non" (list (- xmidbase (/ gap 2)) ybase) "non" (list (+ xmidbase (/
    gap 2)) ybase)

    This can be made scale-dependent with a multiplier of DIMSCALE or LTSCALE or
    something, if you do this in different drawing scales.

    [With the "non" things in there, you don't have to bother setting or
    clearing osnap. Then you don't need to worry what osnap settings there are,
    or save them and restore them.]

    Then insert the block at the midpoint of the baseline, something like:

    "insert" "G:/Acad2000/cadstd/symlib/DC-10/bko" (list xmidbase ybase) "1" "1"
    "0"

    [That's assuming your block insertion point is in the middle of the gap
    width.]
    You can also make this scale-dependent for different scale drawings, with a
    multiplier of DIMSCALE or whatever for the scale factors.

    Also, in general, it's not necessary to clear osnap settings before setting
    it to some individual mode, like your
    "osnap" "none" "osnap" "mid"
    You can just do the
    "osnap" "mid"
    or set OSMODE to the appropriate number. But none of that should be
    necessary in this routine if you let it calculate the locations for you,
    because you don't need to pick the appropriate points on-screen, so you
    don't need osnaps.

    Kent Cooper, AIA


    pieces so I can do as much of it myself as I can. But I am stumped here. I
    have attached what I have so far. At this point I simply want to be prompted
    for first and endpoint of a rectangle, ask if I want to add block bko, if
    not - do nothing else, if so - add a block (bko - which is a break symbol).
    If the symbol is added, it's insertion point will be the mid point of the
    bottom line of the rectangle. I am thinking of drawing lines with specific
    dimensions instead of the rectangle then I can add the block at the midpoint
    of the last entity (I think). What my routine does to now is draw the
    rectangle, prompt for insertion point of break, and prompt for entity to
    trim and the enpoints at which to trim it.
     
    Kent Cooper, AIA, May 13, 2004
    #3
  4. Big 'D'

    Big 'D' Guest

    Kent,
    Thank you for that wonderful lesson. I will study it carefully. I believe this is a much cleaner approach. Your assistance is exactly what a newby needs to keep from getting to the point of total frustration.
    D
     
    Big 'D', May 13, 2004
    #4
  5. Big 'D'

    Big 'D' Guest

    Kent,
    Where do I give the actual distance for the break?
    You wrote:

    Assuming you know the size of the gap (here called "gap") you want to break in the bottom line, do it (BEFORE putting in the block, so the break command won't have any chance to "see" the block instead of the rectangle) by breaking from half-the-gap to the left of the midpoint to half-the-gap to the right of it, something like:

    "break" "non" (list (- xmidbase (/ gap 2)) ybase) "non" (list (+ xmidbase (/ gap 2)) ybase)

    Sorry, don't mean to be so 'uninformed' (that's a nice way of saying dense)
     
    Big 'D', May 14, 2004
    #5
  6. Big 'D'

    Big 'D' Guest

    Never mind Kent
    (duh moment)
     
    Big 'D', May 14, 2004
    #6
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.