checking for block definition

Discussion in 'AutoCAD' started by yavid, Aug 12, 2004.

  1. yavid

    yavid Guest

    Can anyone help me write the code to check for a specific block definition? I need a lisp that will check a drawing to see if a block has been defined. If the block hasnt been defined the routine must then create it. Any help would be greatly appreciated.
     
    yavid, Aug 12, 2004
    #1
  2. yavid

    T.Willey Guest

    (if (not (tblsearch "block" "your block name"))
    (make block here)
    )
    This will see if the block is within the drawings database
    or
    (if (not (ssget "x" (list (cons 0 "INSERT") (cons 2 "your block name"))))
    (make block here)
    )
    This will test to see if the block is physically inserted into the drawing.

    Hope this helps
    Tim
     
    T.Willey, Aug 12, 2004
    #2
  3. I assume you don't need to have the block definition in the drawing except
    to Insert it. In that case, you could simply have that block (drawing)
    located somewhere in the support file search paths in Options, and plain old
    Insert it. If the block is already defined, it will use the definition
    that's in the drawing, and if it isn't, it will find the file and bring it
    in. That saves you the considerable hassle of creating the thing via lisp,
    and you don't need to check whether it's there already, or anything.

    Kent Cooper, AIA


    definition? I need a lisp that will check a drawing to see if a block has
    been defined. If the block hasnt been defined the routine must then create
    it. Any help would be greatly appreciated.
     
    Kent Cooper, AIA, Aug 12, 2004
    #3
  4. yavid

    yavid Guest

    Thanks everybody, with your help I was able to get the lisp working the way I needed it to.
     
    yavid, Aug 12, 2004
    #4
  5. yavid

    Tom Smith Guest

    I assume you don't need to have the block definition in the drawing except
    I agree. It wasn't really clear what the OP was after. Conversely, if there
    is a reason that the block needed to be created programmatically, rather
    than by inserting it, then you could just go ahead and do the entmake (or
    whatever) without checking for the definition first. Entmake will either
    create or update a block definition, so it doesn't matter whether it was
    already defined.
     
    Tom Smith, Aug 12, 2004
    #5
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.