예제 #1
0
        private void CopyOptions(SolidEdgeDraft.DraftPrintUtility draftPrintUtility, DraftPrintUtilityOptions options)
        {
            Type fromType = typeof(DraftPrintUtilityOptions);
            Type toType = typeof(SolidEdgeDraft.DraftPrintUtility);
            PropertyInfo[] properties = toType.GetProperties().Where(x => x.CanWrite).ToArray();

            // Copy all of the properties from DraftPrintUtility to this object.
            foreach (PropertyInfo toProperty in properties)
            {
                // Some properties may throw an exception if options are incompatible.
                // For instance, if PrintToFile = false, setting PrintToFileName = "" will cause an exception.
                // Mostly irrelevant but handle it as you see fit.
                try
                {
                    PropertyInfo fromProperty = fromType.GetProperty(toProperty.Name);
                    if (fromProperty != null)
                    {
                        object val = fromProperty.GetValue(options, null);

                        toType.InvokeMember(toProperty.Name, BindingFlags.SetProperty, null, draftPrintUtility, new object[] { val });

                    }
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
        private void CopyOptions(SolidEdgeDraft.DraftPrintUtility draftPrintUtility, DraftPrintUtilityOptions options)
        {
            Type fromType = typeof(DraftPrintUtilityOptions);
            Type toType   = typeof(SolidEdgeDraft.DraftPrintUtility);

            PropertyInfo[] properties = toType.GetProperties().Where(x => x.CanWrite).ToArray();

            // Copy all of the properties from DraftPrintUtility to this object.
            foreach (PropertyInfo toProperty in properties)
            {
                // Some properties may throw an exception if options are incompatible.
                // For instance, if PrintToFile = false, setting PrintToFileName = "" will cause an exception.
                // Mostly irrelevant but handle it as you see fit.
                try
                {
                    PropertyInfo fromProperty = fromType.GetProperty(toProperty.Name);
                    if (fromProperty != null)
                    {
                        object val = fromProperty.GetValue(options, null); //fromType.InvokeMember(toProperty.Name, BindingFlags.GetProperty, null, options, null);
                        toProperty.SetValue(draftPrintUtility, val, null);
                    }
                }
                catch
                {
                }
            }
        }
예제 #3
0
        void PrintInternal(string filename, DraftPrintUtilityOptions options)
        {
            SolidEdgeFramework.Application application = null;
            SolidEdgeFramework.Documents documents = null;
            SolidEdgeDraft.DraftDocument draftDocument = null;
            SolidEdgeDraft.DraftPrintUtility draftPrintUtility = null;

            try
            {
                // Register with OLE to handle concurrency issues on the current thread.
                SolidEdgeCommunity.OleMessageFilter.Register();

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

                // Make sure Solid Edge is visible.
                application.Visible = true;

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

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

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

                // 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();
                }

                SolidEdgeCommunity.OleMessageFilter.Register();
            }
        }
예제 #4
0
        void PrintInternal(string filename, DraftPrintUtilityOptions options)
        {
            SolidEdgeFramework.Application   application       = null;
            SolidEdgeFramework.Documents     documents         = null;
            SolidEdgeDraft.DraftDocument     draftDocument     = null;
            SolidEdgeDraft.DraftPrintUtility draftPrintUtility = null;

            try
            {
                // Register with OLE to handle concurrency issues on the current thread.
                SolidEdgeCommunity.OleMessageFilter.Register();

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

                // Make sure Solid Edge is visible.
                application.Visible = true;

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

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

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

                // 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();
                }

                SolidEdgeCommunity.OleMessageFilter.Register();
            }
        }
예제 #5
0
        private void buttonPrint_Click(object sender, EventArgs e)
        {
            // Not necessary but we'll later highlight each one as we print them.
            foreach (ListViewItem listViewItem in customListView.Items)
            {
                listViewItem.Selected = false;
            }

            // Loop through all of the files and print them.
            foreach (ListViewItem listViewItem in customListView.Items)
            {
                // GUI sugar.  Highligh the item.
                listViewItem.Selected = true;

                string filename = listViewItem.Text;
                DraftPrintUtilityOptions options = (DraftPrintUtilityOptions)listViewItem.Tag;

                //AppDomain interopDomain = null;

                try
                {
                    toolStripStatusLabel.Text = "Setting up an isolated application domation for COM Interop.";

                    toolStripStatusLabel.Text = String.Format("Printing '{0}' in isolated application.", filename);

                    using (var task = new IsolatedTask <BatchPrintTask>())
                    {
                        task.Proxy.Print(filename, options);
                    }

                    toolStripStatusLabel.Text = String.Empty;
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    listViewItem.Selected = false;
                }
            }

            toolStripStatusLabel.Text = String.Empty;
        }
        private void buttonPrint_Click(object sender, EventArgs e)
        {
            // Not necessary but we'll later highlight each one as we print them.
            foreach (ListViewItem listViewItem in customListView.Items)
            {
                listViewItem.Selected = false;
            }

            // Loop through all of the files and print them.
            foreach (ListViewItem listViewItem in customListView.Items)
            {
                // GUI sugar.  Highligh the item.
                listViewItem.Selected = true;

                string filename = listViewItem.Text;
                DraftPrintUtilityOptions options = (DraftPrintUtilityOptions)listViewItem.Tag;

                AppDomain interopDomain = null;

                try
                {
                    toolStripStatusLabel.Text = "Setting up an isolated application domation for COM Interop.";

                    var thread = new Thread(() =>
                    {
                        // Create a custom AppDomain to do COM Interop.
                        interopDomain = AppDomain.CreateDomain("Interop Domain");

                        Type proxyType = typeof(InteropProxy);

                        // Create a new instance of InteropProxy in the isolated application domain.
                        InteropProxy interopProxy = interopDomain.CreateInstanceAndUnwrap(
                            proxyType.Assembly.FullName,
                            proxyType.FullName) as InteropProxy;

                        toolStripStatusLabel.Text = String.Format("Printing '{0}' in isolated application.", filename);

                        // Start the printing process in the isolated application domain.
                        interopProxy.DoPrint(filename, options);
                    });

                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    thread.Join();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    listViewItem.Selected = false;

                    if (interopDomain != null)
                    {
                        // Unload the Interop AppDomain. This will automatically free up any COM references.
                        AppDomain.Unload(interopDomain);
                    }
                }
            }

            toolStripStatusLabel.Text = String.Empty;
        }
예제 #7
0
 public void Print(string filename, DraftPrintUtilityOptions options)
 {
     InvokeSTAThread<string, DraftPrintUtilityOptions>(PrintInternal, filename, options);
 }
예제 #8
0
 public void Print(string filename, DraftPrintUtilityOptions options)
 {
     InvokeSTAThread <string, DraftPrintUtilityOptions>(PrintInternal, filename, options);
 }