.NET

Reply
Valued Contributor
61 Posts
0 Kudos
Registered: ‎10-25-2005
Post 1 of 4

detect command execution .net

137 Views, 3 Replies
11-02-2005 04:40 AM
Hi,

I'm using VS 2003 .NET and the ObjectARX 2006 SDK to develop an application to Autocad 2006. I wonder if it's possible to detect whan the user run a command like offset, line, mirror, etc... When detect I whant to show a message with a question to the user and, depending on the answer (Yes or No), the command will continue or abort the command execution. I'm using VB to develop but I'm familiar with C# to.

Is this possible?

Thanks in advance for your attention. I'll be wating for an answer.


Regards,
Filipe Marcelino
Valued Contributor
61 Posts
0 Kudos
Registered: ‎10-25-2005
Post 2 of 4

Re: detect command execution .net

11-03-2005 02:05 AM in reply to: fmarcelino
Hi,

I already could figured out how to detect a command execution:

m_doc = Application.DocumentManager.MdiActiveDocument
Private Shared Sub m_doc_CommandWillStart(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.ApplicationServices.CommandEventArgs) Handles m_doc.CommandWillStart
Dim _frm As New frmChangeLayer
_frm.ShowDialog()
End Sub

'-----------------------------------------------------------------

Public Class frmChangeLayer
Inherits System.Windows.Forms.Form

'Initializes the combobox with a list of all layers existing
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Application.DocumentManager.MdiActiveDocument.LockDocument(DocumentLockMode.AutoWrite, Nothing, Nothing, True)
Dim curdb As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = curdb.TransactionManager
Dim myT As Transaction = tm.StartTransaction()
Try
Dim lt As LayerTable = CType(tm.GetObject(curdb.LayerTableId, OpenMode.ForRead), LayerTable)
For Each objId As ObjectId In lt
ComboBox1.Items.Add(CType(tm.GetObject(objId, OpenMode.ForRead), LayerTableRecord).Name)
Next
myT.Commit()
Catch ex As Exception
myT.Abort()
MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
myT.Dispose()
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager
Dim myT As Transaction = tm.StartTransaction()
Dim ExistingLayerId As ObjectId
Dim elt As LayerTable = CType(tm.GetObject(db.LayerTableId, OpenMode.ForWrite, False), LayerTable)
ExistingLayerId = elt.Item(ComboBox1.SelectedItem)
Dim curLay As ObjectId = db.Clayer
db.Clayer = ExistingLayerId
' Do something
db.Clayer = curLay
myT.Commit()
myT.Dispose()
Close()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Close()
End Sub

End Class

------------------------------------------------------------
This should work but what happends is, when I show my form (frmChangeLayer) the LayerManager is blocked. I think that's why my algorithm doesn't change current layer.

Does anyone knows a way to do this? Change the current layer before a command execution programmatically?

Regards,
Filipe Marcelino
New Member
2 Posts
0 Kudos
Registered: ‎08-03-2006
Post 3 of 4

Re: detect command execution .net

08-03-2006 12:55 PM in reply to: fmarcelino
You wrote:
"Application.DocumentManager.MdiActiveDocument.LockDocument(DocumentLockMode.Aut oWrite, Nothing, Nothing, True)"
that means locking the database by your current thread.
But I did not see unblock
It would look like:

Dim ld as DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument(DocumentLockMode.Aut oWrite, Nothing, Nothing, True)

ld.Dispose() '-- it will unlock the database,

I suggest you to try :-)
New Member
2 Posts
0 Kudos
Registered: ‎08-03-2006
Post 4 of 4

Re: detect command execution .net

08-03-2006 12:59 PM in reply to: fmarcelino
You may also see the extended sample at:
http://discussion.autodesk.com/servlet/JiveServlet/download/152-459176-5106557-102154/BoundingBox.txt

regards,
networker
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post