VBA BEGINNER

Discussion in 'AutoCAD' started by johnbortoli, Jul 3, 2003.

  1. johnbortoli

    johnbortoli Guest

    am wanting to get a program which will allow me to input information from a user form and then use the information either selected or input by user and insert it as attributes in ablock so that i can later extract the attributes to an excel spread sheet can any one help me with code or possible help
     
    johnbortoli, Jul 3, 2003
    #1
  2. Hi John,

    Look in the help files. There is sample code there for everything you have
    mentioned.

    Andrew Roe's book "Using Visual Basic with AutoCAD" is also very helpful for
    a beginner. I doubt if I could have got started any where near as quickly
    without it.

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au


    a user form and then use the information either selected or input by user
    and insert it as attributes in ablock so that i can later extract the
    attributes to an excel spread sheet can any one help me with code or
    possible help
     
    Laurie Comerford, Jul 3, 2003
    #2
  3. johnbortoli

    johnbortoli Guest

    thanks laurie,
    thats fine i have searched the help file and utilised them and i am able to create ablock now with one atribute but i need at least seven attributes in my block. Using the define an attribute definition sample code and adding further attributes it only creates the last attribute listed in my code. How do i get multiple attributes. here is asample of my code
    Sub Ch10_CreatingAnAttribute()
        ' Define the block
        Dim blockObj As AcadBlock
        Dim insertionPnt(0 To 2) As Double
        insertionPnt(0) = 0
        insertionPnt(1) = 0
        insertionPnt(2) = 0
        Set blockObj = ThisDrawing.Blocks.Add _
                         (insertionPnt, "cable")

    ' Add an attribute to the block
        Dim attributeObj As AcadAttribute
        Dim height As Double
        Dim mode As Long
        Dim prompt As String
        Dim insertionPoint(0 To 2) As Double
        Dim tag As String
        Dim value As String
        height = 250
        mode = acAttributeModeVerify
        prompt = "tendon-id"
        insertionPoint(0) = 5
        insertionPoint(1) = 5
        insertionPoint(2) = 0
        tag = "ID"
        value = "="
        mode = acAttributeModeVerify
        prompt = "No-Strands"
        insertionPoint(0) = 10
        insertionPoint(1) = 10
        insertionPoint(2) = 0
        tag = "strands"
        value = "-"
        mode = acAttributeModeVerify
        prompt = "Anchor Block"
        insertionPoint(0) = 15
        insertionPoint(1) = 15
        insertionPoint(2) = 0
        tag = "anchor"
        value = "-"
        height = 250
        mode = acAttributeModeInvisible
        prompt = "Coupler"
        insertionPoint(0) = 20
        insertionPoint(1) = 20
        insertionPoint(2) = 0
        tag = "coupler"
        value = "+"
        mode = acAttributeModeVerify
        prompt = "Dead (swage/onion)"
        insertionPoint(0) = 25
        insertionPoint(1) = 25
        insertionPoint(2) = 0
        tag = "dead"
        value = "-"
        mode = acAttributeModeVerify
        prompt = "Pocket (No off)"
        insertionPoint(0) = 30
        insertionPoint(1) = 30
        insertionPoint(2) = 0
        tag = "pocket"
        value = "-"
        mode = acAttributeModeVerify
        prompt = "tendon Length"
        insertionPoint(0) = 35
        insertionPoint(1) = 35
        insertionPoint(2) = 0
        tag = "length"
        value = "-"
        Set attributeObj = blockObj.AddAttribute(height, mode, _
                              prompt, insertionPoint, tag, value)
        ' Insert the block, creating a block reference
        ' and an attribute reference
        Dim blockRefObj As AcadBlockReference
        insertionPnt(0) = 2
        insertionPnt(1) = 2
        insertionPnt(2) = 0
        Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock _
                   (insertionPnt, "cable", 1#, 1#, 1#, 0)
        ' Get the attributes for the block reference
        Dim varAttributes As Variant
        varAttributes = blockRefObj.GetAttributes

    ' Move the attribute tags and values into a
        ' string to be displayed in a Msgbox
        Dim strAttributes As String
        strAttributes = ""
        Dim I As Integer
        For I = LBound(varAttributes) To UBound(varAttributes)
            strAttributes = strAttributes + " Tag: " + _
                        varAttributes(I).TagString + vbCrLf + _
                        " Value: " + varAttributes(I).TextString
        Next
        MsgBox "The attributes for blockReference " + _
                       blockRefObj.Name & " are: " & vbCrLf _
                       & strAttributes



    End Sub
     
    johnbortoli, Jul 4, 2003
    #3
  4. johnbortoli

    Jeff Mishler Guest

    John,
    You were creating the BlockDataBase info. and that is only done once. You
    now need to create individual inserts - "AcadBlockReference" - to actually
    use in the drawing....using basically the code you had in your first post,
    including this and the code after:
    HTH,
    Jeff

    macro it creates my block now with all attributes but if i run it a second
    time it updates the existing block and adds another set of duplicate
    attributes. As i need to be able to have this block up to 100 times in the
    same drawing how do i get it to create a new instance of the blockrather
    than add new attributes for each new location required for the block. The
    attribute information will eventually be used as a materials summary so i
    need multiple instances of the block created
     
    Jeff Mishler, Jul 8, 2003
    #4
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.