Ejemplo n.º 1
0
 /// <summary>
 /// 设置图例 当是圆时 width=0 length=R
 /// </summary>
 /// <param name="ColorIndex"></param>
 /// <param name="B_x"></param>
 /// <param name="B_y"></param>
 /// <param name="width"></param>
 /// <param name="length"></param>
 /// <param name="Wenzi"></param>
 /// <param name="acDoc"></param>
 /// <param name="acCurDb"></param>
 public static void AddTuli(int ColorIndex, double B_x, double B_y, double width, string Filltype, bool IFCircle, double length, string Wenzi, Document acDoc, Database acCurDb)
 {
     if (IFCircle == true)
     {
         WxxTU.AddCircleQuyu(ColorIndex, B_x, B_y, length, Filltype, acDoc, acCurDb);
     }
     else
     {
         WxxTU.AddQuYu(ColorIndex, B_x, B_y, width, length, Filltype, acDoc, acCurDb);
     }
     WxxTU.ObliqueText(Wenzi, 0, ColorIndex, B_x + 3, B_y - 3, 2, acDoc, acCurDb);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建布局和视口
        ///
        /// </summary>
        public static void CreateLayout(double[] B_Sta, Document doc, Database db)
        {
            //  var doc = Application.DocumentManager.MdiActiveDocument;

            if (doc == null)
            {
                return;
            }
            // var db = doc.Database;
            var ed     = doc.Editor;
            var ext    = new Extents2d();
            int k      = 0;// 100000 / 2600 / 3
            int zhushi = 0;
            //求布局数
            double Layoutnum = (B_Sta[B_Sta.Length - 1] - B_Sta[0]) / 350 / 3;

            for (int j = 0; j < Layoutnum + 1; j++)
            {
                using (var tr = db.TransactionManager.StartTransaction())
                {
                    //以读模式打开块表
                    BlockTable acBlkTbl;
                    acBlkTbl = tr.GetObject(db.BlockTableId,
                                            OpenMode.ForRead) as BlockTable;
                    //以写模式打开块表记录Paper空间
                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.PaperSpace],
                                               OpenMode.ForWrite) as BlockTableRecord;
                    //切换到Paper空间布局
                    Application.SetSystemVariable("TILEMODE", 0);
                    doc.Editor.SwitchToPaperSpace();

                    // Create and select a new layout tab
                    var id = LayoutManager.Current.CreateAndMakeLayoutCurrent("病害处理" + j);
                    // Open the created layout
                    var lay = (Layout)tr.GetObject(id, OpenMode.ForWrite);
                    // Make some settings on the layout and get its extents

                    /*     lay.SetPlotSettings(
                     *   //  "ISO_full_bleed_2A0_(1189.00_x_1682.00_MM)", // Try this big boy!
                     *     "ANSI_B_(11.00_x_17.00_Inches)",
                     *     "monochrome.ctb",
                     *     "DWF6 ePlot.pc3");*/
                    //从布局中获取PlotInfo
                    PlotInfo acPlInfo = new PlotInfo();
                    acPlInfo.Layout = lay.ObjectId;
                    //复制布局中的PlotSettings
                    PlotSettings acPlSet = new PlotSettings(lay.ModelType);
                    acPlSet.CopyFrom(lay);
                    //更新PlotSettings对象
                    PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
                    //设置打印区域
                    acPlSetVdr.SetPlotType(acPlSet,
                                           Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
                    //设置打印比例
                    acPlSetVdr.SetUseStandardScale(acPlSet, true);
                    acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit);
                    //居中打印
                    acPlSetVdr.SetPlotCentered(acPlSet, true);
                    ext = lay.GetMaximumExtents();
                    //绘制边框
                    //Create a polyline with two segments (3 points)
                    using (Autodesk.AutoCAD.DatabaseServices.Polyline acPoly = new Autodesk.AutoCAD.DatabaseServices.Polyline())

                    {
                        acPoly.AddVertexAt(0, new Point2d(0.2, 0.7), 0, 0, 0);
                        acPoly.AddVertexAt(1, new Point2d(0.2, ext.MaxPoint.Y - 0.3), 0, 0, 0);
                        acPoly.AddVertexAt(2, new Point2d(ext.MaxPoint.X - 0.13, ext.MaxPoint.Y - 0.3), 0, 0, 0);
                        acPoly.AddVertexAt(3, new Point2d(ext.MaxPoint.X - 0.13, 0.7), 0, 0, 0);
                        acPoly.AddVertexAt(4, new Point2d(0.2, 0.7), 0, 0, 0);
                        acPoly.LineWeight = LineWeight.LineWeight200;
                        //将新对象添加到块表记录和事务
                        acBlkTblRec.AppendEntity(acPoly);
                        tr.AddNewlyCreatedDBObject(acPoly, true);
                    }
                    //创建下方直线分隔
                    double[] Xiafangzuobiao = new double[] { 1.5, 4, 7, 7.5, 8.1, 8.6, 9.2, 9.7, 10.3, 10.8 };
                    for (int i = 0; i < Xiafangzuobiao.Length; i++)
                    {
                        WxxTU.Createline(acBlkTblRec, tr, Xiafangzuobiao[i], Xiafangzuobiao[i], 0.7, 1);
                    }
                    //创建下方需要填写的文字
                    string[] Xiafangwenzi        = new string[] { "路面病害处治设计图", "设计", "复核", "审核", "图号" };
                    double[] Xiafangwenzizuobiao = new double[] { 4.5, 7, 8.15, 9.2, 10.4 };
                    for (int i = 0; i < Xiafangwenzi.Length; i++)
                    {
                        //创建一个单行文字对象
                        using (DBText acText = new DBText())
                        {
                            acText.Position = new Point3d(Xiafangwenzizuobiao[i], 0.8, 0);
                            acText.Height   = 0.15;

                            acText.TextString = Xiafangwenzi[i];
                            acText.ColorIndex = 0;
                            //文字反向   acText.IsMirroredInX = false;
                            acText.Rotation = 0;
                            acBlkTblRec.AppendEntity(acText);
                            tr.AddNewlyCreatedDBObject(acText, true);


                            //释放DBObject对象
                        }
                    }
                    //创建上方直线分割
                    double[] Shangfangzuobiao = new double[] { 10, 10.8 };
                    for (int i = 0; i < Shangfangzuobiao.Length; i++)
                    {
                        WxxTU.Createline(acBlkTblRec, tr, Shangfangzuobiao[i], Shangfangzuobiao[i], ext.MaxPoint.Y - 0.3, ext.MaxPoint.Y - 0.65);
                    }
                    //创建上方需要填写的文字
                    string[] Shangfangwenzi = new string[] { "第" + j + "页", "共" + Math.Truncate(Layoutnum) + "页" };
                    for (int i = 0; i < Shangfangwenzi.Length; i++)
                    {
                        //创建一个单行文字对象
                        using (DBText acText = new DBText())
                        {
                            acText.Position = new Point3d(Shangfangzuobiao[i], ext.MaxPoint.Y - 0.5, 0);
                            acText.Height   = 0.15;

                            acText.TextString = Shangfangwenzi[i];
                            acText.ColorIndex = 0;
                            //文字反向   acText.IsMirroredInX = false;
                            acText.Rotation = 0;
                            acBlkTblRec.AppendEntity(acText);
                            tr.AddNewlyCreatedDBObject(acText, true);


                            //释放DBObject对象
                        }
                    }
                    //创建桩号起终点注释
                    double[] Sta_Y = new double[] { 2.75, 5, 7.1 };
                    for (int i = 0; i < 3; i++)
                    {
                        using (DBText acText = new DBText())
                        {
                            acText.Position = new Point3d(9, Sta_Y[i], 0);
                            acText.Height   = 0.15;

                            acText.TextString = WxxTU.Station_Double2Str(B_Sta[0] + 350 * (zhushi - 3)) + "-" + WxxTU.Station_Double2Str(B_Sta[0] + 350 * (zhushi - 2));
                            acText.ColorIndex = 0;
                            //文字反向   acText.IsMirroredInX = false;
                            acText.Rotation = 0;
                            acBlkTblRec.AppendEntity(acText);
                            tr.AddNewlyCreatedDBObject(acText, true);
                            zhushi++;

                            //释放DBObject对象
                        }
                    }

                    //创建多个视口
                    for (int i = 0; i < 3; i++)
                    {
                        lay.ApplyToViewport(
                            tr, i,
                            vp =>
                        {
                            // Size the viewport according to the extents calculated when
                            // we set the PlotSettings (device, page size, etc.)
                            // Use the standard 10% margin around the viewport
                            // (found by measuring pixels on screenshots of Layout1, etc.)

                            vp.ResizeViewport(ext, 0.8, 2 * i + 1, k);
                            k++;

                            /* // Adjust the view so that the model contents fit
                             * if (ValidDbExtents(db.Extmin, db.Extmax))
                             * {
                             *   vp.FitContentToViewport(new Extents3d(db.Extmin, db.Extmax),0.8);
                             * }
                             *
                             * // Finally we lock the view to prevent meddling*/


                            vp.Locked = true;
                        }
                            );
                    }
                    //  k++;

                    // Commit the transaction
                    tr.Commit();
                }
            }
            // Zoom so that we can see our new layout, again with a little padding

            /*    ed.Command("_.ZOOM", "_E");
             *  ed.Command("_.ZOOM", ".7X");
             *  ed.Regen();*/
        }