Beispiel #1
0
        getTextStyleTableRecord(string name)
        {
            TextStyleTableRecord tstr = null;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    TextStyleTable tst = getTextStyleTable();
                    if (tst.Has(name) == true)
                    {
                        tstr = (TextStyleTableRecord)tr.GetObject(tst[name], OpenMode.ForRead);
                    }
                    else
                    {
                        tstr = addTextStyleTableRecord(name);
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Txt.cs: line: 469");
            }
            return(tstr);
        }
Beispiel #2
0
 // 创建带文字的线型 ////// 返回线型ID
 public static ObjectId CreateLineTypeWithText(string lineTypeName, string text)
 {
     Document    doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor;
     Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { // 读出文字样式表
         TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
         // 读出线型表
         LinetypeTable lt = (LinetypeTable)tr.GetObject(db.LinetypeTableId, OpenMode.ForWrite);
         if (lt.Has(lineTypeName))
         {
             return(lt[lineTypeName]);
         }
         else   // 创建新的线型记录.
         {
             LinetypeTableRecord ltr = new LinetypeTableRecord();
             // ...设置线型记录特性
             ltr.Name             = lineTypeName;
             ltr.AsciiDescription = lineTypeName + " Supply ---- " + text + " ---- " + text + " ---- " + text + " ----";
             ltr.PatternLength    = 1.1;
             ltr.NumDashes        = 3;                                                        //分为三段 // 线段Dash #1
             ltr.SetDashLengthAt(0, 0.5);                                                     // 线段Dash #2
             ltr.SetDashLengthAt(1, -0.3);
             ltr.SetShapeStyleAt(1, tt["Standard"]);                                          //文字样式设定
             ltr.SetShapeNumberAt(1, 0);                                                      //文字位置设定,用一二维向量控制
             ltr.SetShapeOffsetAt(1, new Vector2d(-0.1, -0.05)); ltr.SetShapeScaleAt(1, 0.1); //文字比例
             ltr.SetShapeIsUcsOrientedAt(1, false); ltr.SetShapeRotationAt(1, 0);             //文字方向,0为顺直接方向
             ltr.SetTextAt(1, text);                                                          //文字内容 // 线段Dash #3
             ltr.SetDashLengthAt(2, -0.3);                                                    // 添加新的线型记录到线型表
             ObjectId ltId = lt.Add(ltr);
             tr.AddNewlyCreatedDBObject(ltr, true);
             tr.Commit();
             return(ltId);//返回线型记录ID
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// TextStyle을 name으로 찾아줍니다.
        /// </summary>
        /// <param name="name">TextStyle의 이름입니다.</param>
        /// <returns>TextStyle의 ObjectId를 리턴합니다.</returns>
        public static ObjectId GetTextStyleId(string name)
        {
            Document doc = DatabaseUtil.GetActiveDocument();
            Database db  = doc.Database;

            try
            {
                using (doc.LockDocument())
                {
                    using (Transaction tr = DatabaseUtil.GetTransaction(db))
                    {
                        TextStyleTable oTextStyleTbl = tr.GetObject(db.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;

                        if (oTextStyleTbl.Has(name))
                        {
                            return(oTextStyleTbl[name]);
                        }

                        return(ObjectId.Null);
                    }
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.Print(string.Format("************에러발생************\n위치 : GetTextStyleId\n메시지 : {0}", ex.Message));
                return(ObjectId.Null);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 删除文字样式
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <param name="styleName">文字样式名</param>
        /// <returns>如果删除成功返回true,否则返回false</returns>
        public static bool DeleteTextStyle(this Database db, string styleName)
        {
            var trans = db.TransactionManager;
            //打开文字样式表
            TextStyleTable st = (TextStyleTable)trans.GetObject(db.TextStyleTableId, OpenMode.ForRead);

            //如果不存在名为styleName的文字样式,则返回
            if (!st.Has(styleName))
            {
                return(false);
            }
            //获取名为styleName的文字样式表记录的Id
            ObjectId styleId = st[styleName];

            //如果要删除的文字样式为当前文字样式,则返回(不能删除当前文字样式)
            if (styleId == db.Textstyle)
            {
                return(false);
            }
            //以写的方式打开名为styleName的文字样式表记录
            TextStyleTableRecord str = (TextStyleTableRecord)trans.GetObject(styleId, OpenMode.ForWrite);

            //删除名为styleName的文字样式
            str.Erase(true);
            return(true);//删除文字样式成功
        }
Beispiel #5
0
        /// <summary>
        /// Trả về một Rectangle bao quanh một chuỗi
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static Rectangle GetTextBounds(DBText s, double bufer = 0.35)
        {
            Autodesk.AutoCAD.GraphicsInterface.TextStyle style = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();
            byte        n;
            Transaction tr = GLOBAL.CurrentDatabase.TransactionManager.StartTransaction();

            try
            {
                using (tr)
                {
                    BlockTableRecord btr            = (BlockTableRecord)tr.GetObject(GLOBAL.CurrentDatabase.CurrentSpaceId, OpenMode.ForWrite);
                    string           text           = s.TextString;
                    TextStyleTable   textStyleTable = tr.GetObject
                                                      (
                        GLOBAL.CurrentDatabase.TextStyleTableId,
                        OpenMode.ForRead
                                                      ) as TextStyleTable;

                    string currentTextStyle = Application.GetSystemVariable("TEXTSTYLE").ToString();

                    ObjectId textStyleId = ObjectId.Null;
                    textStyleId = textStyleTable[currentTextStyle];
                    Autodesk.AutoCAD.GraphicsInterface.TextStyle iStyle
                        = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();

                    // get textstyle of newly created text
                    TextStyleTableRecord txtbtr = (TextStyleTableRecord)tr.GetObject(textStyleId, OpenMode.ForRead);
                    // copy properties from TextStyleTableRecord and dbtext to temp AcGi.TextStyle (just very limited one for the future calculation)
                    style.FileName = txtbtr.FileName;
                    // then copy properties from existing text
                    style.TextSize       = s.Height; // txtbtr.TextSize;
                    style.ObliquingAngle = s.Oblique;
                    style.XScale         = s.WidthFactor;
                    // load temp style record
                    try
                    {
                        n = style.LoadStyleRec;
                    }
                    catch { return(null); }

                    Point2d textPos = new Point2d(s.Position.X, s.Position.Y);
                    //bufer = s.Height * 0.35;
                    Point2d p = Autodesk.AutoCAD.Internal.Utils.GetTextExtents(textStyleId, s.TextString, s.Height);

                    Rectangle rec2 = new Rectangle(p.X, p.Y);
                    rec2.LowerLeft  = new Point2d(textPos.X - bufer, textPos.Y - bufer);
                    rec2.UpperLeft  = new Point2d(rec2.LowerLeft.X, rec2.LowerLeft.Y + rec2.Height + 2 * bufer);
                    rec2.UpperRight = new Point2d(rec2.UpperLeft.X + rec2.Width + 2 * bufer, rec2.UpperLeft.Y);
                    rec2.LowerRight = new Point2d(rec2.UpperRight.X, rec2.LowerLeft.Y);

                    return(rec2);
                }
            }
            catch (System.Exception exc)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(exc.Message + "\n" + exc.StackTrace);
                return(null);
            }
            finally { }
        }
Beispiel #6
0
        public static void PrintNote2(Database db, Point3d InsertPoint)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable   st       = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable       blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.PaperSpace], OpenMode.ForWrite) as BlockTableRecord;

                MText theNote = new MText();
                theNote.Contents = "注\\P" +
                                   "{   1.图中尺寸均以毫米为单位。}\\P" +
                                   "{   2.桥梁首尾两节不设加强弦杆。}\\P" +
                                   "{   3.对于加强的桥梁,销子(连同插销)的数量,按上表算出后,单排时应减4个,双排时应减8个,三排时应减12个。}\\P" +
                                   "{   4.端柱、桥座及座板包括在首节内。}\\P" +
                                   "{   5.表列撑架螺栓数量中含斜撑螺栓和支撑架螺栓,若减去斜撑所用螺栓(首节减4个,中节减4个,尾节减8个)余者即为}\\P" +
                                   "{     相应之首节、中节、尾节支撑架、联板所用之螺栓数量。}\\P" +
                                   "{   6.中央桥头搭板与中央钢桥面板相同。}\\P";
                theNote.Location    = InsertPoint;
                theNote.TextStyleId = st["仿宋"];
                theNote.TextHeight  = 2.5;
                recorder.AppendEntity(theNote);
                tr.AddNewlyCreatedDBObject(theNote, true);
                tr.Commit();
            }
            return;
        }
Beispiel #7
0
        public ObjectId CreatMyTextStyle()
        {
            ObjectId     StyleID   = ObjectId.Null;
            const string StyleName = "RQBZ";

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    TextStyleTable Tst = (TextStyleTable)trans.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                    if (Tst.Has(StyleName))
                    {
                        StyleID = Tst[StyleName];     //来自这个链接 https://www.keanw.com/2012/08/a-handy-jig-for-creating-autocad-text-using-net-part-2.html
                    }
                    else
                    {
                        TextStyleTableRecord MyTextStyle = new TextStyleTableRecord();
                        MyTextStyle.FileName        = "txtd.shx";
                        MyTextStyle.BigFontFileName = "hztxt.shx";
                        MyTextStyle.Name            = "RQBZ";
                        MyTextStyle.XScale          = 0.7;
                        Tst.UpgradeOpen();
                        StyleID = Tst.Add(MyTextStyle);
                        trans.AddNewlyCreatedDBObject(MyTextStyle, true);
                    }
                }
                catch (Autodesk.AutoCAD.Runtime.Exception EX)
                {
                    ed.WriteMessage("出错了!" + EX.ToString());
                }
                trans.Commit();
            }
            return(StyleID);
        }
