insert block with attributes by user from VBA

Discussion in 'AutoCAD' started by MiD-AwE, Jan 10, 2005.

  1. MiD-AwE

    MiD-AwE Guest

    Before you decide to scold me, I must mention that I'm new to VBA yet learning quickly, and I've spent the last hour reading everything on this ng about blocks and attributes though I'm not understanding enough to answer my own question. OK, I have written a simple VBA proggie that gets information from user about what block that they'd like to insert to model space and then it should allow them to pre-answer attribute prompts (due to old block and new automation).
    ex. window pops-up and user chooses a block with 6 attributes all requiring PVC sizes to display in block. I then want to allow the user to define these PVC sizes. after which the user clicks <OK> and the block is inserted with all attribute prompts answered.

    I already tried ThisDrawing.SendCommand and just sent all string data to the command line separated by spaces but it doesn't work or maybe I'm just doing it wrong. I am now just inserting the block and then activating this LISP routine (COMMAND "DDATTE" "" "LAST")

    I got the impression from other topics on this ng that it is possible to send the ThisDrawing.SendCommand with the attributes already defined before the block is actually inserted or maybe I misunderstood that as well.

    Please, someone help by at least giving me some clue that I can read to better understand how I can do this. I'll post any code if necessary. Thanks, in advance.
     
    MiD-AwE, Jan 10, 2005
    #1
  2. Hi,

    For this exercise, forget the "Sendcommand" process. Use the APIs to add
    the blocks and populate the attributes.

    There is sample code for doing this supplied with the software, and you
    should find it quite straight forward to modify that code to suit your
    specific needs.

    If you have any queries from the sample code, then post again.

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au


    learning quickly, and I've spent the last hour reading everything on this ng
    about blocks and attributes though I'm not understanding enough to answer my
    own question. OK, I have written a simple VBA proggie that gets information
    from user about what block that they'd like to insert to model space and
    then it should allow them to pre-answer attribute prompts (due to old block
    and new automation).
    requiring PVC sizes to display in block. I then want to allow the user to
    the command line separated by spaces but it doesn't work or maybe I'm just
    doing it wrong. I am now just inserting the block and then activating this
    LISP routine (COMMAND "DDATTE" "" "LAST")
    send the ThisDrawing.SendCommand with the attributes already defined before
    the block is actually inserted or maybe I misunderstood that as well.
    better understand how I can do this. I'll post any code if necessary.
    Thanks, in advance.
     
    Laurie Comerford, Jan 11, 2005
    #2
  3. MiD-AwE

    Jeff Mishler Guest

    Here's a small code snippet that should get you pointed in the right
    direction, based on Laurie's suggestion:

    Code:
    Option Explicit
    
    Sub Example_InsertBlock()
    Dim insertionPnt(0 To 2) As Double
    Dim blockRef As AcadBlockReference
    Dim blockName As String
    Dim attRefs As Variant
    Dim attRef As AcadAttributeReference
    Dim I As Long
    
    blockName = "TDG" 'Change this to the block you want
    insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0#
    Set blockRef = ThisDrawing.ModelSpace.InsertBlock(insertionPnt,
    blockName, 1#, 1#, 1#, 0)
    
    If blockRef.HasAttributes = True Then
    attRefs = blockRef.GetAttributes
    For I = 0 To UBound(attRefs)
    Set attRef = attRefs(I)
    'do your stuff with the values here
    Next I
    End If
    End Sub
    
     
    Jeff Mishler, Jan 11, 2005
    #3
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.