Beispiel #1
0
        private void Close(Param param)
        {
            GICO.WriteLine("OriginConnect: Closing Origin..");
            if (pOrigin != null)
            {
                pOrigin.Visible = MAINWND_VISIBLE.MAINWND_HIDE;
                pOrigin.Exit();


                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pOrigin);

                pWorksheet  = null;
                pGraphLayer = null;
                pDataPlot   = null;
                pOrigin     = null;

                //int hWnd = pOrigin.Application.Hwnd;

                //Force KILL
                //uint processID;
                //GetWindowThreadProcessId((IntPtr)hWnd, out processID);
                System.Diagnostics.Process[] procs = System.Diagnostics.Process.GetProcessesByName("Origin~1");
                foreach (System.Diagnostics.Process p in procs)
                {
                    //if (p.Id == processID)
                    p.Kill();
                }
            }
        }
Beispiel #2
0
        private void OpenSheet(Param param)
        {
            try
            {
                String strWkName = "ScatterData";
                pWorksheet = pOrigin.FindWorksheet(strWkName);
                if (pWorksheet == null) //if check don't exist, create workbook
                {
                    strWkName = (String)pOrigin.CreatePage((int)Origin.PAGETYPES.OPT_WORKSHEET, strWkName, "Origin", 2);
                }
                pWorksheet = (Worksheet)pOrigin.WorksheetPages[strWkName].Layers[0];

                //prepare XYZ column for putting data
                pWorksheet.Cols = 3;

                Column colA = pWorksheet.Columns[0];
                colA.Type = COLTYPES.COLTYPE_X;

                Column colB = pWorksheet.Columns[1];
                colB.Type = COLTYPES.COLTYPE_Y;

                Column colC = pWorksheet.Columns[2];
                colC.Type = COLTYPES.COLTYPE_Z;

                //prepare graph layer for plotting
                String strGrName = "3DScatterPlot"; //if check don't exist, create it.
                pGraphLayer = pOrigin.FindGraphLayer(strGrName);
                if (pGraphLayer == null)
                {
                    strGrName = (String)pOrigin.CreatePage((int)Origin.PAGETYPES.OPT_GRAPH, strGrName, "3D", 2); //3D scatter need "3D" template
                }
                pGraphLayer = (GraphLayer)pOrigin.GraphPages[strGrName].Layers[0];

                //parepare XYZDataRange
                DataRange drXYZ = pWorksheet.NewDataRange(0, 0, -1, -1);

                //plot 3D scatter on GraphLayer
                String strPlotName = "ScatterData_C"; //if exists, don't add new plot, plot name is related to workbook name and column name.

                pDataPlot = pGraphLayer.DataPlots[strPlotName];
                if (pDataPlot == null)
                {
                    pDataPlot = pGraphLayer.DataPlots.Add(drXYZ, PLOTTYPES.IDM_PLOT_3D_SCATTER);
                }

                //force axis rescale as auto to make plot visible
                pGraphLayer.Execute("layer.x.rescale=3");
                pGraphLayer.Execute("layer.y.rescale=3");
                pGraphLayer.Execute("layer.z.rescale=3");

                SentData(param);
            }
            catch (System.Exception ex)
            {
                String strMsg = ResourceException.Origin_FailedPlotting;
                GICO.WriteLine(strMsg);
                GICO.WriteLine(ex);
                throw;
            }
        }