Beispiel #8
0
        public static TextStyleTableRecord GetTextStyle(string textStyleName)
        {
            Document document = Active.Document;
            Database database = document.Database;

            using (Transaction transaction = database.TransactionManager.StartTransaction())
            {
                try
                {
                    TextStyleTable textStyleTable = GetTextStyleTable();
                    foreach (ObjectId textStyleTableRecordId in textStyleTable)
                    {
                        TextStyleTableRecord textStyleTableRecord = transaction.GetObject <TextStyleTableRecord>(textStyleTableRecordId, OpenMode.ForRead);
                        if (textStyleTableRecord.Name == textStyleName)
                        {
                            return(textStyleTableRecord);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Active.WriteMessage(ex.Message);
                    throw;
                }
            }//using
            return(null);
        }
Beispiel #9
0
        // Returns all text styles
        public static Dictionary <string, ObjectId> GetTextStyles()
        {
            Dictionary <string, ObjectId> list = new Dictionary <string, ObjectId>();

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    TextStyleTable        table = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                    SymbolTableEnumerator it    = table.GetEnumerator();
                    while (it.MoveNext())
                    {
                        ObjectId             id    = it.Current;
                        TextStyleTableRecord style = (TextStyleTableRecord)tr.GetObject(id, OpenMode.ForRead);
                        list.Add(style.Name, id);
                    }
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "RebarPos", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                }
            }

            return(list);
        }
