I have a vault job that starts inventor and autocad and converts drawings to pdf but the job runs it often fails because inventor isn't closing when the job is done. closing autocad is allways working? Does anyone have the same issues ? and can someone please help with a solution.
Regards Kent boettger
Here is the code i use to start inventor or get a running inventor.
Try INVRUNNING = True InvApp = GetObject(, "Inventor.Application") 'System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") InvApp.SilentOperation = True InvApp.Visible = True Catch ex As System.Exception If InvApp Is Nothing Then INVRUNNING = False Dim inventorApptype As Type = System.Type.GetTypeFromProgID("Inventor.Application") InvApp = System.Activator.CreateInstance(inventorApptype) InvApp.SilentOperation = True InvApp.Visible = True End If End Try
here is the code i use to kill the process. i think InvApp.quit() is the right way but this often fails.
If INVRUNNING = False Then 'InvApp.Quit() KILLINVENTOR() End If
here is the inventor killer that works. but this can not be the right way to end inventor?
Private Sub KILLINVENTOR() Dim pListOfProcesses() As Process Dim pInventorProcess As System.Diagnostics.Process pListOfProcesses = Process.GetProcessesByName("Inventor") For Each pInventorProcess In pListOfProcesses If pInventorProcess.ProcessName.ToUpper = "INVENTOR" Then pInventorProcess.Kill() End If Next End Sub
Just an idea: do you always restore SilentOperation = False mode, even in case of some error ?
Cheers,
Still no luck! getting inventor to quit without crash or hanging? if i use invapp.quit() only the kill function works.
Here is all the code i use to create a pdf file when a file i released in vault.
The code i run when a drawing is set to state release in vault.
The latest file is downloaded to a local folder and the fullpath of the file is passed to this sub. if the file is an inventor dwg. else it is passed to another sub
that creates the pdf in autocad.
Can somebody please take a look on this issue and help, maybe come upp with a solution.
Regards. Kent boettger.
Private Sub CreatePdfInventor(ByVal fullfilepath As String) Dim INVRUNNING As Boolean = False If System.IO.File.Exists(fullfilepath) = True Then 'Set local *.dwg file attributes else the program will fail System.IO.File.SetAttributes(fullfilepath, IO.FileAttributes.Normal) End If Dim InvApp As Inventor.Application = Nothing Try INVRUNNING = True InvApp = GetObject(, "Inventor.Application") 'System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") InvApp.Visible = True Catch ex As System.Exception INVRUNNING = False If INVRUNNING = False Then Dim inventorApptype As Type = System.Type.GetTypeFromProgID("Inventor.Application") InvApp = System.Activator.CreateInstance(inventorApptype) InvApp.Visible = True End If End Try 'Dim InvApp As Inventor.Application = GetObject(, "Inventor.Application") Dim oNVM As NameValueMap = InvApp.TransientObjects.CreateNameValueMap oNVM.Add("DeferUpdates", True) InvApp.SilentOperation = True Dim oDoc As Inventor.DrawingDocument = InvApp.Documents.OpenWithOptions(fullfilepath, oNVM, True) 'oApp.ActiveDocument InvApp.SilentOperation = False ' Get the PDF translator Add-In. Dim PDFAddIn As TranslatorAddIn PDFAddIn = InvApp.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") Dim oContext As TranslationContext oContext = InvApp.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism 'kFileBrowseIOMechanism ' Create a NameValueMap object Dim oOptions As NameValueMap oOptions = InvApp.TransientObjects.CreateNameValueMap ' Create a DataMedium object Dim oDataMedium As DataMedium oDataMedium = InvApp.TransientObjects.CreateDataMedium ' Check whether the translator has 'SaveCopyAs' options If PDFAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then 'Options for drawings... oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 1 'oOptions.Value("Vector_Resolution") = 400 'oOptions.Value("Sheet_Range") = kPrintAllSheets 'oOptions.Value("Custom_Begin_Sheet") = 2 'oOptions.Value("Custom_End_Sheet") = 4 Dim Pdf_File_Name As String Pdf_File_Name = oDoc.FullFileName.Substring(0, oDoc.FullFileName.Length - 4) 'Set the destination file name oDataMedium.FileName = (Pdf_File_Name & ".pdf") InvApp.SilentOperation = True 'Publish document. Call PDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium) 'Close document without saving oDoc.Close(True) InvApp.SilentOperation = False If INVRUNNING = False Then 'InvApp.Quit() KILLINVENTOR() End If End If End Sub
Similar problem was disscussed here:
Look at the following DevBlog as well:
http://adndevblog.typepad.com/manufacturing/2012/06/quitting-inventor-when-quit-doesnt.html
Cheers,