Author Topic: Transaction timing issues...  (Read 18728 times)

0 Members and 1 Guest are viewing this topic.

Stevray

  • Guest
Re: Transaction timing issues...
« Reply #15 on: March 12, 2013, 08:25:46 AM »
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. 

Code: [Select]
' (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.



WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Transaction timing issues...
« Reply #16 on: March 12, 2013, 11:35:06 AM »
I'm just about stumped.  If you watch your ram usage while this operation is happening does it go over about 1GB for acad.exe during the course of the transaction (that's about what I saw in my version)

Also, not sure how this might impact http://msmvps.com/blogs/carlosq/archive/2011/03/15/vs-2010-sp1-changing-quot-byval-quot-vb-net-code-editor-experience.aspx but in C# the default way to pass parameters into a subroutine is by ref, it appears vb.net is the opposite?

huiz

  • Swamp Rat
  • Posts: 917
  • Certified Prof C3D
Re: Transaction timing issues...
« Reply #17 on: March 12, 2013, 11:59:48 AM »
I'm just about stumped.  If you watch your ram usage while this operation is happening does it go over about 1GB for acad.exe during the course of the transaction (that's about what I saw in my version)

Also, not sure how this might impact http://msmvps.com/blogs/carlosq/archive/2011/03/15/vs-2010-sp1-changing-quot-byval-quot-vb-net-code-editor-experience.aspx but in C# the default way to pass parameters into a subroutine is by ref, it appears vb.net is the opposite?

with vb.net the default is by value. Isn't it the same with c#? I thought in C# the default is by value too.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Transaction timing issues...
« Reply #18 on: March 12, 2013, 12:10:00 PM »
Looking quickly in your Test sub you start a transaction that will "blanket" all other transactions and it is never committed, so will roll back all changes made in nested transaction

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Transaction timing issues...
« Reply #19 on: March 12, 2013, 12:13:26 PM »
I'm just about stumped.  If you watch your ram usage while this operation is happening does it go over about 1GB for acad.exe during the course of the transaction (that's about what I saw in my version)

Also, not sure how this might impact http://msmvps.com/blogs/carlosq/archive/2011/03/15/vs-2010-sp1-changing-quot-byval-quot-vb-net-code-editor-experience.aspx but in C# the default way to pass parameters into a subroutine is by ref, it appears vb.net is the opposite?

with vb.net the default is by value. Isn't it the same with c#? I thought in C# the default is by value too.

I was told it way by ref... After a look I think you're right... http://msdn.microsoft.com/en-us/library/0f66670z(v=vs.71).aspx
snap  :oops:

Stevray

  • Guest
Re: Transaction timing issues...
« Reply #20 on: March 12, 2013, 12:14:44 PM »
VB definitely passes byVal by default.  I had always believed that C# did too.  I have not done much programming in C# but I know from my days programming C++ on VAXes that it generally passes by value.

Does your C# version successfully set the Height and Width of all 1000 instances.  In all of the failures that I have seen, it was attempting to set a property value when if failed even though the code had found a non-empty DynamicBlockReferencePropertyCollection.  The failure was always in the line

prop.value - whatever.

Sometimes it would even successfully set the height for the current instance and then fail to set the width.  That is what got me thinking that it might be a multithreading timing issue and why I threw all those thread.sleep calls into the code.

Like you, I am totally stumped.

And, yes, I forgot to commit the single transaction but the program fails long before it would get to a commit anyway.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Transaction timing issues...
« Reply #21 on: March 12, 2013, 12:29:06 PM »
I'm just about stumped.  If you watch your ram usage while this operation is happening does it go over about 1GB for acad.exe during the course of the transaction (that's about what I saw in my version)

Also, not sure how this might impact http://msmvps.com/blogs/carlosq/archive/2011/03/15/vs-2010-sp1-changing-quot-byval-quot-vb-net-code-editor-experience.aspx but in C# the default way to pass parameters into a subroutine is by ref, it appears vb.net is the opposite?

with vb.net the default is by value. Isn't it the same with c#? I thought in C# the default is by value too.
Default behavior is By Value.
Seems confusion comes from when the argument is a reference a type, which can contain only 2 values null or the address of an object.

By default, a copy of the contents held by the argument are used and if it is a reference type you have access to same the object, which I think is where confusion comes in.

