Results 1 to 8 of 8

Thread: ObjectModified & Properties Palette & Dynamic Blocks

  1. #1
    Member
    Join Date
    2008-02
    Posts
    7
    Login to Give a bone
    0

    Default ObjectModified & Properties Palette & Dynamic Blocks

    When I get these three things together in the same room, they fight and fuss and cause trouble.

    I have the need to capture the change of a dynamic block's property such as Length (the property that stretches the block) when a user changes it using the built in AutoCAD 2008 Properties Palette.

    The code I run works fine when I want to change the object on the screen from edit mode, but when I change it using properties palette, it cycles through too many times, and the third time the DynamicPropertiesCollection shows up emtpy (or with error) in the locals window, and the system crashes on simply trying to read the property's value.

    The Object Modified event fires off for my watched block ref 3 times. First time the property reports no change. The second time the property shows the appropriate changed value. The third time AutoCAD crashes.

    Is there some way to either filter the object's properties or turn off or on events to get this to work? I am only responding to the ObjectModified event.

    Help!!

    Thanks,

    jamie

  2. #2
    I could stop if I wanted to
    Join Date
    2003-03
    Location
    Alberta
    Posts
    260
    Login to Give a bone
    0

    Default Re: ObjectModified & Properties Palette & Dynamic Blocks

    Not sure how you are capturing the change of the block. Are you using database events or something through the editor. Might what to watch the database.

  3. #3
    Member
    Join Date
    2008-02
    Posts
    7
    Login to Give a bone
    0

    Default Re: ObjectModified & Properties Palette & Dynamic Blocks

    Code:
    Private Sub callback_ObjectModified(ByVal sender As Object, ByVal e As ObjectEventArgs)
            If booIgnoreModified = True Then
                Return
            End If
            booIgnoreModified = True
            'Debug.Print(sender.ToString)
            Debug.Print("ObjectModified: " & e.DBObject.GetType.ToString)
            Select Case e.DBObject.GetType.ToString
                Case "Autodesk.AutoCAD.DatabaseServices.BlockReference"
                    'If e.DBObject.IsModified = False Then
                    Debug.Print("BlockReference")
                    Try
                        Dim objCheck As Object = Me.Levels.ContainsHandle(e.DBObject.Handle)
                        If objCheck(0) Then
                            Me.ReactToChange(objCheck)
                        End If
                    Catch ex As Exception
                        MsgBox("Error when running ObjectModified event: " & Err.Description)
                    End Try
                    'End If
            End Select
            booIgnoreModified = False
        End Sub
    Last edited by Opie; 2008-02-15 at 09:09 PM. Reason: [CODE] tags added, see Moderator Note

  4. #4
    I could stop if I wanted to
    Join Date
    2003-03
    Location
    Alberta
    Posts
    260
    Login to Give a bone
    0

    Default Re: ObjectModified & Properties Palette & Dynamic Blocks

    Quote Originally Posted by jamie.159739 View Post
    If booIgnoreModified = True Then
    Return
    End If
    Instead of doing the above try...
    Code:
    If e.DBObject.IsWriteEnabled Then Exit Sub
    If the object is opened for Write by one process it can not be opened for Write by another. Another operation could however open it for Read (at least that is my understanding).

    I might approach the problem diffrently then what you have shown. I'm not sure what your Levels.Contains returns but I would have it return a boolean. Also I understand that transactions are the way to go, don't know what happens in the call to ReactToChange(). Here is a sample of how I might have approached it (hasn't been tested).

    Code:
        Private Sub MyObjectModifiedCallback(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.DatabaseServices.ObjectEventArgs)
    
            If e.DBObject.IsWriteEnabled Then Exit Sub
            If Not Me.Levels.ContainsHandle(e.DBObject.Handle) Then Exit Sub
    
            Dim Trans As Transaction = e.DBObject.Database.TransactionManager.StartTransaction
            Try
                Dim ObjCheck As Object = Trans.GetObject(e.DBObject.Id, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
                Select Case ObjCheck.GetType.Name
                    Case GetType(Autodesk.AutoCAD.DatabaseServices.BlockReference).Name
                        Me.ReactToChange(ObjCheck)
                End Select
                Trans.Commit()
            Catch ex As Exception
                MsgBox("Error when running ObjectModified event. " & vbNewLine & ex.ToString)
            Finally
                Trans.Dispose()
            End Try
        End Sub

  5. #5
    Member
    Join Date
    2008-02
    Posts
    7
    Login to Give a bone
    0

    Default Re: ObjectModified & Properties Palette & Dynamic Blocks

    Thanks for your help, however...
    I added your line at top - If e.DBObject.IsWriteEnabled Then Exit Sub
    Immediate window:

    BlockReference
    PanelRef c1560e2c-de48-436c-840d-c38942c71e19
    BlockReference
    PanelRef c1560e2c-de48-436c-840d-c38942c71e19
    BlockReference
    PanelRef c1560e2c-de48-436c-840d-c38942c71e19
    A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in AcdbMgd.dll
    A first chance exception of type 'System.NullReferenceException' occurred in AcdbMgd.dll

    Still crashes. For some reason changing the dynamic property its the object modified 3 times or more (crashed on 3rd time). The exact missing data (null reference) is the dynamic property collection...

    The effect of crash is the combination of my ReactToChange and this object. In react to change I run this to get a dynamic property:

    Code:
        Public ReadOnly Property XDictionary(ByVal classID As Guid, ByVal strDictName As String) As DBDictionary
            Get
                Dim dbd As DBDictionary = Nothing
                Dim dbdColl As DBDictionary = Nothing
                Dim trans As Transaction = db.TransactionManager.StartTransaction
                Dim NOD As DBDictionary
                Dim dbdObjTree As DBDictionary
                Try 'to get existing Dictionary
                    NOD = trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead)
                    dbdObjTree = trans.GetObject(NOD.GetAt("srwlObjectTree"), OpenMode.ForRead)
                    dbdColl = trans.GetObject(dbdObjTree.GetAt(strDictName), OpenMode.ForRead)
                    If dbdColl.Contains(classID.ToString) Then
                        dbd = trans.GetObject(dbdColl.GetAt(classID.ToString), OpenMode.ForRead)
                    Else
                        NOD.UpgradeOpen()
                        dbdObjTree.UpgradeOpen()
                        dbdColl.UpgradeOpen()
                        dbd = New DBDictionary
                        dbdColl.SetAt(classID.ToString, dbd)
                        trans.AddNewlyCreatedDBObject(dbd, True)
                    End If
                    trans.Commit()
                Catch 'create a new Dictionary instead
                    MsgBox("Error creating a new " & strDictName & " Dictionary. " & Err.Description)
                Finally 'store a reference the dictionary in live memory
                    trans.Dispose()
                End Try
                Return dbd
            End Get
        End Property
    While running this, I am setting off the event again, but only for dynamic properties, not for other block properties. Any clue?

    Thanks,

    jamie

    Last edited by Opie; 2008-02-15 at 09:09 PM. Reason: [CODE] tags added, see Moderator Note

  6. #6
    Member
    Join Date
    2008-02
    Posts
    7
    Login to Give a bone
    0

    Default Re: ObjectModified & Properties Palette & Dynamic Blocks

    oops wrong code snippet:

    Code:
        Public Function GetDynProperty(ByVal bref As BlockReference, ByVal PropertyName As String) As Object
            Dim objProp As Object = Nothing
            Dim trans As Transaction = db.TransactionManager.StartTransaction
            Try
                Dim dpcPanel As DynamicBlockReferencePropertyCollection
                Dim dpPanel As DynamicBlockReferenceProperty
                If bref.IsDynamicBlock Then
                    dpcPanel = bref.DynamicBlockReferencePropertyCollection
                    For Each dpPanel In dpcPanel
                        Select Case dpPanel.PropertyName.ToUpper
                            Case PropertyName
                                objProp = dpPanel.Value
                                Exit For
                        End Select
                    Next
                End If
                'trans.Commit()
            Finally
                trans.Dispose()
            End Try
            Return objProp
        End Function
    Last edited by Opie; 2008-02-15 at 09:10 PM. Reason: [CODE] tags added, see Moderator Note

  7. #7
    I could stop if I wanted to
    Join Date
    2003-03
    Location
    Alberta
    Posts
    260
    Login to Give a bone
    0

    Default Re: ObjectModified & Properties Palette & Dynamic Blocks

    Maybe instead of trying to make calls from within the ObjectModified event add the modified objects to a list of sorts. When all objects have finished being modified iterate the list and check for objects with your custom data. I believe that do be a safer method.

  8. #8
    Member
    Join Date
    2008-02
    Posts
    7
    Login to Give a bone
    0

    Default Re: ObjectModified & Properties Palette & Dynamic Blocks

    Great Idea, but how do I know When all objects are done, in an Automatic environment. I don't want the user to have to press a 'calculate' button. I want calculations to take place automatically...

Similar Threads

  1. 2015: Block Authoring Palette (Dynamic blocks) Empty
    By derek.96018 in forum AutoCAD Customization
    Replies: 3
    Last Post: 2015-04-07, 08:07 PM
  2. Sharing Dynamic Blocks - Palette & Catalogue Issues
    By Warr_E_Er in forum Dynamic Blocks - Technical
    Replies: 7
    Last Post: 2014-08-13, 09:15 PM
  3. Match Properties of Dynamic Blocks
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2007-12-14, 09:13 PM
  4. Replies: 1
    Last Post: 2006-10-20, 08:19 PM
  5. Properties Palette - Global Scale for Blocks
    By ntaylor in forum AutoCAD Wish List
    Replies: 4
    Last Post: 2005-01-13, 09:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •