.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Double Click Block to return ID

11 REPLIES 11
Reply
Message 1 of 12
SRSDS
600 Views, 11 Replies

Double Click Block to return ID

Just thought I'd post this..

Arcticad gave me code to work out the right keywords to search for. The only google hit was a chinese website.

I added it to his/her code but didn't delete any of the existing handlers just in case.

 

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports AcApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.EditorInput
<Assembly: ExtensionApplication(GetType(VbExtApp))> 

Public Class VbExtApp
    Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

    Private DocMan As DocumentCollection

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

        DocMan = AcApp.DocumentManager

        AddHandler DocMan.DocumentCreated, AddressOf callback_documentCreated
        AddHandler DocMan.DocumentActivated, AddressOf callback_documentActivated

        Dim doc As Document
        For Each doc In DocMan
            Dim db As Database = doc.Database
            AddHandler db.ObjectModified, AddressOf callback_ObjectModified
            AddHandler db.ObjectAppended, AddressOf callback_ObjectAppended
            AddHandler db.ObjectErased, AddressOf callback_ObjectErased
            AddHandler Application.BeginDoubleClick, AddressOf callback_BeginDoubleClick
        Next
    End Sub
    'BeginDoubleClick
    Public Sub callback_BeginDoubleClick(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.ApplicationServices.BeginDoubleClickEventArgs)
        MsgBox("Double Click")
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim res As PromptSelectionResult = ed.SelectImplied()
        Dim ss As SelectionSet = res.Value
        If ss IsNot Nothing Then
            If ss.Count = 1 Then
                Using tr As Transaction = doc.TransactionManager.StartTransaction()
                    Dim br As BlockReference = DirectCast(tr.GetObject(ss(0).ObjectId, OpenMode.ForRead), BlockReference)
                    If br IsNot Nothing Then
                        DoubleClickBlock(br.ObjectId)
                    End If
                End Using
            End If
        End If
    End Sub

    'Terminate sub
    Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
        RemoveHandler DocMan.DocumentCreated, AddressOf callback_documentCreated
    End Sub

    Public Shared Sub callback_ObjectModified(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.DatabaseServices.ObjectEventArgs)
        'MsgBox("Something was modified")
        ID = e.DBObject.ObjectId
        ObjectModified(ID)
    End Sub


    Public Shared Sub callback_ObjectAppended(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.DatabaseServices.ObjectEventArgs)
        'MsgBox("Something was Appended")
    End Sub

    Public Shared Sub callback_ObjectErased(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.DatabaseServices.ObjectErasedEventArgs)
        'MsgBox("Something was Erased")
        ID = e.DBObject.ObjectId
        ObjectErased(ID)
    End Sub

    Private Sub callback_documentCreated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
        If e.Document = Nothing Then
            Exit Sub
        Else
            '   MsgBox("Document Created")
        End If

    End Sub

    Private Sub callback_documentActivated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
        If e.Document = Nothing Then
            Exit Sub
        Else
            '    MsgBox("Document Active")
        End If
    End Sub

End Class

 

 

 

 

 

 

11 REPLIES 11
Message 2 of 12
Hallex
in reply to: SRSDS

Just at the quick glance...

 

- - you have to add reference:

 

Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common

 

and also there is no Autodesk.AutoCAD.ApplicationServices.BeginDoubleClickEventArgs

this event is of AcadApplication, anyway I didn't see it in Intellisence drop-down

--  after adding references I showed above use simple BeginDoubleClickEventArgs instead

 

--  ID is not declared , the same with any subs:

ObjectErased(ID) &etc

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 12
SRSDS
in reply to: Hallex

Hi Hallex,

 I am a newb so bear with me.

 Took a while to find this but it does seem  to kick off the event and return an ID without the need for interop references

 Interop connects with 'old style' compentry? I don't know what interop means 😞

Message 4 of 12
SRSDS
in reply to: SRSDS

ID should be declared as ObjectID

I didn't include that.

 

Message 5 of 12
Hallex
in reply to: SRSDS

You have to add reference (References --> COM tab)

 

-- AutoCAD 2XXX Type Library

 

-- AutoCAD/ObjectDBX  Common 1X.X Type Library

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 6 of 12
Hallex
in reply to: SRSDS

Try this code

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 7 of 12
Jeff_M
in reply to: Hallex

Hallex, in AutoCAD 2010 and newer the BeginDoubleClickEvent is available in the .NET managed API, no need for the COM Interops anymore......

Jeff_M, also a frequent Swamper
EESignature
Message 8 of 12
Hallex
in reply to: Jeff_M

Thanks for info, Jeff,

I'm in A2009 yet

Can you provide the same way for 2010

(for one of friends of mine 🙂

Regards,

 

Oleg

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 9 of 12
Jeff_M
in reply to: Hallex

The code SRDS posted above should work ok, with the addition of Dim'ing ID As ObjectId.

Jeff_M, also a frequent Swamper
EESignature
Message 10 of 12
Hallex
in reply to: Jeff_M

Thanks,

Cheers 🙂

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 11 of 12
SRSDS
in reply to: Hallex

Thanks Hallex,

I probably should use your suggestion from the sounds of things. Some computers in our office do have pre 2010 installations. 

Message 12 of 12
Hallex
in reply to: SRSDS

Will be glad

Cheers 🙂

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost