Block Help!!

Discussion in 'AutoCAD' started by kyeric, Feb 8, 2005.

  1. kyeric

    kyeric Guest

    Hello all,

    I am beating my head trying to figure out how to create a one-button macro in ACAD2005 to do the following:

    1. Create unnamed Block from selection
    2. Erase previous selection
    3. Insert Block in exact position of previous selection.

    I understand that the macro has to be copyclipped at 0,0, the erase previous, then insert block at 0,0, but all of my attempts to create this macro gives me an error message in AutoCAD.

    I don't know if it would be easier to just have a lisp command to do this...

    Any help on this matter would be greatly appreciated!

    Thanks,
    e
     
    kyeric, Feb 8, 2005
    #1
  2. kyeric

    James Buzbee Guest

    This creates a block of the selected objects called TEMP* (* = 1, 2, 3 etc.)
    and inserts at same location. The actual insertion point of the blockref
    changes - it only picks a point of one of the objects selected. It also
    places the blockref on layer "0". Not very elegant I'm sure but it works
    and I use it alot!

    jb


    (defun c:jbAnonBlock (/ *Error* anon-blk-obj ins-pt bn bc blk-obj)
    (defun *Error* (Msg)
    (cond
    ((or (not Msg)
    (member Msg
    '("console break"
    "Function cancelled"
    "quit / exit abort"))))
    ((princ (strcat "\nError: " Msg))))
    (princ))
    (setq anon-blk-obj(ssget))
    (if anon-blk-obj
    (progn
    (setq ins-pt(cdr (assoc 10(entget(ssname anon-blk-obj 0)))))
    (if (= ins-pt nil)
    (setq ins-pt "0,0,0"))
    (setq bn "TEMP1"
    bc 1)
    (while (/= (tblsearch "BLOCK" bn) nil)
    (setq bc (1+ bc)
    bn (strcat "TEMP" (itoa bc))))
    (command "-block" bn ins-pt anon-blk-obj "")
    (initdia 0)
    (command "-insert" bn ins-pt "" "" "0")
    (setq blk-obj(vlax-ename->vla-object (entlast)))
    (vla-put-layer blk-obj "0")))
    (princ)
    (princ))
     
    James Buzbee, Feb 8, 2005
    #2
  3. kyeric

    kyeric Guest

    Thanks James,

    Problem is, I don't know how to use this lisp! Could you give me a little more instruction on what to do with what you wrote? I assume that I can copy/paste your code into a new wordpad file. Then rename the file to "something".lsp to get AutoCAD to recognize it. Now, what do I name it, where do I put it to load into ACAD every session, and while in ACAD, how do I envoke the command? Sorry, but I am an extreme newbie at this lisp stuff! Thanks for your help!!!!

    -e
     
    kyeric, Feb 8, 2005
    #3
  4. kyeric

    James Buzbee Guest

    No problem.
    You are correct about the copy/paste/wordpad part. Name it whatever you
    want. For the sake of the example below let's name it: "AnonBlock.lsp".
    The file needs to reside in AutoCAD's search path.

    Now start another wordpad session and copy/paste the following:
    (progn(load "AnonBlock.lsp")(princ "AnonBlock.lsp now loaded. use
    'jbAnonBlock' to start command"))
    (princ)

    Now save this file as "acaddoc.lsp" and make sure it's in the search path as
    well. Now when you start AutoCAD, or another drawing session, you should
    see "AnonBlock.lsp now loaded. use 'jbAnonBlock' to start command" echoed at
    the command line. Use jbAnonBlock to start the command and follow the
    prompts.

    jb
     
    James Buzbee, Feb 8, 2005
    #4
  5. kyeric

    Don Butler Guest

    Don Butler, Feb 8, 2005
    #5
  6. kyeric

    kyeric Guest

    Thank you guys so much for the help, I really appreciate it!
     
    kyeric, Feb 8, 2005
    #6
  7. kyeric

    Alaspher Guest

    Alaspher, Feb 9, 2005
    #7
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.