Beispiel #10
0
 public static void CreateTextStyle(string TextStyleName, string FontName, double ObliqueAng, out string message)
 {
     try
     {
         using (Transaction transaction = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())
         {
             Database             db    = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
             TextStyleTable       tst1  = (TextStyleTable)transaction.GetObject(db.TextStyleTableId, OpenMode.ForWrite, true, true);
             TextStyleTableRecord tstr1 = new TextStyleTableRecord
             {
                 Name           = TextStyleName,
                 FileName       = FontName,
                 XScale         = 1,
                 ObliquingAngle = Tools.Deg2Rad(ObliqueAng),
                 Annotative     = AnnotativeStates.True
             };
             tst1.Add(tstr1);
             transaction.TransactionManager.AddNewlyCreatedDBObject(tstr1, true);
             transaction.Commit();
             //RmTSid = tstr1.ObjectId;
             //return true;
             message = string.Empty;
         }
     }
     catch (Autodesk.AutoCAD.Runtime.Exception e)
     {
         message = e.Message.ToString();
     }
 }
Beispiel #11
0
        // Creates a new text style
        public static ObjectId GetOrCreateTextStyle(Database db, string name, string filename, double scale)
        {
            ObjectId id = ObjectId.Null;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable table = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                if (table.Has(name))
                {
                    id = table[name];
                }
                else
                {
                    TextStyleTableRecord style = new TextStyleTableRecord();
                    style.Name     = name;
                    style.FileName = filename;
                    style.XScale   = scale;
                    table.UpgradeOpen();
                    id = table.Add(style);
                    table.DowngradeOpen();
                    tr.AddNewlyCreatedDBObject(style, true);
                }

                tr.Commit();
            }

            return(id);
        }
