Thank's Arnošt
My plugin is a activity control that counts the time used in the development of a project.
I using Win7 (64 Bits), Revit 2014, VB.Net 2012, access 2010 (64 bist)
i am open the document revit (*.rvt) from the revit api following this steps:
- create ribbon panel and pushBotton
- call a OpenFiledialog, select document revit (*.rvt) and open file
- capture the file name revit (.rvt) in the variable fileopened
- start the timer of my form frm_registro
if the user closed the document
5. stop timer
6. save value timer and file name revit in my data base access 2010 (64 Bits)
7. reset timer and emply the variable fileopened
this is my code for open file:
Public Function Execute(
ByVal commandData As ExternalCommandData,
ByRef message As String,
ByVal elements As ElementSet) _
As Result Implements IExternalCommand.Execute
Dim uiapp As UIApplication = commandData.Application
Dim uidoc As UIDocument = uiapp.ActiveUIDocument
Dim app As Autodesk.Revit.ApplicationServices.Application = uiapp.Application
Dim frm As New Frm_Registro
For Each Form In Windows.Forms.Application.OpenForms
If (Form.Name = "Frm_Registro") Then
frm = Form
End If
Next
frm.Show()
With frm.OpenFileDialog1
.Title = "DCV Consultores - Buscar Proyecto BIM"
.Filter = "Revit Files|*.rvt"
.RestoreDirectory = True
If frm.OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
uiapp.OpenAndActivateDocument(.FileName)
FileOpened = commandData.Application.ActiveUIDocument.Document.PathName()
Try
Dim FECHA As String = DateTime.Today
Dim HORA As String = Now.ToString("HH:mm:ss")
'Dim parteruta() As String = FileOpened.Split("\")
'Dim int As Integer = parteruta.LongLength
'codigo para separar la ruta del modelo central por \
Dim parteruta() As String = FileOpened.Split("\")
'contar cuantos segmentos hay en la variable cargada con la ruta del modelo central
Dim int As Integer = parteruta.LongLength - 1
cliente = parteruta(int - 4) ' asignando parte de la ruta (cliente) al txtcliente
proyecto = parteruta(int - 3) ' asignando parte de la cadena (proyecto) al txtproyecto
especialidad = parteruta(int - 2) ' asignando parte de la cadena (especialidad) al txtespecialidad
archivo = parteruta(int) ' asignando parte de la cadena (nombre archivo central) a la variable mod_local
conectarDB()
Dim comandos As New OleDbCommand
Dim sql As String = "insert into CONTROL_MODELO (USUARIO, CLIENTE, PROYECTO, ESPECIALIDAD, ARCHIVO, FECHA, HORA_INI, ACTIVIDAD, OBSERVACION)" _
& "VALUES (@USUARIO, @CLIENTE, @PROYECTO, @ESPECIALIDAD, @ARCHIVO, @FECHA, @HORA_INI, @ACTIVIDAD, @OBSERVACION)"
comandos = New OleDbCommand(sql, cn)
comandos.Parameters.AddWithValue("@USUARIO", Windows.Forms.SystemInformation.ComputerName & " - " & Windows.Forms.SystemInformation.UserName)
comandos.Parameters.AddWithValue("@CLIENTE", cliente)
comandos.Parameters.AddWithValue("@PROYECTO", proyecto)
comandos.Parameters.AddWithValue("@ESPECIALIDAD", especialidad)
comandos.Parameters.AddWithValue("@ARCHIVO", archivo)
comandos.Parameters.AddWithValue("@FECHA", FECHA)
comandos.Parameters.AddWithValue("@HORA_INI", HORA)
comandos.Parameters.AddWithValue("@ACTIVIDAD", 0)
comandos.Parameters.AddWithValue("@OBSERVACION", "")
comandos.ExecuteNonQuery()
Dim str As String = "SELECT MAX(ID_CONTROL) as ULT_NRO FROM CONTROL_MODELO"
Dim cmmd As New OleDbCommand(str, cn)
Dim id_avance As Integer = Convert.ToInt32(cmmd.ExecuteScalar())
CodigoControl = Convert.ToString(id_avance + 0)
MsgBox("Inicio de Actividad, el Modelo " & .SafeFileName & " se encuentra disponible", MsgBoxStyle.Information, "DCV Consultores")
frm.Iniciar_Timer()
'frm.ocultar()
Catch ex As Exception
MsgBox("Error: " & Err.Description, MsgBoxStyle.Critical, "DCV Consultores")
End Try
End If
End With
Return Result.Succeeded
End Function
End Class
this is my code when closed document
Private Sub DocumentClosing(sender As Object, e As Autodesk.Revit.DB.Events.DocumentClosingEventArgs)
If Not FileOpened = "" Then
Try
Dim frm As New Frm_Registro
frm.Show()
frm.Parar_timer()
Dim sql As String = "UPDATE CONTROL_MODELO SET ACTIVIDAD = '" & frm.txtactividad.Text & "' WHERE ID_CONTROL = " & CodigoControl & ""
' Dim sql As String = "UPDATE CONTROL_MODELO SET ACTIVIDAD = '" & Cronometro & "' WHERE ID_CONTROL = " & CodigoControl & ""
Dim comandos_up As New OleDb.OleDbCommand
comandos_up = New OleDb.OleDbCommand(sql, cn)
comandos_up.ExecuteNonQuery()
MessageBox.Show("Se esta cerrando el modelo " & FileOpened & ", " & frm.txtactividad.Text, "DCV Consultores", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
frm.Reset_timer()
frm.Close()
FileOpened = ""
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, "DCV Consultores")
End Try
End If
End Sub
this is the image the error

It's all the details of my application, il will use the documentclosed event following your recommendation.
thank you very much, i hope cant help me.
regards from Peru!!!!