Insert Block from Remote File (Like Design Center)

Discussion in 'AutoCAD' started by James Upton, Feb 15, 2005.

  1. James Upton

    James Upton Guest

    Is there any way to insert a block from a remote file, like Design
    Center can? I'd like to incorporate this into a lisp routine.

    Note: I don't want to insert the whole file, just one block that is in
    the file. I asked in the regular AutoCAD group and no one could answer.
    If there isn't a way with lisp, would VBA work?

    Thanks,
    James
     
    James Upton, Feb 15, 2005
    #1
  2. James Upton

    Jeff Mishler Guest

    You can do this in either lisp or VBA using ObjectDBX. There have been a
    number of discussions on this and I have posted an Article outlining the use
    of ObjectDBX that may help you, in fact it uses the example of copying a
    block from a remote drawing to the current drawing.
    http://www.cadvault.com/forums/article.php?a=55
     
    Jeff Mishler, Feb 15, 2005
    #2
  3. Hi all,

    Jeff, I have read your article at CadVault, very interesting
    and it solves some doubts that I had.

    I will also want to ask you if you have found any aproach to solve the
    problem
    with the attributes, also I found that even if I don't modify the text
    position
    or alignment of the object but contents, if it is fit aligned, when I
    open the file it doesn't show OK.
    To solve this I move the block from
    0,0 to the same point, but if I do the same via
    Dbx it doesn´t work, do you know what else can I do?

    TIA

    Saludos

    Marco Jacinto
     
    Marco Jacinto, Feb 15, 2005
    #3
  4. James Upton

    Jeff Mishler Guest

    Marco, I'm glad you found the article useful.

    As for the attributes, I'm afraid that there is no easy workaround. Tony
    Tanzillo had provided a solution in his AcadX extension, but he has since
    stopped supporting or updating it. There have been a number of posts
    regarding this issue, and AFAIK there have been no other solutions.
     
    Jeff Mishler, Feb 15, 2005
    #4
  5. James Upton

    Jeff Mishler Guest

    Hi Luis,
    Yep, that's one of my 'good' hair days ;-)

    To insert a block with attributes is just a matter of inserting the block,
    retrieving the block's attributes and modifying each one with the data you
    want.
    Here's a snip from my title block insertion routine ......

    Code:
    ;;|Routine will automagically input values for attributes of a
    Title block that contains attributes with tagstrings of
    "NO", "SHEETS" & "SHEET_NAME" by using the Tab order number
    for the "NO" (sheet number), the total number of tabs minus 1 (the
    Model tab) for "SHEETS" (number of sheets), and the Tab name for the
    "SHEET_NAME"|;
    
    (if (not newblk)
    (setq newblk (vlax-invoke-method
    blk ;;this is the layout's block that I'm inserting to
    'insertblock
    (vlax-3d-point
    '(0.0 0.0 0.0))
    bname 1.0 1.0 1.0 0.0)
    )
    )
    (if (= (vla-get-hasattributes newblk) :vlax-true)
    (progn
    (setq atts (vlax-safearray->list
    (vlax-variant-value
    (vla-getattributes newblk))))
    (foreach att atts
    (setq tag (vla-get-tagstring att))
    (cond ((= tag "NO")
    (vla-put-textstring att (itoa (vla-get-taborder x))))
    ((= tag "SHEETS")
    (vla-put-textstring att (itoa (1- (vla-get-count lays)))))
    ((= tag "SHEET_NAME")
    (vla-put-textstring att (strcase (stripstr (vla-get-name x) "-"))))
    ((assoc tag attlist)
    (vla-put-textstring att (cdr (assoc tag attlist))))
    (t ;no default input, add marker text
    (vla-put-textstring att "????")
    )
    )
    )
    )
    )
    
    Is that what you were looking for?
     
    Jeff Mishler, Feb 15, 2005
    #5
  6. James Upton

    James Upton Guest

    That looks like what I need. The block name could be a variable that
    was previously defined correct? And how could I explode after insertion?

    Thanks,
    James
     
    James Upton, Feb 15, 2005
    #6
  7. James Upton

    Jeff Mishler Guest

    Luis, give me a bit and I'll look into this......
     
    Jeff Mishler, Feb 15, 2005
    #7
  8. James Upton

    Jeff Mishler Guest

    Yes, the block name can be a variable.... Once defined in the block table,
    insert using the InsertBlock method, then use the Explode method....but
    remember that ActiveX Explode creates new entites, just like the Explode
    command, but it leaves the original entity in place so you must delete it.

    Make sense? Or would you like some sample code?
     
    Jeff Mishler, Feb 15, 2005
    #8
  9. James Upton

    Jeff Mishler Guest

    Luis, how is Autocad crashing? Error messages?

    I just tested in R2002 using your code, but substituting my test files, and
    it ran fine. Is the DBX drawing already open by you or someone else?

    BTW, you have one line that is not needed with ODBX docs: (vla-update obj)
     
    Jeff Mishler, Feb 15, 2005
    #9
  10. Luis, vl-InsertBlock Method and ObjectDbx has a problem with the
    linetypes set to ByLayer, try changing them in the original drawing
    to ByBlock or other linetype and the problem will gone.

    Saludos

    Marco Jacinto
     
    Marco Jacinto, Feb 15, 2005
    #10
  11. James Upton

    Jeff Mishler Guest

    Marco, could you be more specific about this? I have not run into any
    problems with linetypes and ObjectDBX......

    Thanks,
     
    Jeff Mishler, Feb 15, 2005
    #11
  12. When I try to insert a file via ObjectDbx and vl-InsertBlock, if the file
    has the objects linetype
    set to Bylayer, the autocad crash when i open the file, with an error
    mesagge saying that linetype
    reference is missing or wrong.

    I will look for the code that causes the crash to try to explain myself
    better.
     
    Marco Jacinto, Feb 15, 2005
    #12
  13. Marco Jacinto, Feb 15, 2005
    #13
  14. James Upton

    Jeff Mishler Guest

    Heh, so much for my memory ;-) It looks like I found a solution to this back
    then :D

    And Luis, if you are following over here, I just ran an Audit on the new
    drawing...sure enough it found invalid linetypes. So I will ask you to check
    out my solution using CopyObjects.

    Now what was the name of those pills for improving memory retention?
     
    Jeff Mishler, Feb 15, 2005
    #14
  15. Thank you Marco,

    This is something strange, is the block does not have attributes it works just fine.

    For now I keeping this valuable information for later use.

    Gracias.
     
    Luis Esquivel, Feb 16, 2005
    #15
  16. I will, thank you Sir.

    I don't remember the name of that.... I just starting eating a lot of carrots.... they said that helps..... :)
     
    Luis Esquivel, Feb 16, 2005
    #16
  17. James Upton

    James Guest

    Ahh, the code doesn't actually insert the block, it just defines it in
    the block table. Makes sense. Can I use the regular -insert in the
    lisp to avoid the entity problem?
     
    James, Feb 16, 2005
    #17
  18. James Upton

    James Upton Guest

    I tested out the code as written (with changes to file and block name),
    and I get the following error:

    Automation Error. Problem in loading application

    I am using ADT 2005, and I checked an the ObjectDBX.AxDbDocument is
    already registered in my registry.

    What am I missing?

    Thanks,
    James

    Here is the code:

    (defun C:ib ()

    (setq dwgName "j:\\gp_adt\\gp standard.dwg")
    (setq dbxDoc (vla-GetInterfaceObject (vlax-get-acad-object)
    "ObjectDBX.AxDbDocument"))
    (vlax-invoke dbxDoc "Open" dwgName)

    (setq dbxBlocks (vla-get-blocks dbxDoc))
    (setq dbxBlock (vla-item dbxBlocks "A-1.1"))

    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (setq objArray
    (vlax-safearray-fill
    (vlax-make-safearray vlax-vbObject '(0 . 0)) (list dbxBlock)))
    (vla-CopyObjects dbxDoc objArray (vla-get-blocks doc) idpairs)

    (vlax-release-object dbxDoc)
    (setq dbxDoc nil)

    (princ)
    )
     
    James Upton, Feb 17, 2005
    #18
  19. James Upton

    Jürg Menzi Guest

    Hi James

    For 2k5 use "ObjectDBX.AxDbDocument.16"

    Cheers
     
    Jürg Menzi, Feb 17, 2005
    #19
  20. James Upton

    James Upton Guest

    Thanks. I read that the first time, and then forgot it when i actually
    wrote the code.
     
    James Upton, Feb 17, 2005
    #20
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.