Insert number of blocks and increase the attribute number

Discussion in 'AutoCAD' started by VikCAD04, Mar 4, 2005.

  1. VikCAD04

    VikCAD04 Guest

    OK, i'm getting confused.
    I decided to fix a little repetitive task that we do here all the time, i have an idea of how it should work, but i'm stuck.

    Need to do this:
    Prompt for how many blocks to insert
    Prompt for what angle
    Prompt for what number to start numbering
    Prompt for insertion point of the first block

    then,
    Insert the first block,
    this is where i get lost.
    If the starting number is 2, how do i keep it in the loop to keep inserting another block but .25 lower or to the right (depending on what angle was specified) until all the blocks (how ever many were specified) are in.

    So the idea is I type in the command, tell it all the info and it will insert like 20 terminal blocks all right next to each other and all numbered.

    all the promting and easy stuff i can do, it's the root of this that's killing me. Cause i'm not sure what to add one to. Maybe someone already has something similar.

    Thanks for all the help in advance.

    Viktor.
     
    VikCAD04, Mar 4, 2005
    #1
  2. VikCAD04

    Jeff Mishler Guest

    This is based on the response I gave you back in October for inserting
    multiple blocks. This is portable enough that you could supply hard coded
    values in place of user prompts, if so desired.

    (defun multi-insert (bname rpt num insPt scale ang spacingx spacingy / )
    (repeat rpt
    ;block must have exactly 1 attribute that asks for a value
    (command "-insert" bname insPt scale scale ang (itoa num))
    (setq insPt (list (+ (car insPt) spacingx)
    (+ (cadr insPt) spacingy)
    (caddr insPt)
    )
    num (1+ num)
    )
    )
    )

    And here's an example of how to use this:

    (setq pt1 (getpoint "\nSelect insertion point for first block: ")
    ang (getangle pt1 "\nRotation angle: ")
    scale (getreal "\nScale to use for block? ")
    x (getreal "\nEnter X spacing: ")
    y (getreal "\nEnter Y spacing: ")
    )

    (multi-insert "test" 10 2 pt1 scale ang x y); "test" is the block name
    ;| where the 10 is number of blocks, 2 is the number to start numbering
    from,
    pt1 is the insertion point of the first block, scale is the block's scale
    factor, ang is the rotation angle, x is the spacing for the block to move
    in the x direction and y is the y spacing|;

    HTH,
     
    Jeff Mishler, Mar 4, 2005
    #2
  3. VikCAD04

    VikCAD04 Guest

    thanks,
    i don't remember seeing this one, maybe my memory is fading.
    I'm still having issues though, this is what i have:

    (defun c:tb ( / )
    (setq blockQuantity(getint "\nHow many terminal blocks? "))
    (setq startNumber(getint "\nWhat number to start the blocks with? "))
    (setq blockangle(getint "\nWhat angle do you want the block to be [0 = Y axis 90 = X axis]? "))
    (setq blockLocation(getpoint "\nPick insertion point of the first block "))


    (repeat rpt
    (command "-insert" "tbk-tbk1-xx-h" blocklocation "" "" blockangle (itoa startnumber) "")
    (if = (blockangle 0)
    (setq insertionPt(list (+ (car blocklocation) 0.25))))
    (if = (blockangle 90)
    (setq insertionPt(list (+ (cadr blocklocation) 0.25))))))

    I know it's messed up, but can you point me to why my thinking is not straight?
    See, i know that the offset of the block is .25 all the time, and if the user says that angle is 0 degrees, then X axis need to be offset .25 for every block, if the user says 90 degrees, then it should offset on the Y axis .25.

    This part is just for inserting a number of blocks, numbering them will be another issue.

    thanks,
    forgive my clueless.
     
    VikCAD04, Mar 4, 2005
    #3
  4. VikCAD04

    James Allen Guest

    "(list (+ (car blocklocation) 0.25))"

    Hi Viktor,
    I think what you mean here is;
    (list (+ (car blocklocation) 0.25) (cadr blocklocation))
    I'll leave the rest to you...
    --
    James Allen, EIT
    Malicoat-Winslow Engineers, P.C.
    Columbia, MO


    user says that angle is 0 degrees, then X axis need to be offset .25 for
    every block, if the user says 90 degrees, then it should offset on the Y
    axis .25.
     
    James Allen, Mar 4, 2005
    #4
  5. VikCAD04

    Jeff Mishler Guest

    Hi VikCAD04,
    Please look at the function I posted. It will do what you want, you just
    need to send the correct values to it based on your user's input.

    (defun c:tb ( / blockangle blocklocation blockquantity startnumber x y)
    (setq blockQuantity(getint "\nHow many terminal blocks? "))
    (setq startNumber(getint "\nWhat number to start the blocks with? "))
    (setq blockangle(getint "\nWhat angle do you want the block to be [0 = Y
    axis 90 = X axis]? "))
    (setq blockLocation(getpoint "\nPick insertion point of the first block
    "))
    (if (eq blockangle 0)
    (setq x 0.0
    y 0.25)
    (setq x 0.25
    y 0.0)
    )
    (multi-insert "tbk-tbk1-xx-h" blockQuantity startNumber blockLocation 1
    blockangle x y)
    (princ)
    )
     
    Jeff Mishler, Mar 4, 2005
    #5
  6. VikCAD04

    VikCAD04 Guest

    ok i fixed that, thanks.
    Now, i still can't get it to insert more than 1 block. I'm assuming i can use REPEAT function to keep repeating as many times as the user request blocks of, but i can't even get it to do 2.
    I'm not only bad at lisping but at troubleshooting as well.
    Please help some more. I'm learning as i go.
    Thanks,
    viktor.

    here's my "creation"
    (defun c:tb ( / )
    (setq blockQuantity(getint "\nHow many terminal blocks? "))
    (setq startNumber(getint "\nWhat number to start the blocks with? "))
    (setq blockangle(getint "\nWhat angle do you want the block to be [0 = Y axis 90 = X axis]? "))
    (setq blockLocation(getpoint "\nPick insertion point of the first block "))
    (command "-insert" "tbk-tbk1-xx-h" blocklocation "" "" blockangle startnumber "")

    (repeat blockquantity
    (cond
    (if = (blockangle 0)
    (setq insertionPt(list (+ (car blocklocation) 0.25)(cadr blocklocation))))
    (if = (blockangle 90)
    (setq insertionPt(list (car blocklocation)(+ (cadr blocklocation) 0.25))))
    (command "-insert" "tbk-tbk1-xx-h" insertionpt "" "" blockangle startnumber "")
    )
    )
    )
     
    VikCAD04, Mar 4, 2005
    #6
  7. VikCAD04

    James Allen Guest

    Jeff has offered a solution that you could learn from. Also, in the
    interest of learning, you are setting insertionPt to the same value in every
    loop.

    (setq insertionPt ... blocklocation...); blocklocation never changes,
    therefore neither does insertionPt.

    --
    James Allen, EIT
    Malicoat-Winslow Engineers, P.C.
    Columbia, MO


    use REPEAT function to keep repeating as many times as the user request
    blocks of, but i can't even get it to do 2.
     
    James Allen, Mar 5, 2005
    #7
  8. VikCAD04

    VikCAD04 Guest

    Hi Jeff and everyone who helped.
    Thanks Jeff for your function, I wasn't quiet sure why you had the multi-insert function separately, and got a bit confused, i thought you were using the minsert which i knew wouldn't work for me. Once i figured it out (3 hours later) it works beatifuly, thanks for your help all.
    And I did learn from this one.

    Thanks,
    Viktor.
     
    VikCAD04, Mar 7, 2005
    #8
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.