Attributes Not Inserted Along with Block (VB6 and AutoCAD 2007)

Discussion in 'AutoCAD' started by Han, Jan 26, 2007.

  1. Han

    Han Guest

    I am programming in VB 6.0 and have a project referencing all available
    AutoCAD 2007 libraries. The routine I have inserts a drawing (symbol
    or block), which is NOT opened into another drawing, which is open.

    The issue is that the attributes are not inserted along with the block.
    I tried to use ".GetAttributes" of the inserted symbol in the opened
    drawing, but there are no attributes. I have stepped through the code
    and it inserts the block just fine. I have added "blockRefObj" to
    "Watches" while I step through; my code checks the proper block for
    attributes.

    I have read through most posts and searched the web, but there are only
    solutions for LISP. None for VB6. There was also advice (no code) for
    VBA, but it suggests inserting the block, then retrieving the
    attributes of that block (which would require opening the symbol in
    AutoCAD and getting the attributes), then editing the inserted block's
    attributes. This can't be the best way to solve the problem. I don't
    see a reason why the ".InsertBlock" wouldn't include attributes too.

    I don't have any experience with ObjectDBX, although I heard that was
    another solution to editing an object, but not opening it. Below is
    the code I have that does not transfer the attributes along with the
    insertion of the block. At the moment, it is simply to print out in
    the immediate window the attributes. Later, however, I will want to be
    able to edit these attributes.



    Private Sub BlockInsertion(strOptionName As String, strOptionType As
    String, _
    dblPosX As Double, dblPosY As Double, strSheet As String)

    Dim InsertionPoint(0 To 2) As Double
    Dim RotationAngle As Double
    Dim ScaleFactor As Double
    Dim blockRefObj As AcadBlockReference
    Dim acadApp As AutoCad.AcadApplication
    Dim acadDoc As AutoCad.AcadDocument
    Dim strCurrentFile As String
    Dim strDwgList As String
    Dim strBlockFile As String
    Dim atts As Variant, i As Long

    ' Block insertion information
    InsertionPoint(0) = 0
    InsertionPoint(1) = 0
    InsertionPoint(2) = 0
    ScaleFactor = 1
    RotationAngle = 0

    ' Block that will be inserted
    strBlockFile = "001_a.dwg"

    ' Open the drawing list
    strDwgList = "\\autocad\reqengr\" & strOptionType & "\dwg_list.txt"
    Open strDwgList For Input As #1

    ' Add the block to each drawing on the drawing list
    Do While Not EOF(1)
    Line Input #1, strCurrentFile
    Set acadApp = New AutoCad.AcadApplication
    acadApp.Visible = False
    Set acadDoc = acadApp.Documents.Open("\\autocad\reqengr\" _
    & OptType & strCurrentFile)
    Set blockRefObj = acadDoc.ModelSpace.InsertBlock(InsertionPoint, _
    "\\autocad\reqengr\Symbol_Repository\" & strBlockFile, _
    ScaleFactor, ScaleFactor, ScaleFactor, RotationAngle)
    atts = blockRefObj.GetAttributes
    ' Check all attributes
    For i = LBound(atts) To UBound(atts)
    Debug.Print atts(i).TextString
    Next
    acadDoc.Regen acActiveViewport
    acadDoc.Application.ZoomAll
    Set blockRefObj = Nothing
    Loop

    ' Close the file containing the list of drawings to modify.
    Close #1

    ' Close AutoCAD
    acadDoc.Close True
    acadApp.Quit

    End Sub
     
    Han, Jan 26, 2007
    #1
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.