protected void StartApplication() { Application.Run(); }
/// Insert Insight for Excel structure public static void SetInsightForExcelMolecule( int row, int col, MoleculeMx mol) { if (LogCalls) { DebugLog.Message("ExcelOp SetInsightForExcelMolecule " + row + ", " + col); } if (StructureInsertCount == 0) // check that AddIn is loaded { InsightForExcelAddInLoaded = LoadInsightForExcelAddIn(); if (!InsightForExcelAddInLoaded) { DebugLog.Message("Insight Chemistry AddIn failed to load"); } } StructureInsertCount++; try { if (MoleculeMx.IsUndefined(mol)) { return; } string molFile = mol.GetMolfileString(); if (!InsightForExcelAddInLoaded) { throw new Exception("Insight Chemistry AddIn failed to load"); } CellSelect(row, col); // outputCell string errorString = ""; bool returnStatus = false; string textFormat = "Automatic"; string macroPath = "InsightChemistry.xlam!IxlPutChemistryInCell"; // path to macro (don't use fullPath = XlApp.LibraryPath + @"\" + "InsightChemistry.xlam!IxlPutChemistryInCell") string fullPath = XlApp.LibraryPath + @"\" + macroPath; // (do not use full path) //if (StructureInsertCount == 2) throw new Exception("Test Exception"); // debug object ro = XlApp.Run( // call Insight macro directly (i.e. no added VBA macro in sheet) Macro: macroPath, Arg1: molFile, Arg2: XlRange, Arg3: errorString, Arg4: returnStatus, Arg5: textFormat); ReleaseObject(ro); return; } catch (Exception ex) { string msg = ex.Message; try { msg = "Insight for Excel Failed\r\n" + "Molecule: " + StructureInsertCount + ", Atoms: " + mol.AtomCount; XlSheet.Cells[row, col] = msg; } catch (Exception ex2) { ex2 = ex2; } throw new Exception(msg, ex); // throw exception so failure gets counted } }