Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
'////////////////////////////////////////////////////////////////////
'// Use: Jig a newly created block reference
'// Author: Philippe Leefsma, September 2011
'////////////////////////////////////////////////////////////////////
Public Class JigMsgFilter
Inherits EntityJig
Private _position As Point3d
Private _filter As JigFilter
Public Sub New(ByVal btrId As ObjectId)
MyBase.New(New BlockReference(Point3d.Origin, btrId))
_position = Point3d.Origin
_filter = New JigFilter
System.Windows.Forms.Application.AddMessageFilter(_filter)
End Sub
Public Overloads ReadOnly Property Entity() As BlockReference
Get
Return MyBase.Entity
End Get
End Property
Protected Overloads Overrides Function Update() As Boolean
Entity.Position = _position
Return True
End Function
Protected Overloads Overrides Function Sampler(ByVal prompts As JigPrompts) As SamplerStatus
Dim jigOpts As JigPromptPointOptions = New JigPromptPointOptions(vbCrLf + "Specify position: ")
jigOpts.UserInputControls = UserInputControls.NullResponseAccepted
Dim res As PromptPointResult = prompts.AcquirePoint(jigOpts)
If (res.Status <> PromptStatus.OK) Then
Return SamplerStatus.Cancel
End If
If (_position = res.Value) Then
Return SamplerStatus.NoChange
End If
_position = res.Value
Return SamplerStatus.OK
End Function
Public Function Run() As PromptStatus
Dim promptResult As PromptResult = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.Drag(Me)
Return promptResult.Status
End Function
'////////////////////////////////////////////////////////////
'// Use: Start Jig command
'//
'////////////////////////////////////////////////////////////
Public Shared Sub JigMsgFilter()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument()
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim res As PromptResult = ed.GetString(vbCrLf + "Enter block name to insert: ")
If res.Status <> PromptStatus.OK Then
Exit Sub
End If
Using Tx As Transaction = db.TransactionManager.StartTransaction()
Dim bT As BlockTable = Tx.GetObject(db.BlockTableId, OpenMode.ForRead)
If (Not bT.Has(res.StringResult)) Then
ed.WriteMessage(vbCrLf + "Block do not exist :(")
Exit Sub
End If
Dim btrId As ObjectId = bT(res.StringResult)
Dim jig As New JigMsgFilter(btrId)
If (jig.Run() <> PromptStatus.OK) Then
jig.Entity.Dispose()
Exit Sub
End If
Dim model As BlockTableRecord = Tx.GetObject(bT(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
model.AppendEntity(jig.Entity)
Tx.AddNewlyCreatedDBObject(jig.Entity, True)
Tx.Commit()
End Using
End Sub
End Class
'////////////////////////////////////////////////////////////
'// Use: Implementation of message filter
'//
'////////////////////////////////////////////////////////////
Public Class JigFilter
Implements IMessageFilter
Private WM_RIGHTCLICK As Integer = &H204
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements IMessageFilter.PreFilterMessage
If m.Msg = WM_RIGHTCLICK Then
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument()
Dim ed As Editor = doc.Editor()
ed.WriteMessage(vbCrLf + "Right Button pressed!!")
'Block message for AutoCAD
Return True
End If
Return False
End Function
End Class
http://adndevblog.typepad.com/autocad/2012/05/how-to-combine-a-net ... atch-user-input-such-as-right-click.html