One way to see the difference is to set the argument to null or to point to different object and see how only when passed by reference will that change the original variable.

You will see books and other material still say by default C# passes objects by reference.
« Last Edit: March 12, 2013, 12:32:32 PM by Jeff H »

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Transaction timing issues...
« Reply #22 on: March 12, 2013, 12:33:49 PM »
Yeah, mine did set all the properties.  I'm curious, could you break the dictionary call out of the property setting loop.  Maybe then we can determine what about the data is invalid, or if the dictionary call is the source of the problem.
Something like:
Code - vb.net: [Select]
  1.                     For Each prop As DynamicBlockReferenceProperty In propColl
  2.                         If _propertyInfo.ContainsKey(prop.PropertyName) Then
  3.                             Dim value As double
  4.                             try
  5.                                   value = _propertyInfo(prop.PropertyName)
  6.                             Catch ex As System.Exception
  7.                                   Editor.WriteMessage("Failed to get {0} from dictionary", prop.PropertyName)
  8.                             End Try
  9.                             try
  10.                                   prop.Value = value
  11.                             Catch ex As System.Exception
  12.                                   Editor.WriteMessage("Failed to set {0} value: {1}", prop.PropertyName, value)
  13.                             End Try
  14.                         End If
  15.                     Next
  16.  
