Message 1 of 4
read anonymous blocks
Not applicable
10-23-2012
03:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have the follwoing error in C3D R2013.
Unable to cast object of type 'Autodesk.AutoCAD.DatabaseServices.BlockTableRecord' to type 'Autodesk.AutoCAD.DatabaseServices.BlockReference'.
When casting from a number, the value must be a number less than infinity
Make sure the source type is convertible to the destination type
My code is:
Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.LayerManager
Imports Autodesk.AutoCAD.Windows
Imports Autodesk.AutoCAD.PlottingServices
Imports Autodesk.AutoCAD.Colors
Imports Autodesk.Civil.DatabaseServices
Imports Autodesk.Civil.ApplicationServices
Imports Autodesk.Civil.DatabaseServices.LabelGroup
Imports Autodesk.Civil.DatabaseServices.Styles.LabelSetStylesRoot
Imports Autodesk.Civil.Runtime
Imports Excel = Microsoft.Office.Interop.Excel
Imports Microsoft.VisualBasic.FileIO.FileSystem
Imports System.IO
Imports System.Convert
Imports Microsoft.VisualBasic.Strings
Imports System.Runtime.InteropServices
Imports System.Collections.Specialized
...
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim btable As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
If btable.Has("vbredakdettek") Then
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(btable("vbredakdettek"), OpenMode.ForRead), BlockTableRecord)
For Each refId As ObjectId In btr.GetAnonymousBlockIds()
myBlock = DirectCast(tr.GetObject(refId, OpenMode.ForRead), BlockReference)
...