Esempio n. 1
0
        /// <summary>
        /// Asynchronous version of MainForm_Load.
        /// </summary>
        private void MainForm_Load_Async()
        {
            toolStripStatusLabel.Text = "Connecting to Solid Edge to get a copy of DraftPrintUtility settings.";

            SolidEdgeFramework.Application application = null;

            try
            {
                // Connect to or start Solid Edge.
                application = SolidEdgeUtils.Connect(true, true);

                // Minimize Solid Edge.
                //application.WindowState = (int)FormWindowState.Minimized;

                // Get a copy of the settings for use as a template.
                customListView._draftPrintUtilityOptions = new DraftPrintUtilityOptions(application);

                // Enable UI.
                toolStrip.Enabled      = true;
                customListView.Enabled = true;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (application != null)
                {
                    Marshal.ReleaseComObject(application);
                }
            }

            toolStripStatusLabel.Text = "Tip: You can drag folders and files into the ListView.";
        }
        public void DoPrint(string filename, DraftPrintUtilityOptions options)
        {
            SolidEdgeFramework.Application   application       = null;
            SolidEdgeFramework.Documents     documents         = null;
            SolidEdgeDraft.DraftDocument     draftDocument     = null;
            SolidEdgeDraft.DraftPrintUtility draftPrintUtility = null;

            // Copy all of the settings from DraftPrintUtilityOptions to the DraftPrintUtility object.
            CopyOptions(draftPrintUtility, options);

            OleMessageFilter.Register();

            try
            {
                // Connect to or start Solid Edge.
                application = SolidEdgeUtils.Connect(true);

                // Get a reference to the Documents collection.
                documents = application.Documents;

                // Get a reference to the DraftPrintUtility.
                draftPrintUtility = (SolidEdgeDraft.DraftPrintUtility)application.GetDraftPrintUtility();

                // Open the document.
                draftDocument = (SolidEdgeDraft.DraftDocument)documents.Open(filename);

                // Give Solid Edge time to process.
                application.DoIdle();

                // Add the draft document to the queue.
                draftPrintUtility.AddDocument(draftDocument);

                // Print out.
                draftPrintUtility.PrintOut();

                // Cleanup queue.
                draftPrintUtility.RemoveAllDocuments();
            }
            catch
            {
                throw;
            }
            finally
            {
                // Make sure we close the document.
                if (draftDocument != null)
                {
                    draftDocument.Close();
                }
            }
        }