« Last Edit: March 12, 2013, 12:38:27 PM by WILL HATCH »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Transaction timing issues...
« Reply #23 on: March 12, 2013, 01:04:59 PM »
Works for me if I commit, and I changed the number to 500 instead so I did not have to wait, but when it is not commited it gets aborted and has to go back and undo all changes made. Link with more info
Code - C#: [Select]
  1.         <CommandMethod("Test")> Public Sub Test()
  2.             Dim XbyX As XbyXEndView
  3.             Dim point As New Point3d(0, 0, 0)
  4.             Dim offset As New Vector3d(2.5, 0, 0)
  5.             Dim num As Integer = 1
  6.             Dim acTransaction As Transaction = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()
  7.             Using acTransaction
  8.                 Try
  9.                     Dim acBlockTable As BlockTable = CType(acTransaction.GetObject(Application.DocumentManager.MdiActiveDocument.Database.BlockTableId, OpenMode.ForRead), BlockTable)
  10.                     Dim acModelSpace As BlockTableRecord = CType(acTransaction.GetObject(acBlockTable(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
  11.                     Do While num <= 500
  12.                         XbyX = New XbyXEndView(acBlockTable)
  13.                         XbyX.Height = 5.5
  14.                         XbyX.Width = 1.5
  15.                         XbyX.CreateReference(point, acModelSpace, acTransaction)
  16.                         num += 1
  17.                         point += offset
  18.                     Loop
  19.                 Catch ex As Autodesk.AutoCAD.Runtime.Exception
  20.                     AcadEditor.ReportError(ex)
  21.                 End Try
  22. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  23. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  24.                 acTransaction.Commit()''''''''''''''''''''''''Commit
  25. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  26. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  27.             End Using
  28.         End Sub

Stevray

  • Guest
Re: Transaction timing issues...
« Reply #24 on: March 12, 2013, 02:05:22 PM »
To Jeff H.

When I put the commit in it still fails randomly.  However, if I also set the Height to 3.5 so both the Height and Width are simply being set to the default value that the block has, it works fine.  However, what is the point of having a dynamic block if you can't set the properties to anything but their defaults?

What versions of acad, windows etc. are you running?

I am running Acad 2010 on a 64 bit quad-core Win7 machine.  Because I am running Acad 2010, i have to retarget the VB code from the Net Framework V4 to V3.5.

I would be interested to know whether you are running a newer version of AutoCad or are running a 32 bit version.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Transaction timing issues...
« Reply #25 on: March 12, 2013, 02:32:22 PM »
Your width and height properties are set to list.
Are you using values defined in the list?
That was my first thought would your problem could be but it looked liked you were setting them to values in the list.


Tested on Win 7, AutoCAD 2013, 64bit

TheMaster

  • Guest
Re: Transaction timing issues...
« Reply #26 on: March 12, 2013, 11:08:46 PM »
To Jeff H.

When I put the commit in it still fails randomly.  However, if I also set the Height to 3.5 so both the Height and Width are simply being set to the default value that the block has, it works fine.  However, what is the point of having a dynamic block if you can't set the properties to anything but their defaults?

What versions of acad, windows etc. are you running?

I am running Acad 2010 on a 64 bit quad-core Win7 machine.  Because I am running Acad 2010, i have to retarget the VB code from the Net Framework V4 to V3.5.

I would be interested to know whether you are running a newer version of AutoCad or are running a 32 bit version.

I haven't tried your code, so this is just guessing.

Since the problem is obviously that the DynamicBlockReferenceProperty is throwing eNotApplicable when you try to set the value, you need to put in some more comprehensive debugging code, like for example, when the exception is caught, you should capture the value that you tried to set the property to, and any previous values that were successfully set, along with the values of ALL properties of the DynamicBlockReferenceProperty instance that threw the exception, and dump everything to the console. You can use TypeDescriptor.GetProperties() to get the PropertyDescriptors for all properties of the DynamicBlockReferenceProperty and use them to get the values of the properties and dump them to the console.

That of course, requires that you wrap the line that assigns the property value in a Try/Catch so that the Catch block has access to all local variables.

Stevray

  • Guest
Re: Transaction timing issues...
« Reply #27 on: March 13, 2013, 11:36:46 AM »
Jeez, I haven't had this much fun since I spent 3 weeks pouring over a hex dump of memory trying to figure out why my program ABENDed with an error code of IBM911I.

For you youngsters, the made up word "ABEND" means "abnormally end".

To attempt to debug the abend code, one went to the IBM "Messages and Codes" manual which took an entire 3 foot shelf in the the key punch room.  If you have never had to enter a key punch room, thank the deity of your choice!

The entire entry in Messages and Codes for the error code IBM911I is "An error has occurred."

By the way, after spending those three weeks pouring over the memory dump, I never did find out why the program abended.  So, in absolute frustration, I ran it again and it worked just fine.  That's why I still remember the error code and description after thirty some years! Go figure!

At this point, I am giving up on the assumption that Autodesk's api has a bug in it and I will try to find a workaround.

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Transaction timing issues...
« Reply #28 on: March 13, 2013, 01:31:10 PM »
awww
I'm still curious what the result of breaking out the property assignment in a try catch block would have been  :-( I used the 2010 dynamic block api a bit and didn't come across any errors like this.

Stevray

  • Guest
Re: Transaction timing issues...
« Reply #29 on: March 13, 2013, 03:34:06 PM »
Dang!  I was hoping to put this behind me and get on with my life!

So, I added a try/catch block around the prop.value = whatever statement as in

Code: [Select]
   
                        Try
                                prop.Value = _propertyInfo(prop.PropertyName)
                            Catch ex As System.Exception
                                ExceptionDumper.Dump(prop, propColl, _propertyInfo, ex)
                                Throw New System.Exception("Failed to write dynamic block property value")
                            End Try

where ExceptionDumper is a purpose written bit of code that simply formats the data and dumps it to a file.  The result is

Code: [Select]
Dump of DynamicBlockReferenceCollection Follows

Name Height
Value 5.5
BlockID (8796088145280)
Description
Allowed Values System.Object[]
Type Code 1
ReadOnly False

Name Origin
Value (-0.000378755066321901,-0.00319671684420086,0)
BlockID (8796088145280)
Description
Allowed Values System.Object[]
Type Code 12
ReadOnly True

Name Width
Value 1.5
BlockID (8796088145280)
Description
Allowed Values System.Object[]
Type Code 1
ReadOnly False

Name Origin
Value (-0.000378755066321901,-0.00319671684420086,0)
BlockID (8796088145280)
Description
Allowed Values System.Object[]
Type Code 12
ReadOnly True

Dump of _propertyInfo Follows

Height 5.5
Width 1.5

Dump of the Top Level exception follows...

Message eAtMaxReaders
ErrorStatus AtMaxReaders
Source acdbmgd
TargetSite Void set_Value(System.Object)
StackTrace    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 117


So, the error code changes from eNotApplicable to eAtMaxReaders.  Anyone know what that means and how to get around it?

Frankly, AutoDesk's error handling sucks.  They might a well replace every error code with a simple "An error has occurred" and leave it at that.