I would like to thank everyone for their help. I am a newbie at programming AutoCAD (although I have been writing computer code since 1964 and VB code since version 1.0). Taking all of your comments into consideration, I have incorporated most of them into the test code shown below. Unfortunately it still fails, this time at insertion #171. After the code below is an error dump and I have attached a screen shot showing more of the error details as well.
' (C) Copyright 2013 by Don Stevens-Rayburn
'
Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
' This line is not mandatory, but improves loading performances
<Assembly: CommandClass(GetType(TestCode.TestClass))>
Namespace TestCode
Public Class TestClass
<CommandMethod("Test")> Public Sub Test()
Dim XbyX As XbyXEndView
Dim point As New Point3d(0, 0, 0)
Dim offset As New Vector3d(2.5, 0, 0)
Dim num As Integer = 1
Dim acTransaction As Transaction = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()
Using acTransaction
Try
Dim acBlockTable As BlockTable = CType(acTransaction.GetObject(Application.DocumentManager.MdiActiveDocument.Database.BlockTableId, OpenMode.ForRead), BlockTable)
Dim acModelSpace As BlockTableRecord = CType(acTransaction.GetObject(acBlockTable(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
Do While num <= 1000
XbyX = New XbyXEndView(acBlockTable)
XbyX.Height = 5.5
XbyX.Width = 1.5
XbyX.CreateReference(point, acModelSpace, acTransaction)
num += 1
point += offset
Loop
Catch ex As Autodesk.AutoCAD.Runtime.Exception
AcadEditor.ReportError(ex)
End Try
End Using
End Sub
End Class
Public Class XbyXEndView
Private Shared _parentBlockID As ObjectId = Nothing
Private _parentBlockName As String = "XbyX End View"
Private _acBlockReference As BlockReference = Nothing
Private _layer As String = "<use current>"
Private _rotation As Double
Private _scaleX As Double = 1.0
Private _scaleY As Double = 1.0
Private _scaleZ As Double = 1.0
Private _propertyInfo As New Dictionary(Of String, Double)
Public Sub New(ByVal bt As BlockTable)
If _parentBlockID = ObjectId.Null Then
If bt.Has(_parentBlockName) Then
_parentBlockID = bt(_parentBlockName)
End If
End If
End Sub
Public Property Width As Double
Get
If _propertyInfo.ContainsKey("Width") Then
Return _propertyInfo("Width")
Else
Return -1
End If
End Get
Set(value As Double)
If _propertyInfo.ContainsKey("Width") Then
_propertyInfo("Width") = value
Else
_propertyInfo.Add("Width", value)
End If
End Set
End Property
Public Property Height As Double
Get
If _propertyInfo.ContainsKey("Height") Then
Return _propertyInfo("Height")
Else
Return -1
End If
End Get
Set(value As Double)
If _propertyInfo.ContainsKey("Height") Then
_propertyInfo("Height") = value
Else
_propertyInfo.Add("Height", value)
End If
End Set
End Property
Public Sub CreateReference(Location As Point3d, blockTableRec As BlockTableRecord, acTransaction As Transaction)
If _acBlockReference = Nothing Then
Try
_acBlockReference = New BlockReference(Location, _parentBlockID)
Dim id As ObjectId = blockTableRec.AppendEntity(_acBlockReference)
If _acBlockReference.IsNewObject Then
acTransaction.AddNewlyCreatedDBObject(_acBlockReference, True)
End If
_acBlockReference.ScaleFactors = New Scale3d(_scaleX, _scaleY, _scaleZ)
If _layer <> "<use current>" Then
_acBlockReference.Layer = _layer
End If
_acBlockReference.Rotation = _rotation
Dim propColl As DynamicBlockReferencePropertyCollection = _acBlockReference.DynamicBlockReferencePropertyCollection
For Each prop As DynamicBlockReferenceProperty In propColl
If _propertyInfo.ContainsKey(prop.PropertyName) Then
prop.Value = _propertyInfo(prop.PropertyName)
End If
Next
Catch ex As System.Exception
Throw New System.Exception("Failed to insert block at " & Location.ToString, ex)
End Try
Else
Throw New System.Exception("Reference already created...")
End If
End Sub
End Class
Public Class AcadEditor
Public Shared Sub ReportError(ByVal ex As System.Exception)
Dim message As String = ex.Message & vbCrLf & vbCrLf & ex.StackTrace
message &= vbCrLf & vbCrLf & ex.Source
If ex.InnerException IsNot Nothing Then
message &= vbCrLf & vbCrLf & ex.InnerException.Message
End If
MsgBox(message, MsgBoxStyle.Critical, "Error")
End Sub
End Class
End Namespace
System.Exception: Failed to insert block at (427.5,0,0) ---> Autodesk.AutoCAD.Runtime.Exception: eNotApplicable
at Autodesk.AutoCAD.DatabaseServices.DynamicBlockReferenceProperty.set_Value(Object Value)
at TestCode.TestCode.XbyXEndView.CreateReference(Point3d Location, BlockTableRecord blockTableRec, Transaction acTransaction) in C:\Users\Don Stevens-Rayburn\Documents\Visual Studio 2010\Projects\TestCode\TestCode\TestClass.vb:line 113
--- End of inner exception stack trace ---
at TestCode.TestCode.XbyXEndView.CreateReference(Point3d Location, BlockTableRecord blockTableRec, Transaction acTransaction) in C:\Users\Don Stevens-Rayburn\Documents\Visual Studio 2010\Projects\TestCode\TestCode\TestClass.vb:line 117
at TestCode.TestCode.TestClass.Test() in C:\Users\Don Stevens-Rayburn\Documents\Visual Studio 2010\Projects\TestCode\TestCode\TestClass.vb:line 31
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5466 (Win7SP1GDR.050727-5400)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
----------------------------------------
acdbmgd
Assembly Version: 18.0.0.0
Win32 Version: 18.0.309.0.0
CodeBase: file:///C:/Program%20Files/AutoCAD%202010/AcdbMgd.DLL
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5467 (Win7SP1GDR.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
msvcm90
Assembly Version: 9.0.30729.6161
Win32 Version: 9.00.30729.6161
CodeBase: file:///C:/Windows/WinSxS/amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_08e61857a83bc251/msvcm90.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5467 (Win7SP1GDR.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
PresentationFramework
Assembly Version: 3.0.0.0
Win32 Version: 3.0.6920.5448 built by: Win7SP1GDR
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/PresentationFramework/3.0.0.0__31bf3856ad364e35/PresentationFramework.dll
----------------------------------------
WindowsBase
Assembly Version: 3.0.0.0
Win32 Version: 3.0.6920.5448 built by: Win7SP1GDR
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/WindowsBase/3.0.0.0__31bf3856ad364e35/WindowsBase.dll
----------------------------------------
PresentationCore
Assembly Version: 3.0.0.0
Win32 Version: 3.0.6920.5448 built by: Win7SP1GDR
CodeBase: file:///C:/Windows/assembly/GAC_64/PresentationCore/3.0.0.0__31bf3856ad364e35/PresentationCore.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
AdWindowsInterop
Assembly Version: 0.0.0.0
Win32 Version: 18.0.309.0.0
CodeBase: file:///C:/Program%20Files/AutoCAD%202010/AdWindowsInterop.DLL
----------------------------------------
AdWindows
Assembly Version: 2.1.0.0
Win32 Version: 2.1.123.309
CodeBase: file:///C:/Program%20Files/AutoCAD%202010/AdWindows.DLL
----------------------------------------
acmgd
Assembly Version: 18.0.0.0
Win32 Version: 18.0.309.0.0
CodeBase: file:///C:/Program%20Files/AutoCAD%202010/acmgd.DLL
----------------------------------------
System.Core
Assembly Version: 3.5.0.0
Win32 Version: 3.5.30729.5420 built by: Win7SP1
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
AcWindows
Assembly Version: 18.0.0.0
Win32 Version: 18.0.309.0.0
CodeBase: file:///C:/Program%20Files/AutoCAD%202010/AcWindows.DLL
----------------------------------------
AcWindows.resources
Assembly Version: 18.0.0.0
Win32 Version: 18.0.59.0.0
CodeBase: file:///C:/Program%20Files/AutoCAD%202010/en-US/AcWindows.resources.DLL
----------------------------------------
AcCui
Assembly Version: 18.0.0.0
Win32 Version: 18.0.309.0.0
CodeBase: file:///C:/Program%20Files/AutoCAD%202010/AcCui.DLL
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5468 (Win7SP1GDR.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
PresentationFramework.Aero
Assembly Version: 3.0.0.0
Win32 Version: 3.0.6920.4902 built by: NetFXw7
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/PresentationFramework.Aero/3.0.0.0__31bf3856ad364e35/PresentationFramework.Aero.dll
----------------------------------------
ContextualTabSelectorRules
Assembly Version: 0.0.0.0
Win32 Version: 18.0.309.0.0
CodeBase: file:///C:/Program%20Files/AutoCAD%202010/AcWindows.dll
----------------------------------------
ManagedMC3
Assembly Version: 2.20.0.0
Win32 Version: 3.14.1
CodeBase: file:///C:/Program%20Files/AutoCAD%202010/ManagedMC3.DLL
----------------------------------------
System.Web.Services
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Web.Services/2.0.0.0__b03f5f7f11d50a3a/System.Web.Services.dll
----------------------------------------
AcLayer
Assembly Version: 18.0.0.0
Win32 Version: 18.0.309.0.0
CodeBase: file:///C:/Program%20Files/AutoCAD%202010/AcLayer.DLL
----------------------------------------
AcLayer.resources
Assembly Version: 18.0.0.0
Win32 Version: 18.0.59.0.0
CodeBase: file:///C:/Program%20Files/AutoCAD%202010/en-US/AcLayer.resources.DLL
----------------------------------------
WindowsFormsIntegration
Assembly Version: 3.0.0.0
Win32 Version: 3.0.6920.4902 built by: NetFXw7
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/WindowsFormsIntegration/3.0.0.0__31bf3856ad364e35/WindowsFormsIntegration.dll
----------------------------------------
bqzzon_n
Assembly Version: 2.1.0.0
Win32 Version: 2.0.50727.5467 (Win7SP1GDR.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
UIAutomationProvider
Assembly Version: 3.0.0.0
Win32 Version: 3.0.6920.4902 built by: NetFXw7
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/UIAutomationProvider/3.0.0.0__31bf3856ad364e35/UIAutomationProvider.dll
----------------------------------------
Accessibility
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Accessibility/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
TestCode
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/Don%20Stevens-Rayburn/Documents/Visual%20Studio%202010/Projects/TestCode/TestCode/bin/Debug/TestCode.dll
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
Microsoft.VisualStudio.Debugger.Runtime
Assembly Version: 10.0.0.0
Win32 Version: 10.0.30319.1
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualStudio.Debugger.Runtime/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Debugger.Runtime.dll
----------------------------------------
************** JIT Debugging **************
Application does not support Windows Forms just-in-time (JIT)
debugging. Contact the application author for more
information.