Пример #1
0
        /// <summary>
        /// 为当前图形添加一个新的表格样式
        /// </summary>
        /// <param name="style"></param>
        /// <returns></returns>
        public static ObjectId AddTableStyle(string style)
        {
            ObjectId styleId; // 存储表格样式的Id
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Database db  = HostApplicationServices.WorkingDatabase;

            using (DocumentLock doclock = doc.LockDocument())
            {
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    // 打开表格样式字典
                    DBDictionary dict = (DBDictionary)db.TableStyleDictionaryId.GetObject(OpenMode.ForRead);
                    if (dict.Contains(style))        // 如果存在指定的表格样式
                    {
                        styleId = dict.GetAt(style); // 获取表格样式的Id
                    }
                    else
                    {
                        TableStyle ts = new TableStyle(); // 新建一个表格样式
                        // 设置表格所有行的外边框的线宽为0.30mm
                        ts.SetGridLineWeight(LineWeight.LineWeight030, (int)GridLineType.OuterGridLines, TableTools.AllRows);
                        // 不加粗表格表头行的底部边框
                        ts.SetGridLineWeight(LineWeight.LineWeight000, (int)GridLineType.HorizontalBottom, (int)RowType.HeaderRow);
                        // 不加粗表格数据行的顶部边框
                        ts.SetGridLineWeight(LineWeight.LineWeight000, (int)GridLineType.HorizontalTop, (int)RowType.DataRow);
                        // 设置表格中所有行的文本高度为1(默认)
                        ts.SetTextHeight(1, TableTools.AllRows);
                        // 设置表格中所有行的对齐方式为正中
                        ts.SetAlignment(CellAlignment.MiddleCenter, TableTools.AllRows);
                        dict.UpgradeOpen();//切换表格样式字典为写的状态

                        // 将新的表格样式添加到样式字典并获取其Id
                        styleId = dict.SetAt(style, ts);
                        // 将新建的表格样式添加到事务处理中
                        trans.AddNewlyCreatedDBObject(ts, true);
                        dict.DowngradeOpen();
                        trans.Commit();
                    }
                }
            }
            return(styleId); // 返回表格样式的Id
        }
Пример #2
0
        //为当前图形添加一个新的表格样式//CAD2010及以上版本可以用CAD2010版本以下的方法,但是不建议。
        public static ObjectId AddTableStyle(string style)
        {
            ObjectId styleId; // 存储表格样式的Id
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                // 打开表格样式字典
                DBDictionary dict = (DBDictionary)db.TableStyleDictionaryId.GetObject(OpenMode.ForRead);
                if (dict.Contains(style))        // 如果存在指定的表格样式
                {
                    styleId = dict.GetAt(style); // 获取表格样式的Id
                }
                else
                {
                    TableStyle ts = new TableStyle(); // 新建一个表格样式
                    // 设置表格的标题行为灰色
                    //ts.SetBackgroundColor(Color.FromColorIndex(ColorMethod.ByAci, 8), (int)RowType.TitleRow);
                    // 设置表格所有行的外边框的线宽为0.30mm
                    ts.SetGridLineWeight(LineWeight.LineWeight030, (int)GridLineType.OuterGridLines, TableTools.AllRows);
                    // 不加粗表格表头行的底部边框
                    ts.SetGridLineWeight(LineWeight.LineWeight000, (int)GridLineType.HorizontalBottom, (int)RowType.HeaderRow);
                    // 不加粗表格数据行的顶部边框
                    ts.SetGridLineWeight(LineWeight.LineWeight000, (int)GridLineType.HorizontalTop, (int)RowType.DataRow);
                    // 设置表格中所有行的文本高度为0.8
                    ts.SetTextHeight(2.5, TableTools.AllRows);
                    // 设置表格中所有行的对齐方式为正中
                    ts.SetAlignment(CellAlignment.MiddleCenter, TableTools.AllRows);
                    dict.UpgradeOpen();//切换表格样式字典为写的状态
                    // 将新的表格样式添加到样式字典并获取其Id
                    styleId = dict.SetAt(style, ts);
                    // 将新建的表格样式添加到事务处理中
                    trans.AddNewlyCreatedDBObject(ts, true);
                    trans.Commit();
                }
            }
            return(styleId); // 返回表格样式的Id
        }
Пример #3
0
        private void CreateTableStyle(string tableStyleName, string textStyleName, LineWeight lineWeight, out ObjectId tsObjID)
        {
            using (Transaction tr = m_db.TransactionManager.StartTransaction())
            {
                tsObjID = ObjectId.Null;
                DBDictionary dbDic = tr.GetObject(m_db.TableStyleDictionaryId, OpenMode.ForRead) as DBDictionary;
                if (dbDic.Contains(tableStyleName))
                {
                    tsObjID = dbDic.GetAt(tableStyleName);
                }
                else
                {
                    TableStyle newTs = new TableStyle();
                    TextStyleTable test = tr.GetObject(m_db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                    //if (test.Has(textStyleName))
                        //newTs.SetTextStyle(m_db.TextStyleTableId, textStyleName);
                    newTs.SetGridLineWeight(lineWeight, (int)GridLineType.AllGridLines, (int)GridLineType.AllGridLines);
                    tsObjID = newTs.PostTableStyleToDatabase(m_db, tableStyleName);
                    tr.AddNewlyCreatedDBObject(newTs, true);
                }

                tr.Commit();
            }
        }