Beispiel #12
0
 /// <summary>
 /// Gets all text style table records.
 /// </summary>
 /// <param name="symbolTbl">The symbol table.</param>
 /// <param name="mode">The mode.</param>
 /// <param name="filter">The filter.</param>
 /// <returns></returns>
 public static IEnumerable <TextStyleTableRecord> GetAllTextStyleTableRecords(this TextStyleTable symbolTbl,
                                                                              OpenMode mode = OpenMode.ForRead, SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
 {
     return
         (symbolTbl.GetSymbolTableRecords <TextStyleTableRecord>(
              symbolTbl.Database.TransactionManager.TopTransaction, mode, filter, true));
 }
Beispiel #13
0
        public static DBText PrintText(Database db, string textstring, double H, Point2d PositionPoint, double scale = 100, bool isCover = false)
        {
            DBText txt = new DBText();

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable   st         = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable       blockTbl   = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                                                           OpenMode.ForWrite) as BlockTableRecord;
                txt.TextString     = textstring;
                txt.Height         = H * scale;
                txt.Position       = PositionPoint.Convert3D();
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode   = TextVerticalMode.TextBottom;
                txt.AlignmentPoint = PositionPoint.Convert3D(0, 0.5 * scale);
                txt.TextStyleId    = st["fsdb"];
                txt.Layer          = "标注";
                txt.WidthFactor    = 0.75;
                if (isCover)
                {
                    // 遮罩
                }

                modelSpace.AppendEntity(txt);
                tr.AddNewlyCreatedDBObject(txt, true);
                tr.Commit();
            }
            return(txt);
        }
Beispiel #14
0
        addTextStyleTableRecord(string name, string nameFontFile = "Romans.shx", double size = 0.0, double xscale = 0.8)
        {
            TextStyleTableRecord TStr = new TextStyleTableRecord();

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    TextStyleTable TST = getTextStyleTable();
                    TStr.Name = name;

                    TST.UpgradeOpen();
                    TST.Add(TStr);

                    TStr.FileName   = nameFontFile;
                    TStr.TextSize   = size;
                    TStr.XScale     = xscale;
                    TStr.Annotative = AnnotativeStates.True;

                    tr.AddNewlyCreatedDBObject(TStr, true);
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Txt.cs: line: 199");
            }
            return(TStr);
        }
