Import/Export Block Table Properies Information

Import/Export Block Table Properies Information

Anonymous
Not applicable
3,257 Views
7 Replies
Message 1 of 8

Import/Export Block Table Properies Information

Anonymous
Not applicable

I am working with a set of dynamic blocks, each with a block table that provides a drop down for the user to alter attributes from.  My goal is to be able to update the block table using VBA to push data from an excel file.  I do have import/export code that will update block attributes, but I am not sure the functions that would access the table properties.  Any assistance would be greatly appreciated.

0 Likes
Accepted solutions (1)
3,258 Views
7 Replies
Replies (7)
Message 2 of 8

truss_85
Advocate
Advocate

If I missunderstood your goal please correct me. You want to import/export custom properties of your dynamic block like attributes. you can easly export custom property but import that properties depends on property is readonly or not. VBA does not that. In vb.net you will manage that.

0 Likes
Message 3 of 8

Anonymous
Not applicable

That is the basic gist.  To go into more detail:

 

If you enter block editor, the block has a table attached.  When the block is placed the table allows the engineer to select a part number (via a drop down) and auto fill in certain attributes based upon the data the table has defined in its columns.  The goal would be to use a master list to update that table (through scripting) as part numbers and vendors change at the end of the year/quarter as opposed to manually entering all the information block by block through the entire library.

 

The intention was to use VBA.  Is that not possible or only possible with .NET?  VB.NET would be fine as we use visual studio for other solutions.

 

Thank you for the reply truss.

 

Additional information:

AutoCAD 2010

Excel 2007

 

 

 

0 Likes
Message 4 of 8

truss_85
Advocate
Advocate

Yes, is it possible with .net. I suggested VB.net because it is a goog start for VBA user. It does not matter what the language is. Also anything is possible via .net. I do not know lisp very well, it might be a solution via lisp. But I strongly suggest .net.

 

Any time when you need help.

0 Likes
Message 5 of 8

Anonymous
Not applicable

Thank you for the help and letting me know that it is possible.

 

Would you happen to know a resource or location that I could find the command/call/function to get the block table data out or a piece of sample code to start?

 

0 Likes
Message 6 of 8

truss_85
Advocate
Advocate
Accepted solution

Any time you need help no problem.

 

Once I write a sub to get some attributes. You can modify it any other thing in block table record. Take a look at code at least you can start that way.

 

 

Public Sub SetAttribute(ByVal BlockID As Autodesk.AutoCAD.DatabaseServices.ObjectId, ByVal blckname As String, ByVal AttTag As String, ByVal AttVal As String)
        Dim MyDb As Database = Application.DocumentManager.MdiActiveDocument.Database
        If BlockID.IsNull Then Exit Sub
        Try
            Using myTrans As Transaction = MyDb.TransactionManager.StartTransaction
                Dim myBlckRef As BlockReference
                Dim myAttColl As AttributeCollection
                Dim myBlckTable As BlockTableRecord
                myBlckRef = BlockID.GetObject(OpenMode.ForWrite)
                If myBlckRef.IsDynamicBlock Then
                    myBlckTable = myTrans.GetObject(myBlckRef.DynamicBlockTableRecord, OpenMode.ForRead)
                Else
                    myBlckTable = myTrans.GetObject(myBlckRef.BlockTableRecord, OpenMode.ForRead)
                End If

                If String.Compare(myBlckTable.Name, blckname, True) = 0 Then
                    myAttColl = myBlckRef.AttributeCollection
                    Dim myEnt As Autodesk.AutoCAD.DatabaseServices.ObjectId
                    Dim myAttRef As Autodesk.AutoCAD.DatabaseServices.AttributeReference
                    For Each myEnt In myAttColl
                        myAttRef = myEnt.GetObject(OpenMode.ForWrite)
                        If String.Compare(myAttRef.Tag, AttTag, True) = 0 Then
                            myAttRef.TextString = AttVal.ToString
                        End If
                    Next
                End If
                myTrans.Commit()
            End Using
        Catch ex As Exception
        End Try
    End Sub

 

Also you can use that  >>link<< to get more information, documantation of SDK.

Message 7 of 8

Anonymous
Not applicable

Thank you very much for your help!!

 

0 Likes
Message 8 of 8

truss_85
Advocate
Advocate

I am glad to help.

Any time you need.

 

0 Likes