Creating a macro to redefine a block

I am attempting to create a macro to automatically redefine a block.  This is in response to my decision to use a regular block as though it were an x-ref to avoid the layer name issue. [See the discussion "Managing a zillion tabs".]

To work on this macro, I first tried to do it from the command line. However, when I use the "-insert" command with the "~" command it does give me the dialog box, but if the block is an existing one, I am not prompted if I want to redefine the block.  Rather, it inserts the existing block and ignors the external file.

It has been well over a decade since I used this version of the command line for inserting a block, so my memory of how it should function may be faulty. But, if my memory is correct, then this is a bug.

Any work-arounds suggested to open a file dialog box and allow the user to select a block that will be automatcially redefined?

-Joe Dunfee

Comments

  • When I have done that in the past it worked by typing c:\(directory)\XXX, but as you say it just inserts the internal version.

    I had a lisp which added a directory to the block name to do it, looks like I modified it in mid 2009 to not bother. Now I just use it to quickly insert more of the same block.

    Can't remember if that worked in earlier Icad versions or only in Acad before that.

  • The more I think about it, the more I am sure it is a bug.  The ~ option should ask you if you want to redefine a block, if you choose a block that is already defined. I will report it to Bricsys through their support request page. I imagine few people use the command prompts any more, so few will notice this issue.

    Joe Dunfee

  • Yes it could not have been intended, there would be no way to replace a block from the command line if it was.

  • To redefine a block on the command line you can use this:

    : -INSERT
    ? to list blocks in drawing/~ to open the file dialog/<Block to insert> <000>: 000=d:\bKG_tmp\Testblocks\1\000.dwg
    The block 000 already exists. Do you want to redefine it? <N> y

    A lisp to do this:

    (defun c:DDRD () (c:DD_ReDefine))
    (defun c:DD_ReDefine ( / block file)
    (setvar 'cmdecho 0)
    (if (setq file (getfiled "Select dwg file" (getvar 'dwgprefix) "dwg" 0))
    (if (tblsearch "block" (setq block (vl-filename-base file)))
    (progn
    (command "_.-insert" (strcat block "=" file) "_yes")
    (command)
    (princ (strcat "\nBlock " block " has been redefined "))
    )
    (progn
    (command "_.-insert" file)
    (command)
    (princ (strcat "\nBlock " block " has been defined "))
    )
    )
    )
    (setvar 'cmdecho 1)
    (princ)
    )

    (princ "\nUse: DD_ReDefine or DDRD ")
    (princ)
  • Roy, have you tried it lately?

    Betcha the command line version doesn't ask if you want to replace it - because it picks the existing block within the file.

    My lisp like yours masks the question, so you don't know if it hasn't replaced the block unless you notice the block had not changed.

  • @John Gaunt: Yes I have tested this before posting. It works on 11.4.3 but also on previous BC10 and BC11 versions.

  • @John Gaunt: Note that I don't use the ~ option.

  • Thank you for the replies.  I attempted the command line version, but found that it interpreted the spaces in my path name as an "enter" key.  I am sure this is a limitation of the command line, since AutoCAD was written before file names allowed spaces.

    I recall that there was a way to get a DOS compatable version of a path when Microsoft first allowed long file names with spaces. However, that may no longer be an option, since it has been so many years ago.

    I just now tried the LISP, and it worked without a hitch.  Thank you very much Roy.

  • I beg your pardon Roy, I missed the 'blockname=' before c:\path\blockname. I'm sure that's not how it used to work and can't see the point of it. It's not even consistent with the way it works using the popup to insert blocks. If you went to the trouble of typing the full path to a file, it should be obvious to the program you didn't want the version much easier to dig out.

  • BTW: If the dwg file of the block is in the search path this will also redefine it:

    : -INSERT
    ? to list blocks in drawing/~ to open the file dialog/<Block to insert> <000>: 000=
    The block 000 already exists. Do you want to redefine it? <N> y

    @ John: I would agree that -insert with the '~' option should be compatible with the browse option of the 'normal' insert command.

This discussion has been closed.