Beispiel #15
0
        /// <summary>
        /// 将指定文字样式设为当前
        /// </summary>
        public static bool SetTextStyleCurrent(this Database db, string TextStyleName,
                                               string FontFilename = "smsim.shx", string BigFontFilename = "smfs.shx", double WidthFactor = 0.75)
        {
            // 开启事务处理
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                // 打开文字样式表
                TextStyleTable tst = (TextStyleTable)trans.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                //如果不存在指定文字样式,则创建
                if (!tst.Has(TextStyleName))
                {
                    try { db.AddTextStyle(TextStyleName, FontFilename, BigFontFilename, WidthFactor); }
                    catch { return(false); }
                }

                //获取名为TextStyleName的的文字样式表记录的Id
                ObjectId tsId = tst[TextStyleName];
                //指定当前文字样式
                db.Textstyle = tsId;

                // 提交事务
                trans.Commit();
            }
            return(true);
        }
        /// <summary>
        /// 获取文字样式ID
        /// </summary>
        /// <param name="textStyleName">文字样式名</param>
        /// <param name="createIfNotExist">自动创建</param>
        /// <returns>结果</returns>
        public static ObjectId GetTextStyleId(string textStyleName, bool createIfNotExist = false)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                TextStyleTable tsTab = (TextStyleTable)trans.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                if (tsTab.Has(textStyleName))
                {
                    return(tsTab[textStyleName]);
                }
                else
                {
                    if (createIfNotExist)
                    {
                        tsTab.UpgradeOpen();
                        TextStyleTableRecord tstr = new TextStyleTableRecord {
                            Name = textStyleName
                        };
                        var result = tsTab.Add(tstr);
                        trans.AddNewlyCreatedDBObject(tstr, true);
                        trans.Commit();
                        return(result);
                    }
                    else
                    {
                        return(db.Textstyle);
                    }
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// 新建文字样式
        /// </summary>
        public static ObjectId AddTextStyle(this Database db, string TextStyleName, string FontFilename, string BigFontFilename, double WidthFactor)
        {
            ObjectId tsId = ObjectId.Null;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                // 打开文字样式表
                TextStyleTable tst = (TextStyleTable)trans.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                // 如果不存在名为styleName的文字样式,则新建一个文字样式
                if (!tst.Has(TextStyleName))
                {
                    //定义一个新的的文字样式表记录
                    TextStyleTableRecord tsr = new TextStyleTableRecord();
                    //设置的文字样式名
                    tsr.Name = TextStyleName;
                    //设置文字样式的字体
                    tsr.FileName        = FontFilename;
                    tsr.BigFontFileName = BigFontFilename;
                    // 切换文字样式表的状态为写以添加新的文字样式
                    tsr.XScale = WidthFactor;
                    tst.UpgradeOpen();
                    // 更新数据信息
                    tst.Add(tsr);
                    trans.AddNewlyCreatedDBObject(tsr, true);
                    // 为了安全,将文字样式表的状态切换为读
                    tst.DowngradeOpen();

                    tsId = tst[TextStyleName];
                }
                // 提交事务
                trans.Commit();
            }
            return(tsId);
        }
Beispiel #18
0
        public ErrorStatus getTextStyleId(string Textstil, ref ObjectId TextstilId)
        {
            Database    db  = HostApplicationServices.WorkingDatabase;
            Transaction myT = db.TransactionManager.StartTransaction();

            ErrorStatus es = ErrorStatus.KeyNotFound;

            try
            {
                TextStyleTable tsTbl = (TextStyleTable)myT.GetObject(db.TextStyleTableId, OpenMode.ForRead, true, true);

                foreach (ObjectId objId in tsTbl)
                {
                    TextStyleTableRecord tsTblRec = new TextStyleTableRecord();
                    tsTblRec = (TextStyleTableRecord)myT.GetObject(objId, OpenMode.ForWrite);

                    if (Textstil == tsTblRec.Name)
                    {
                        TextstilId = objId;
                        //m_myT.Commit();
                        break;
                    }
                }

                es = ErrorStatus.OK;
            }

            finally
            {
                myT.Commit();
            }

            return(es);
        }
Beispiel #19
0
        private void DrawAxisLine(Point3d point, Vector3d direction, double chainage)
        {
            var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            var db  = doc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
                using (TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead))
                    using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite))
                    {
                        // Draw axis
                        ObjectId textStyleId = ObjectId.Null;
                        if (tt.Has(TextStyleName))
                        {
                            textStyleId = tt[TextStyleName];
                        }

                        // Line
                        Point3d pt1  = point - direction * AxisLineLength / 2;
                        Point3d pt2  = point + direction * AxisLineLength / 2;
                        Line    line = AcadEntity.CreateLine(db, pt1, pt2);
                        btr.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);

                        // Axis text
                        Point3d ptt      = pt2 + direction * TextHeight / 2;
                        double  rotation = Vector3d.YAxis.GetAngleTo(direction, Vector3d.ZAxis);
                        DBText  text     = AcadEntity.CreateText(db, ptt, AxisName, TextHeight, rotation, 1, TextHorizontalMode.TextCenter, TextVerticalMode.TextBottom, textStyleId);

                        btr.AppendEntity(text);
                        tr.AddNewlyCreatedDBObject(text, true);

                        tr.Commit();
                    }
        }
