Simple block redefine not so simple

Discussion in 'AutoCAD' started by Big 'D', Oct 12, 2004.

  1. Big 'D'

    Big 'D' Guest

    I have been trying to create a lisp or script routine to redefine two blocks and striking out. I have blocks (res1 and cap) that I have tried to redefine. I just want to insert then cancel, or redefine then cancel. I don't care if the block already exists or not. I want to replace all occurences. I am using ACAD 2004 and none of the usual responses are working for me. Please help.
    D
     
    Big 'D', Oct 12, 2004
    #1
  2. You cannot issue a cancel to a script, or it will cancel the script itself.
    So if you want to use a script to do the redefine, fully insert the block,
    and then delete it.

    .._AttReq 0
    .._-Insert
    Res1=C:\Temp\Res1
    0,0,0
    1
    1
    0
    (entdel (entlast))

    --
    R. Robert Bell


    I have been trying to create a lisp or script routine to redefine two blocks
    and striking out. I have blocks (res1 and cap) that I have tried to
    redefine. I just want to insert then cancel, or redefine then cancel. I
    don't care if the block already exists or not. I want to replace all
    occurences. I am using ACAD 2004 and none of the usual responses are working
    for me. Please help.
    D
     
    R. Robert Bell, Oct 12, 2004
    #2
  3. Assuming the "new" definition is an available external drawing file with the
    same name as the block, you can do this:

    -INSERT RES1=
    or
    -INSERT CAP=

    If it's a drawing file with a different name:

    -INSERT RES1=<whatever-it's-called>
    or
    -INSERT CAP=<whatever-that's-called>

    I don't think you can do this kind of redefinition through the Insert dialog
    box, so you need the NON-dialog-box command-line variety, with the hyphen
    preceding the command name.

    If the block doesn't already exist in the drawing, or if you want to add one
    anyway, from here it operates just like normal Insert. If it does exist,
    and you don't want to put another one in, you can cancel, and you may have
    to regenerate to update existing insertions.

    Here's the slightly more complicated one I have (tablet/pull-down/screen
    variety), that asks for any name, so you can use one routine for any
    redefinition:

    [RedefIns]*^C^C^P(setq rgnmd (getvar "REGENMODE")) +
    (setq redef (getstring "NAME OF INSERTED DWG TO REDEFINE: ")) \+
    REGENAUTO OFF -INSERT (strcat redef "=") ^C^P+
    SETVAR REGENMODE !rgnmd

    It requires the name of the external drawing to be the same as the
    insertion. It forestalls regenerating because it was originally built
    before there were Xref's, and we inserted detail drawings at different
    scales into sheets, and computers were slower so we didn't want it to
    regenerate after each redefinition. We could wait to regen until after
    updating as many as needed.
     
    Kent Cooper, AIA, Oct 12, 2004
    #3
  4. Big 'D'

    Big 'D' Guest

    Thank you, Gentlemen. I can see uses for both suggesstions. I think the cancel is what was giving me the problem. I thought I could use ^c. I am still not sure what the problem with the lisp attempt was.
    Have a great day and thanks again.
    D
     
    Big 'D', Oct 12, 2004
    #4
  5. Big 'D'

    OLD-CADaver Guest

    Dunno about 2004, but (command) cancels in R2002 so the lisp would read:

    (command ".-insert" "oldblk=newblk" "y" (command))

    course you need to check if the block exists first, otherwise the "Y" will throw an error.
     
    OLD-CADaver, Oct 12, 2004
    #5
  6. Big 'D'

    Big 'D' Guest

    Is there a way to apply the same routine to work whether the block already exists or not? For example, in the case I want to batch run this procedure on a directory of drawings. In no situation will I need to insert these blocks. This is strictly for redefining.

    D
     
    Big 'D', Oct 12, 2004
    #6
  7. How about [untested]:

    Invoke -INSERT, and give it the block name with the = following. If it
    doesn't exist in the drawing already, the equal sign doesn't keep it from
    working or anything -- it still brings in the definition.

    Then give it a Y, which (if the block exists already) it will take as a
    "Yes" to redefine it, or (if it doesn't) it will take that as a call for a Y
    scale factor.

    Then put in a Cancel, which will be answering different prompts in those two
    cases, but ought to be equally effective.
     
    Kent Cooper, AIA, Oct 12, 2004
    #7
  8. Big 'D'

    James Allen Guest

    Try this.

    (progn
    (command "._insert" "oldblk=newblk" "y")
    (command)
    (prompt "\nIt worked anyway.")
    (princ)
    )

    The "y" will error to the command line if oldblk does not already exist, but
    the routine will continue to run. The empty command call is equivalent to
    entering esc at the command line. HTH
     
    James Allen, Oct 12, 2004
    #8
  9. Big 'D'

    Big 'D' Guest

    This worked great, James. Any help on how I can run this from a script? I have a batch script and have set my lisp to automatically load when AutoCAD is started. The command to invoke this lisp (rep) is at the beginning of the batch script. The script stops after running the lisp
    ( message: Begin LISP
    Begin Command
    *error* Cancelled Command INSERT
    LISP Ended.
    I can types resume and the process will continue through the next file but, if I have to type this after every drawing I am defeating a part of the benefit of a batch script. Can you help?
     
    Big 'D', Oct 12, 2004
    #9
  10. Big 'D'

    Don Butler Guest

    Here's how I am doing it. I build three lists and use a MAPCAR/LAMBDA
    expression with three arguments.

    List 1 are Block names to process...
    <These are actually read from a data file but for clarity I will quote a
    list here:>
    (setq LIS2
    '("1698" "1700" "1702" "1704" "1706" "1708" "0462" "0464" "0468" "0190"
    "0192"
    "0194" "0606" "0608" "0610" "0280" "2832" "2842" "1214" "0810" "1314" "1316"
    "1318" "1320" "1322" "1324" "1646" "1648" "1650" "2046" "2048" "2050" "0462"
    "0464" "0468" "0470" "0472")
    )

    List 2 are names to use FINDFILE on to see if they exist.
    (setq CHECK (mapcar '(lambda (x) (strcat x ".dwg")) lis2))...RETURNS
    ("1698.dwg" "1700.dwg" "1702.dwg" "1704.dwg" "1706.dwg" "1708.dwg"
    "0462.dwg"
    "0464.dwg" "0468.dwg" "0190.dwg" "0192.dwg" "0194.dwg" "0606.dwg" "0608.dwg"
    "0610.dwg" "0280.dwg" "2832.dwg" "2842.dwg" "1214.dwg" "0810.dwg" "1314.dwg"
    "1316.dwg" "1318.dwg" "1320.dwg" "1322.dwg" "1324.dwg" "1646.dwg" "1648.dwg"
    "1650.dwg" "2046.dwg" "2048.dwg" "2050.dwg" "0462.dwg" "0464.dwg" "0468.dwg"
    "0470.dwg" "0472.dwg")


    List 3 is the argument to pass to INSERT command.
    (setq INSRT (mapcar '(lambda (x) (strcat x "=")) lis2))...RETURNS
    ("1698=" "1700=" "1702=" "1704=" "1706=" "1708=" "0462=" "0464=" "0468="
    "0190=" "0192=" "0194=" "0606=" "0608=" "0610=" "0280=" "2832=" "2842="
    "1214="
    "0810=" "1314=" "1316=" "1318=" "1320=" "1322=" "1324=" "1646=" "1648="
    "1650="
    "2046=" "2048=" "2050=" "0462=" "0464=" "0468=" "0470=" "0472=")

    So if block is found in drawing and file is found, we use arg in list three
    with Insert command.
    (mapcar '(lambda (x y z)
    (if (and (tblobjname "block" z) (findfile x))
    (progn (command "._insert" y "0,0,0") (command)) <<<<COMMAND cancels
    insert after database is updated.
    )
    )
    check
    insrt
    lis2
    )

    Don Butler
     
    Don Butler, Oct 12, 2004
    #10
  11. Big 'D'

    James Allen Guest

    I haven't done anything with scripts, but are you making sure it is loaded
    in each current file before trying to use it. If that is not it try posting
    the portion of your script that loads the lisp and maybe someone can help.
     
    James Allen, Oct 13, 2004
    #11
  12. Big 'D'

    Rick Keller Guest

    I use this to insert a blank drawing that contains my default layers &
    dimstyles. I use this after I purge a drawing and need them back.
    It seems acad doesnt care if the block is there or not.
    Maybe I'm missing something in the way I use it but it works for me.

    (COMMAND "INSERT" "LA-DIM=//g12/support/template/LA-DIM.DWG" "0,0" "1" "1"
    "0")

    Rick


     
    Rick Keller, Oct 13, 2004
    #12
  13. That's what I showed you with the pure script version in my prior post.

    --
    R. Robert Bell


    This worked great, James. Any help on how I can run this from a script? I
    have a batch script and have set my lisp to automatically load when AutoCAD
    is started. The command to invoke this lisp (rep) is at the beginning of the
    batch script. The script stops after running the lisp
    ( message: Begin LISP
    Begin Command
    *error* Cancelled Command INSERT
    LISP Ended.
    I can types resume and the process will continue through the next file but,
    if I have to type this after every drawing I am defeating a part of the
    benefit of a batch script. Can you help?
     
    R. Robert Bell, Oct 13, 2004
    #13
  14. Big 'D'

    CAB2k Guest

    Rick
    IF you use this it will purge the block but leave the layers in the drawing.
    This is one line so when you paste it into a botton make sure ther are no ^M; added by ACAD.
    If your block dwg is in the ACAD path you don't need the path.
    ^C^C(COMMAND "INSERT" "LayerBlock=Layers-1story.DWG" "0,0" "1" "1" "0" "._erase" (entlast) "" "._purge" "B" "layerBlock" "N")
     
    CAB2k, Oct 14, 2004
    #14
  15. Big 'D'

    Rick Keller Guest

    Thanks...
    I'll try that.
    I have mine in a lisp routine.
    I dont like alot of buttons. (I'm a kb shortcut person).

    Rick
     
    Rick Keller, Oct 14, 2004
    #15
  16. Big 'D'

    CAB2k Guest

    You probably already know this
    (command "._insert" "LayerBlock=Layers-1story.DWG" "0,0" "1" "1" "0")
    (command "._erase" (entlast) "")
    (command "._purge" "B" "layerBlock" "N")
     
    CAB2k, Oct 15, 2004
    #16
  17. Big 'D'

    Rick Keller Guest

    Ya... I got it working.

    Thanks
    Rick
     
    Rick Keller, Oct 15, 2004
    #17
  18. Big 'D'

    Rick Keller Guest

    Ya.. I got it.

    I never even thought about deleting the block.

    Thanks
    Rick
     
    Rick Keller, Oct 15, 2004
    #18
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.