Quantcast
Viewing all articles
Browse latest Browse all 14319

PointMonitorEventHandler Help

I have created a PointMonitorEventHandler to add additional info whenever the cursor is over a BlockReference, the Name, the number of inserts and also identify it when it is a dynamic block.  The code works most of the time, however sometimes is crashes as a lead balloon. I have no idia what is causing it to fail.  Someone please take a look at the code and see if you can help me find out where is the error or how to implement this handler properly.  I will really appreciate any help.  Thanks.  I am using AutoCAD 2012 Mechanical <Vanilla> on 64bit Windows 7.

 

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime<Assembly: ExtensionApplication(GetType(AutoCADPlugin.AppEventClass))> 
Public Class AppEventClass

    Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
	
Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize

	AddHandler Application.DocumentManager.DocumentCreated, AddressOf Me.DocumentCreated_Handler
	
End Sub
	
Private Sub DocumentCreated_Handler(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)

	AddHandler Application.DocumentManager.MdiActiveDocument.Editor.PointMonitor, New PointMonitorEventHandler(AddressOf Me.EditorPointMonitor_Handler)

End Sub
	
 Private Sub EditorPointMonitor_Handler(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.EditorInput.PointMonitorEventArgs)
        Dim anonymousIds As ObjectIdCollection
        Dim BlkRefs As ObjectIdCollection
        Dim fullpaths() As FullSubentityPath
        Dim BlkTblRec As BlockTableRecord
        Dim BlkName As String = ""
        Dim Blk As BlockReference
        Dim msg As String = ""
        Dim Total As Integer
        Dim value As Integer
        Dim Ent As Entity
        Dim id As ObjectId
        Dim idd As ObjectId

        Try

            Using trans = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction

                Using dlock = Application.DocumentManager.MdiActiveDocument.LockDocument

                    If Application.DocumentManager.MdiActiveDocument.Editor.IsQuiescent = False Then

                        Exit Sub

                    End If

                    Application.DocumentManager.MdiActiveDocument.Editor.TurnForcedPickOn()

                    fullpaths = e.Context.GetPickedEntities

                    If fullpaths.Length = 0 Then

                        Exit Sub

                    End If

                    Ent = trans.GetObject(fullpaths(0).GetObjectIds(0), OpenMode.ForRead)

                    If TypeOf Ent Is BlockReference Then

                        Blk = CType(Ent, BlockReference)

                        If Blk.IsDynamicBlock = True Then

                            BlkTblRec = CType(trans.GetObject(Blk.DynamicBlockTableRecord, OpenMode.ForRead), BlockTableRecord)

                            BlkName = BlkTblRec.Name

                            anonymousIds = BlkTblRec.GetAnonymousBlockIds

                            For Each id In anonymousIds

                                BlkTblRec = CType(trans.GetObject(id, OpenMode.ForRead), BlockTableRecord)

                                BlkRefs = BlkTblRec.GetBlockReferenceIds(False, False)

                                For Each idd In BlkRefs

                                    Total = Total + 1

                                Next

                            Next

                            msg = "Dynamic Block" & vbCrLf

                        Else

                            BlkName = Blk.Name

                            BlkTblRec = CType(trans.GetObject(Blk.BlockTableRecord, OpenMode.ForRead), BlockTableRecord)

                            BlkRefs = BlkTblRec.GetBlockReferenceIds(False, False)

                            Total = BlkRefs.Count

                        End If

                        value = CShort(Application.GetSystemVariable("ROLLOVERTIPS"))

                        If Not value = 0 Then

                            Application.SetSystemVariable("ROLLOVERTIPS", 0)

                        End If

                        msg = msg & String.Format("Block Name: {0}", BlkName) & vbCrLf

                        msg = msg & String.Format("Block Inserts: {0}", Total) & vbCrLf

                        e.AppendToolTipText(msg)

                        If Not value = 0 Then

                            Application.SetSystemVariable("ROLLOVERTIPS", value)

                        End If

                    End If

                    trans.Commit()

                End Using

            End Using

        Catch ex As Exception

            System.Windows.Forms.MessageBox.Show(ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Error)

        End Try

    End Sub
	
End Class

 

 

Here are the error message I am getting

 

Image may be NSFW.
Clik here to view.
PM_Error1.png

 

Image may be NSFW.
Clik here to view.
PM_Error2.png

 

Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 14319

Trending Articles