Ejemplo n.º 1
0
        public void Screen()
        {
            using (var cad = new AutoCadConnector())
            {
                try
                {
                    AcadDocument doc = cad.Application.Documents.Open(FileFullName);
                    Scale = Convert.ToDouble(doc.GetVariable("DIMSCALE"));

                    var points = (double[])doc.Limits;

                    var width  = (int)Math.Ceiling((points[2] - points[0]) / Scale);
                    var height = (int)Math.Ceiling((points[3] - points[1]) / Scale);

                    //Console.WriteLine(@"file name:{0},GetPaperSize:{1}*{2}", FileShortName, w,h);
                    doc.Close(false, "");
                    Angle      = width > height ? 0 : 90;
                    Width      = width;
                    Height     = height;
                    PrintedNum = 0;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("调用CAD执行图纸筛选时时发生错误!\n错误描述:{0}", ex.Message), @"批量打印",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public static void Open(string filepath)
        {
            var cad = new AutoCadConnector();

            cad.Application.Documents.Open(filepath);
            cad.Application.Visible = true;
        }
Ejemplo n.º 3
0
 public void Open()
 {
     if (string.IsNullOrEmpty(FileFullName.Trim()))
     {
         var cad = new AutoCadConnector();
         cad.Application.Documents.Open(FileFullName);
         cad.Application.Visible = true;
     }
 }
Ejemplo n.º 4
0
        public void Screen()
        {
            //var startDate=DateTime.Now;
            using (AutoCadConnector cad = new AutoCadConnector())
            {
                int i = 1;
                foreach (CadPaper paper in this)
                {
                    try
                    {
                        //AcadDocument doc = cad.Application.Documents.Open(paper.FileFullName);
                        //paper.Scale = Convert.ToDouble(doc.GetVariable("DIMSCALE"));

                        //var points = (double[]) doc.Limits;

                        //var width = (int) Math.Ceiling((points[2] - points[0])/paper.Scale);
                        //var height = (int) Math.Ceiling((points[3] - points[1])/paper.Scale);

                        //doc.Close(false, "");
                        //paper.Angle = width > height ? 90 : 0;
                        //paper.Width = width;
                        //paper.Height = height;
                        //paper.PrintedNum = 0;

                        paper.Screen();
                        var args = new CadPaperProgressEventArgs
                        {
                            Count        = Count,
                            CurrentPoint = i++,
                            CurrentPaper = paper,
                            SenderMethod = CadPaperProgressSender.筛选
                        };
                        //Console.WriteLine(@"begin invoke OnCadPaperProgress ,id:{0},{1}",Thread.CurrentThread.ManagedThreadId,i);
                        OnCadPaperProgress(args);
                    }
                    catch (COMException ex)
                    {
                        MessageBox.Show(string.Format("调用CAD程序图幅筛选时出错!\n请先手工打开Autocad界面再尝试重新筛选!\n错误描述:{0}", ex.Message), @"CAD批量打印",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        OnCadPaperProgress(new CadPaperProgressEventArgs {
                            SenderMethod = CadPaperProgressSender.运行错误
                        });
                        break;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(string.Format("程序在图幅筛选时出错!\n错误描述:{0}", ex.Message), @"CAD批量打印",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        OnCadPaperProgress(new CadPaperProgressEventArgs {
                            SenderMethod = CadPaperProgressSender.运行错误
                        });
                        break;
                    }
                }
            }

            OnCadPaperProgress(new CadPaperProgressEventArgs {
                SenderMethod = CadPaperProgressSender.筛选完成
            });
            //Console.WriteLine(@"end invoke OnCadPaperProgress");
            //var endTime = DateTime.Now;
            //var n = endTime.Subtract(startDate).TotalSeconds;
            //Console.WriteLine(@"总共耗时:{0}",n);
        }
Ejemplo n.º 5
0
        public void Print()
        {
            using (var cad = new AutoCadConnector())
            {
                try
                {
                    AcadDocument doc    = cad.Application.Documents.Open(FileFullName);
                    AcadLayout   layout = doc.ModelSpace.Layout;

                    #region Autocad.Layout对象的属性及方法,主要用于打印输出

                    //Application
                    //Block
                    //CanonicalMediaName
                    //CenterPlot
                    //ConfigName
                    //Document
                    //GetCanonicalMediaNames
                    //GetLocaleMediaName
                    //GetPlotDeviceNames
                    //GetPlotStyleTableNames
                    //Handle
                    //HasExtensionDictionary
                    //ModelType
                    //Name
                    //ObjectID
                    //ObjectName
                    //OwnerID
                    //PaperUnits
                    //PlotHidden
                    //PlotOrigin
                    //PlotRotation
                    //PlotType
                    //PlotViewportBorders
                    //PlotViewportsFirst
                    //PlotWithLineweights
                    //PlotWithPlotStyles
                    //RefreshPlotDeviceInfo
                    //ScaleLineweights
                    //ShowPlotStyles
                    //StandardScale
                    //StyleSheet
                    //TabOrder
                    //UseStandardScale
                    //ViewToPlot

                    #endregion

                    //layout.RefreshPlotDeviceInfo();

                    //ConfigName    指定打印机配置名。用于布局或打印配置的 PC3 文件或打印设备的名称。
                    layout.ConfigName = PlotConfigName;

                    layout.StyleSheet = StyleSheet;

                    #region

                    /*
                     * //PlotType  指定布局或打印配置的类型。
                     * //acDisplay 打印当前显示的所有对象。
                     * //acExtents 打印当前选定空间范围内的所有对象。
                     * //acLimits 打印当前空间界限内的所有对象。
                     * //acView 打印在ViewToPlot属性中命名的视口。
                     * //acWindow 打印在SetWindowToPlot方法中指定的窗口中的所有对象。
                     * //acLayout 打印指定纸张尺寸边界内的所有对象,它的原点是由布局选项卡中从坐标(0,0)计算得到。该选项在从模型空间打印时不可用。
                     *
                     * */

                    #endregion

                    layout.PlotType = AcPlotType.acExtents;

                    //PlotWithPlotStyles:指定对象是按在打印样式文件中分配的配置打印,还是按图形文件中的配置打印。
                    layout.PlotWithPlotStyles = true;

                    //CanonicalMediaName    按名称指定图纸尺寸.String[字符串]; 可读写,图纸尺寸的名称
                    layout.CanonicalMediaName = CanonicalMediaName;
                    layout.PaperUnits         = AcPlotPaperUnits.acMillimeters;
                    layout.PlotOrigin         = new double[] { 0, 0 };
                    layout.UseStandardScale   = true;
                    layout.StandardScale      = AcPlotScale.acScaleToFit;
                    if (MapSheet == "A3" || MapSheet == "A4")
                    {
                        layout.PlotRotation = Angle == 0 ? AcPlotRotation.ac90degrees : AcPlotRotation.ac0degrees;
                    }
                    else
                    {
                        layout.PlotRotation = Angle == 90 ? AcPlotRotation.ac90degrees : AcPlotRotation.ac0degrees;
                    }
                    layout.RefreshPlotDeviceInfo();
                    double w, h;
                    layout.GetPaperSize(out w, out h);
                    Console.WriteLine(@"图幅:{0},{1}*{2}", CanonicalMediaName, w, h);

                    doc.Plot.PlotToDevice(null);
                    doc.Close(false);

                    PrintedNum++;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("调用CAD执行批量打印时发生错误!\n错误描述:{0}", ex.Message), @"批量打印",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw;
                }
            }
        }