Beispiel #20
0
        public static void RemoveTextStyle(string styleName)
        {
            Document document = Active.Document;
            Database database = document.Database;

            try
            {
                TextStyleTable textStyleTable = GetTextStyleTable();
                using (Transaction transaction = database.TransactionManager.StartTransaction())
                {
                    foreach (ObjectId textStyleTableRecordId in textStyleTable)
                    {
                        TextStyleTableRecord textStyleTableRecord = transaction.GetObject <TextStyleTableRecord>(textStyleTableRecordId, OpenMode.ForRead);
                        if (textStyleTableRecord.Name == styleName)
                        {
                            textStyleTableRecord.UpgradeOpen();
                            textStyleTableRecord.Erase();
                        }
                    }

                    transaction.Commit();
                }//using
            }
            catch (Exception ex)
            {
                Active.WriteMessage(ex.Message);
                throw;
            }
        }
Beispiel #21
0
        public void CreateStyle()
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st        = (TextStyleTable)trans.GetObject(db.TextStyleTableId, OpenMode.ForWrite);
                String         StyleName = "工程图";
                if (st.Has(StyleName) == false)
                {
                    TextStyleTableRecord str = new TextStyleTableRecord();
                    str.Name     = StyleName;
                    str.FileName = "simfang.ttf";
                    //---------------------------------------------
                    // 设置SHX字体
                    // str.FileName = "gbenor"
                    //设置大字体.
                    // str.BigFontFileName = "gbcbig"
                    // --------------------------------------------
                    str.ObliquingAngle = 15 * Math.PI / 180;
                    str.XScale         = 0.67;
                    ObjectId TextstyleId = st.Add(str);
                    trans.AddNewlyCreatedDBObject(str, true);
                    db.Textstyle = TextstyleId;
                    trans.Commit();
                }
            }
        }
 public bool Exists(string styleName)
 {
     using (Transaction t = targetDB.TransactionManager.StartTransaction())
     {
         TextStyleTable tst = (TextStyleTable)t.GetObject(targetDB.TextStyleTableId, OpenMode.ForRead);
         return(tst.Has(styleName));
     }
 }
 private ObjectId GetStyleByName(string textStyleName)
 {
     using (Transaction t = targetDB.TransactionManager.StartTransaction())
     {
         TextStyleTable tst = (TextStyleTable)t.GetObject(targetDB.TextStyleTableId, OpenMode.ForRead);
         return((ObjectId)t.GetObject(tst[textStyleName], OpenMode.ForRead).ObjectId);
     }
 }
Beispiel #24
0
 /// <summary>
 /// Gets the shape file table records.
 /// </summary>
 /// <param name="symbolTbl">The symbol table.</param>
 /// <param name="trx">The TRX.</param>
 /// <param name="mode">The mode.</param>
 /// <param name="filter">The filter.</param>
 /// <returns></returns>
 public static IEnumerable <TextStyleTableRecord> GetShapeFileTableRecords(this TextStyleTable symbolTbl,
                                                                           Transaction trx, OpenMode mode = OpenMode.ForRead,
                                                                           SymbolTableRecordFilter filter = SymbolTableRecordFilter.None)
 {
     return
         (symbolTbl.GetSymbolTableRecords <TextStyleTableRecord>(trx, mode, filter, true)
          .Where(txt => txt.IsShapeFile));
 }
