HELP NEEDED: How to insert a block from another drawing?

Discussion in 'AutoCAD' started by Dennis van Dongen, Dec 23, 2003.

  1. Hi all,

    Does anyone know how to insert a block from another drawing on this way;
    - I have a self made pull-down menu where i select a block name
    - There are several (4) drawings with lots of blocks in it where i want to
    call this block from
    - The drawings i make are most made with this blocks.

    I like to know how to create the command (in lisp or VBA) and also in the
    MNU file where i select the block from.
    I don't want to Bind all the drawings to the new drawing, because the file
    becomes very large after binding all blocks. Purging at close drawing is not
    the solution i want, because after that i need to bind all the drawings
    again.
    I only want to insert the blocks i realy need at the new drawing. The way i
    want it to be done this way, is because all these blocks need to be rebuild
    frequently, so its the easiest way to put these blocks on 1 drawing.

    The question is how to insert a block (example): BLOCKA
    into a new drawing, from the self made Pull-down menu
    From Drawing: LIBRARY_1.dwg

    Help appreciated.
    Dennis
     
    Dennis van Dongen, Dec 23, 2003
    #1
  2. Dennis van Dongen

    Jeff Guest

    here's a function you can place in a button macro that will allow you to add
    the block name and the drawing path that holds the block. There's one line
    in the file that you will need to adjust for whatever prompts you want
    answered in the "insert" command.

    Happy Holidays!
    Jeff

    ;| Import block from another drawing, block name and
    path\drawing are passed as arguments
    (imp_blk "blockname" "path\\tp\\blocks.dwg")
    Jeff Mishler, Dec. 23, 2003
    Check for ObjectDBX installation (portion) by R. Robert Bell
    |;

    (defun imp_blk (bname source / *acad* doc odbx Doctest
    blocks blist bimport)
    (vl-load-com)
    (if (not (tblsearch "block" bname))
    (progn
    (setq *acad* (vlax-get-acad-object)
    doc (vla-get-activedocument *acad*)
    )
    (vlax-for oDoc (vla-get-documents *acad*)
    (if (= (vla-get-fullname oDoc) source)
    (setq Doctest t)
    )
    )
    (if (not Doctest)
    (progn
    (if (> (atoi (getvar "AcadVer")) 15)
    (setq oDBX (vla-GetInterfaceObject
    *acad* "ObjectDBX.AxDbDocument.16"))
    (progn
    (if (not (vl-registry-read
    "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument\\CLSID"))
    (startapp "regsvr32.exe"
    (strcat "/s \"" (findfile "axdb15.dll") "\""))
    )
    (setq oDBX (vla-GetInterfaceObject
    *acad* "ObjectDBX.AxDbDocument"))
    );progn
    );if
    (vla-open oDBX source);; "opens" source for our use
    (setq blocks (vla-get-blocks oDBX));; source blocks table
    (if (> (vla-get-count blocks) 0);;ensure there are blocks to import
    (progn
    (setq blist (list (vla-item blocks bname))
    bimport (vlax-safearray-fill
    (vlax-make-safearray vlax-vbObject
    (cons 0 (- (length blist) 1))
    ) blist)
    );; create safearray for use in ActiveX method
    (vla-copyobjects oDBX bimport (vla-get-blocks doc))
    );progn
    );if
    (vlax-release-object oDBX);; we're done with it
    );progn
    (princ "\nYou entered a file in use by Autocad, please close and try
    again....")
    );if
    );progn
    );if
    (if (tblsearch "block" bname)
    (progn
    (setq oldecho (getvar "cmdecho"))
    (setvar "cmdecho" 1)
    (command "_-insert" bname pause pause pause)
    ;***** adjust above line to allow for required responses***
    (setvar "cmdecho" oldecho)
    );progn
    (princ "\nERROR in database, block not found!")
    );if
    (princ);; exit quietly
    );defun
     
    Jeff, Dec 23, 2003
    #2
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.