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

detect command execution .net

3 REPLIES 3
Reply
Message 1 of 4
fmarcelino
412 Views, 3 Replies

detect command execution .net

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
3 REPLIES 3
Message 2 of 4
fmarcelino
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
Message 3 of 4
networker
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 🙂
Message 4 of 4
networker
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

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