Beispiel #25
0
        static public ObjectIdCollection GetObjIdNonGrafical(Database db)
        {
            ObjectIdCollection idsNonGraficals = new ObjectIdCollection();

            Transaction tr = db.TransactionManager.StartTransaction();

            using (tr)
            {
                //Block Table
                BlockTable btBlock = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                foreach (ObjectId btrId in btBlock)
                {
                    idsNonGraficals.Add(btrId);
                }

                //Dim Style
                DimStyleTable tbDimSty = tr.GetObject(db.DimStyleTableId, OpenMode.ForRead) as DimStyleTable;
                foreach (ObjectId btrId in tbDimSty)
                {
                    idsNonGraficals.Add(btrId);
                }

                //Layer
                LayerTable tbLayer = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                foreach (ObjectId btrId in tbLayer)
                {
                    idsNonGraficals.Add(btrId);
                }

                //Line types
                LinetypeTable tbLinetype = tr.GetObject(db.LinetypeTableId, OpenMode.ForRead) as LinetypeTable;
                foreach (ObjectId btrId in tbLinetype)
                {
                    idsNonGraficals.Add(btrId);
                }

                //Table Style
                TextStyleTable tbTextStyle = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                foreach (ObjectId btrId in tbTextStyle)
                {
                    idsNonGraficals.Add(btrId);
                }

                foreach (ObjectId objId in idsNonGraficals)
                {
                    if (!objId.IsValid)
                    {
                        idsNonGraficals.Remove(objId);
                    }
                }
            }

            return(idsNonGraficals);
        }
Beispiel #26
0
        public static ObjectId GetTextStyle(string name)
        {
            Database dbH = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = dbH.TransactionManager.StartTransaction())
            {
                TextStyleTable TST = (TextStyleTable)trans.GetObject(dbH.TextStyleTableId, OpenMode.ForWrite);
                ObjectId       id  = GetIdFromSymbolTable(TST, name);
                return(id);
            }
        }
Beispiel #27
0
        public static ObjectId GetStandardTextStyle(Database db, Transaction tr)
        {
            TextStyleTable tst = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);

            if (tst.Has("Standard"))
            {
                return(tst["Standard"]);
            }

            return(ObjectId.Null);
        }
Beispiel #28
0
        public void TextStyleDemo()
        {
            Database db = HostApplicationServices.WorkingDatabase;

            db.AddTextStyle("测试文字样式");
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                TextStyleTable tst = (TextStyleTable)trans.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                foreach (var item in tst)
                {
                }
            }
        }
Beispiel #29
0
        public static void PrintCirText(Database db, int textstring, Point2d PositionPoint, Point2d startP, Point2d endP, double scale = 100)
        {
            DBText txt = new DBText();
            Circle C1 = new Circle();
            Circle C2 = new Circle();
            Line   L1, L2;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable   st         = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable       blockTbl   = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                                                           OpenMode.ForWrite) as BlockTableRecord;


                txt.TextString     = textstring.ToString();
                txt.Height         = 2.5 * scale;
                txt.Position       = PositionPoint.Convert3D();
                txt.HorizontalMode = TextHorizontalMode.TextCenter;
                txt.VerticalMode   = TextVerticalMode.TextVerticalMid;
                txt.AlignmentPoint = PositionPoint.Convert3D();
                txt.TextStyleId    = st["fsdb"];
                txt.Layer          = "标注";
                txt.WidthFactor    = 0.75;

                C1       = new Circle(PositionPoint.Convert3D(), Vector3d.ZAxis, 1.5 * scale);
                C2       = new Circle(PositionPoint.Convert3D(), Vector3d.ZAxis, 1.8 * scale);
                C1.Layer = "标注";
                C2.Layer = "标注";

                L1       = new Line(PositionPoint.Convert3D(0, 1.8 * scale), endP.Convert3D());
                L2       = new Line(PositionPoint.Convert3D(0, -1.8 * scale), startP.Convert3D());
                L1.Layer = "标注";
                L2.Layer = "标注";

                modelSpace.AppendEntity(txt);
                tr.AddNewlyCreatedDBObject(txt, true);
                modelSpace.AppendEntity(C1);
                tr.AddNewlyCreatedDBObject(C1, true);
                modelSpace.AppendEntity(C2);
                tr.AddNewlyCreatedDBObject(C2, true);
                modelSpace.AppendEntity(L1);
                tr.AddNewlyCreatedDBObject(L1, true);
                modelSpace.AppendEntity(L2);
                tr.AddNewlyCreatedDBObject(L2, true);
                tr.Commit();
            }
            return;
        }
Beispiel #30
0
        private static ObjectId GetTextStyleId(string v)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            ObjectId id;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                TextStyleTable tst = (TextStyleTable)trans.GetObject(db.TextStyleTableId, OpenMode.ForRead);

                id = tst[v];

                trans.Commit();
            }
            return(id);
        }