Author Topic: [VB.NET] - Struggling with some code  (Read 4374 times)

0 Members and 1 Guest are viewing this topic.

Matt__W

  • Seagull
  • Posts: 12954
  • I like my water diluted.
Re: [VB.NET] - Struggling with some code
« Reply #15 on: December 09, 2011, 02:23:27 PM »
Of course not good coding practice hard-coding values, should be broken, etc...........
but here is some code to maybe get you started that just prints all the attribute reference's to the command line, and of course you need to change the drawing path.
 
Code: [Select]

         <CommandMethod("OpenDrawingInSideDatabase")> _
        Public Sub OpenDrawingInSideDatabase()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor

            Using sideDb As New Database(False, True)

                sideDb.ReadDwgFile("C:\Testing\AutoCAD\AttTest.dwg", FileOpenMode.OpenForReadAndAllShare, False, "")

                Using trx As Transaction = sideDb.TransactionManager.StartTransaction

                    Dim bt As BlockTable = trx.GetObject(sideDb.BlockTableId, OpenMode.ForRead)

                    For Each btrId As ObjectId In bt
                        Dim btr As BlockTableRecord = trx.GetObject(btrId, OpenMode.ForRead)

                        If btr.IsLayout Or btr.IsFromExternalReference Or btr.IsDependent Then
                            Continue For
                        End If

                        If btr.HasAttributeDefinitions Then

                            Dim brefIds As ObjectIdCollection = btr.GetBlockReferenceIds(True, False)

                            For Each brefId As ObjectId In brefIds

                                Dim bref As BlockReference = trx.GetObject(brefId, OpenMode.ForRead)

                                For Each attRefId As ObjectId In bref.AttributeCollection
                                    Dim attref As AttributeReference = trx.GetObject(attRefId, OpenMode.ForRead)
                                    ed.WriteMessage("{0}{1} = {2}{0}", Environment.NewLine, attRef.Tag, attRef.TextString)
                                Next

                            Next

                        End If

                    Next

                End Using
            End Using

        End Sub
I'll have to disect this next week.  Seems everybody wants everything NOW!!

Thanks!  :)
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io