示例#1
0
        getDimStyleTableRecord(string name)
        {
            ObjectId id = ObjectId.Null;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    DimStyleTable dst = (DimStyleTable)HostApplicationServices.WorkingDatabase.DimStyleTableId.GetObject(OpenMode.ForRead);
                    if (dst.Has(name) == true)
                    {
                        //dst.UpgradeOpen();
                        DimStyleTableRecord dstr = (DimStyleTableRecord)dst[name].GetObject(OpenMode.ForRead);
                        id = dstr.ObjectId;
                    }
                    else
                    {
                        dst.UpgradeOpen();
                        DimStyleTableRecord dstr = new DimStyleTableRecord();
                        dstr.Name       = name;
                        dstr.Annotative = AnnotativeStates.True;
                        id = dst.Add(dstr);
                        tr.AddNewlyCreatedDBObject(dstr, true);
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Dim.cs: line: 162");
            }
            return(id);
        }
示例#2
0
        //public static ObjectId AddDimStyle(this Database db,string styleName)
        //{
        //    DimStyleTable dst = (DimStyleTable)db.DimStyleTableId.GetObject(OpenMode.ForRead);

        //    if (!dst.Has(styleName))
        //    {
        //        DimStyleTableRecord dstr = new DimStyleTableRecord();

        //        dstr.Name = styleName;
        //        dstr.Dimscale = 12;
        //        dst.UpgradeOpen();
        //        dst.Add(dstr);
        //        db.TransactionManager.AddNewlyCreatedDBObject(dstr, true);
        //        dst.DowngradeOpen();
        //    }
        //    return dst[styleName];
        //}

        public static void AddDimStyle(this Database db, string styleName)
        {
            DimStyleTable dst = (DimStyleTable)db.DimStyleTableId.GetObject(OpenMode.ForRead);

            if (!dst.Has(styleName))
            {
                DimStyleTableRecord dstr = new DimStyleTableRecord
                {
                    Name     = styleName,
                    Dimscale = 12
                };
                dst.UpgradeOpen();
                dst.Add(dstr);
                db.TransactionManager.AddNewlyCreatedDBObject(dstr, true);
                dst.DowngradeOpen();
            }
        }
示例#3
0
        /// <summary>
        /// 创建一个新的标注样式
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <param name="styleName">标注样式名</param>
        /// <returns>返回新建的标注样式的Id</returns>
        public static ObjectId AddDimStyle(this Database db, string styleName)
        {
            //打开标注样式表
            DimStyleTable dst = (DimStyleTable)db.DimStyleTableId.GetObject(OpenMode.ForRead);

            if (!dst.Has(styleName))//如果不存在名为styleName的标注样式,则新建一个标注样式
            {
                //定义一个新的标注样式表记录
                DimStyleTableRecord dstr = new DimStyleTableRecord();
                dstr.Name = styleName; //设置标注样式名
                dst.UpgradeOpen();     //切换标注样式表的状态为写以添加新的标注样式
                dst.Add(dstr);         //将标注样式表记录的信息添加到标注样式表中
                //把标注式表记录添加到事务处理中
                db.TransactionManager.AddNewlyCreatedDBObject(dstr, true);
                dst.DowngradeOpen(); //为了安全,将标注样式表的状态切换为读
            }
            return(dst[styleName]);  //返回新添加的标注样式表记录的ObjectId
        }
示例#4
0
        public static ObjectId AddDimStyle(this Database db, string styleName, double dimasz, double dimexe, int dimtad, double dimtxt)
        {
            DimStyleTable dst = (DimStyleTable)db.DimStyleTableId.GetObject(OpenMode.ForRead);

            if (!dst.Has(styleName))
            {
                DimStyleTableRecord dstr = new DimStyleTableRecord
                {
                    Name   = styleName,
                    Dimasz = dimasz,
                    Dimexe = dimexe,
                    Dimtad = dimtad,
                    Dimtxt = dimtxt
                };

                dst.UpgradeOpen();
                dst.Add(dstr);
                db.TransactionManager.AddNewlyCreatedDBObject(dstr, true);
                dst.DowngradeOpen();
            }
            return(dst[styleName]);
        }
示例#5
0
        public void NewDimStyle()
        {
            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                DimStyleTable DimTabb = (DimStyleTable)trans.GetObject(db.DimStyleTableId, OpenMode.ForRead);

                ObjectId dimId = ObjectId.Null;

                if (!DimTabb.Has("Test"))
                {
                    DimTabb.UpgradeOpen();

                    DimStyleTableRecord newRecord = new DimStyleTableRecord();

                    newRecord.Name = "Test";

                    dimId = DimTabb.Add(newRecord);

                    trans.AddNewlyCreatedDBObject(newRecord, true);
                }

                else
                {
                    dimId = DimTabb["Test"];
                }

                DimStyleTableRecord DimTabbRecaord = (DimStyleTableRecord)trans.GetObject(dimId, OpenMode.ForRead);

                if (DimTabbRecaord.ObjectId != db.Dimstyle)
                {
                    db.Dimstyle = DimTabbRecaord.ObjectId;
                    db.SetDimstyleData(DimTabbRecaord);
                }
                trans.Commit();
            }
        }
示例#6
0
        public void AddDimStyleFromDWG()
        {
            Document mdiActiveDocument = Application.DocumentManager.MdiActiveDocument;
            Database database          = mdiActiveDocument.Database;

            try
            {
                using (Transaction transaction = database.TransactionManager.StartTransaction())
                {
                    DimStyleTable dimStyleTable = (DimStyleTable)transaction.GetObject(database.DimStyleTableId, 1);
                    if (!dimStyleTable.Has("DIM100"))
                    {
                        string   text      = Class33.Class31_0.Info.DirectoryPath + "\\support\\DimStyle.Dwg";
                        Database database2 = new Database(false, true);
                        database2.ReadDwgFile(text, FileShare.Read, true, "");
                        DimStyleTableRecord dimStyleTableRecord;
                        using (Transaction transaction2 = database2.TransactionManager.StartTransaction())
                        {
                            DimStyleTable dimStyleTable2 = (DimStyleTable)transaction2.GetObject(database2.DimStyleTableId, 0);
                            dimStyleTableRecord = (DimStyleTableRecord)transaction2.GetObject(dimStyleTable2["DIM100"], 0);
                            transaction2.Dispose();
                        }
                        mdiActiveDocument.Editor.WriteMessage("\n" + dimStyleTableRecord.Name);
                        DimStyleTableRecord dimStyleTableRecord2 = new DimStyleTableRecord();
                        dimStyleTableRecord2 = (DimStyleTableRecord)dimStyleTableRecord.Clone();
                        dimStyleTable.Add(dimStyleTableRecord2);
                        transaction.AddNewlyCreatedDBObject(dimStyleTableRecord2, true);
                        mdiActiveDocument.Editor.WriteMessage("\n标注样式:DIM100添加成功");
                    }
                    transaction.Commit();
                }
            }
            catch (Exception ex)
            {
                mdiActiveDocument.Editor.WriteMessage("\n标注样式加载出错: " + ex.Message);
            }
        }
示例#7
0
        public static ObjectId AddDimStyle(Database db, string DimName)//添加标注样式
        {
            DimStyleTable table = (DimStyleTable)db.DimStyleTableId.GetObject(OpenMode.ForRead);

            if (!table.Has(DimName))
            {
                DimStyleTableRecord record = new DimStyleTableRecord();
                record.Name   = DimName;
                record.Dimasz = 0.5;
                record.Dimtxt = 0.5;
                record.Dimtad = 1;
                record.Dimdec = 3;
                record.Dimtad = 1;
                //文字
                record.Dimtih          = false;
                record.Dimtoh          = false;
                record.Dimtxtdirection = false;
                table.UpgradeOpen();
                table.Add(record);
                db.TransactionManager.AddNewlyCreatedDBObject(record, true);
                table.DowngradeOpen();
            }
            return(table[DimName]);
        }
示例#8
0
        public static ObjectId CreateDimStyle(string _name, ObjectId _text, ObjectId _arrow)
        {
            Document mdiActiveDocument = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database database          = mdiActiveDocument.Database;
            Editor   editor            = mdiActiveDocument.Editor;
            ObjectId result;

            using (mdiActiveDocument.LockDocument())
            {
                using (Transaction transaction = database.TransactionManager.StartTransaction())
                {
                    DimStyleTable dimStyleTable = transaction.GetObject(database.DimStyleTableId, OpenMode.ForWrite) as DimStyleTable;
                    if (!dimStyleTable.Has(_name))
                    {
                        DimStyleTableRecord dimStyleTableRecord = new DimStyleTableRecord();
                        dimStyleTableRecord.Name       = _name;
                        dimStyleTableRecord.Dimadec    = 2;
                        dimStyleTableRecord.Dimalt     = false;
                        dimStyleTableRecord.Dimaltd    = 0;
                        dimStyleTableRecord.Dimaltf    = 25.4;
                        dimStyleTableRecord.Dimaltrnd  = 0.0;
                        dimStyleTableRecord.Dimalttd   = 0;
                        dimStyleTableRecord.Dimalttz   = 0;
                        dimStyleTableRecord.Dimaltu    = 2;
                        dimStyleTableRecord.Dimaltz    = 0;
                        dimStyleTableRecord.Dimapost   = "";
                        dimStyleTableRecord.Dimarcsym  = 0;
                        dimStyleTableRecord.Dimatfit   = 3;
                        dimStyleTableRecord.Dimaunit   = 1;
                        dimStyleTableRecord.Dimazin    = 0;
                        dimStyleTableRecord.Dimblk     = _arrow;
                        dimStyleTableRecord.Dimblk1    = _arrow;
                        dimStyleTableRecord.Dimblk2    = _arrow;
                        dimStyleTableRecord.Dimcen     = 2.0;
                        dimStyleTableRecord.Dimclrd    = Color.FromColorIndex(ColorMethod.ByBlock, 8);
                        dimStyleTableRecord.Dimclre    = Color.FromColorIndex(ColorMethod.ByBlock, 8);
                        dimStyleTableRecord.Dimclrt    = Color.FromColorIndex(ColorMethod.ByBlock, 4);
                        dimStyleTableRecord.Dimdec     = 0;
                        dimStyleTableRecord.Dimdle     = 0.0;
                        dimStyleTableRecord.Dimdli     = 7.0;
                        dimStyleTableRecord.Dimdsep    = char.Parse("Null");
                        dimStyleTableRecord.Dimexe     = 0.1;
                        dimStyleTableRecord.Dimexo     = 0.1;
                        dimStyleTableRecord.Dimfrac    = 1;
                        dimStyleTableRecord.Dimgap     = 0.5;
                        dimStyleTableRecord.Dimldrblk  = _arrow;
                        dimStyleTableRecord.Dimlfac    = 1.0;
                        dimStyleTableRecord.Dimlim     = false;
                        dimStyleTableRecord.Dimltex1   = database.ByBlockLinetype;
                        dimStyleTableRecord.Dimltex2   = database.ByBlockLinetype;
                        dimStyleTableRecord.Dimltype   = database.ByBlockLinetype;
                        dimStyleTableRecord.Dimlunit   = 2;
                        dimStyleTableRecord.Dimlwd     = LineWeight.ByBlock;
                        dimStyleTableRecord.Dimlwe     = LineWeight.ByBlock;
                        dimStyleTableRecord.Dimpost    = "";
                        dimStyleTableRecord.Dimrnd     = 0.5;
                        dimStyleTableRecord.Dimsah     = true;
                        dimStyleTableRecord.Dimscale   = 0.2;
                        dimStyleTableRecord.Dimsd1     = false;
                        dimStyleTableRecord.Dimsd2     = false;
                        dimStyleTableRecord.Dimse1     = false;
                        dimStyleTableRecord.Dimse2     = false;
                        dimStyleTableRecord.Dimsoxd    = false;
                        dimStyleTableRecord.Dimtad     = 1;
                        dimStyleTableRecord.Dimtdec    = 1;
                        dimStyleTableRecord.Dimtfac    = 1.0;
                        dimStyleTableRecord.Dimtih     = false;
                        dimStyleTableRecord.Dimtix     = true;
                        dimStyleTableRecord.Dimtm      = 0.0;
                        dimStyleTableRecord.Dimtmove   = 2;
                        dimStyleTableRecord.Dimtofl    = true;
                        dimStyleTableRecord.Dimtoh     = false;
                        dimStyleTableRecord.Dimtol     = false;
                        dimStyleTableRecord.Dimtolj    = 0;
                        dimStyleTableRecord.Dimtp      = 0.0;
                        dimStyleTableRecord.Dimtsz     = 0.0;
                        dimStyleTableRecord.Dimtxsty   = _text;
                        dimStyleTableRecord.Dimtvp     = 0.0;
                        dimStyleTableRecord.Dimtxt     = 1.7;
                        dimStyleTableRecord.Dimtzin    = 8;
                        dimStyleTableRecord.Dimupt     = false;
                        dimStyleTableRecord.Dimzin     = 8;
                        dimStyleTableRecord.DimfxlenOn = true;
                        dimStyleTableRecord.Dimfxlen   = 40.0;
                        dimStyleTableRecord.Dimtxt     = 0.5;
                        dimStyleTableRecord.Dimasz     = 0.2;
                        result = dimStyleTable.Add(dimStyleTableRecord);
                        transaction.AddNewlyCreatedDBObject(dimStyleTableRecord, true);
                    }
                    else
                    {
                        result = dimStyleTable[_name];
                    }
                    transaction.Commit();
                }
            }
            return(result);
        }
        public static void CADini()
        {
            // Get the current document and database
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            Editor   ed      = acDoc.Editor;

            // Start a transaction
            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
            {
                Dictionary <string, short> ldic = new Dictionary <string, short>()
                {
                    ["粗线"]  = 4,
                    ["细线"]  = 2,
                    ["标注"]  = 7,
                    ["中心线"] = 1,
                    ["虚线"]  = 3,
                    ["填充"]  = 8,
                    ["图框"]  = 8,
                    ["地质"]  = 8,
                };
                List <string> Lname = new List <string>()
                {
                    "CENTER", "DASHED"
                };
                LayerTable acLyrTbl;
                acLyrTbl = tr.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) as LayerTable;
                LinetypeTable acLinTbl;
                acLinTbl = tr.GetObject(acCurDb.LinetypeTableId, OpenMode.ForRead) as LinetypeTable;
                foreach (string ltname in Lname)
                {
                    if (!acLinTbl.Has(ltname))
                    {
                        acCurDb.LoadLineTypeFile(ltname, "acad.lin");
                    }
                }
                LayerTableRecord acLyrTblRec = new LayerTableRecord();
                foreach (string key in ldic.Keys)
                {
                    short cid = ldic[key];
                    acLyrTblRec = new LayerTableRecord();
                    if (!acLyrTbl.Has(key))
                    {
                        acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid);
                        if (cid != 4)
                        {
                            acLyrTblRec.LineWeight = LineWeight.LineWeight013;
                        }
                        else
                        {
                            acLyrTblRec.LineWeight = LineWeight.LineWeight030;
                        }
                        if (cid == 1)
                        {
                            acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"];
                        }
                        if (cid == 3)
                        {
                            acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"];
                        }
                        if (key == "图框")
                        {
                            acLyrTblRec.IsPlottable = false;
                        }
                        if (key == "地质")
                        {
                            acLyrTblRec.IsPlottable = false;
                        }
                        acLyrTblRec.Name = key;
                        if (acLyrTbl.IsWriteEnabled == false)
                        {
                            acLyrTbl.UpgradeOpen();
                        }
                        acLyrTbl.Add(acLyrTblRec);
                        tr.AddNewlyCreatedDBObject(acLyrTblRec, true);
                    }
                    else
                    {
                        acLyrTblRec       = tr.GetObject(acLyrTbl[key], OpenMode.ForWrite) as LayerTableRecord;
                        acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid);
                        if (cid != 4)
                        {
                            acLyrTblRec.LineWeight = LineWeight.LineWeight013;
                        }
                        else
                        {
                            acLyrTblRec.LineWeight = LineWeight.LineWeight030;
                        }
                        if (cid == 1)
                        {
                            acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"];
                        }
                        if (cid == 3)
                        {
                            acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"];
                        }
                        if (key == "图框")
                        {
                            acLyrTblRec.IsPlottable = false;
                        }
                        if (key == "地质")
                        {
                            acLyrTblRec.IsPlottable = false;
                        }
                    }
                }
                if (!acLyrTbl.Has("sjx"))
                {
                    acLyrTblRec            = new LayerTableRecord();
                    acLyrTblRec.Color      = Color.FromColorIndex(ColorMethod.ByAci, 1);
                    acLyrTblRec.Name       = "sjx";
                    acLyrTblRec.LineWeight = LineWeight.LineWeight015;
                    if (acLyrTbl.IsWriteEnabled == false)
                    {
                        acLyrTbl.UpgradeOpen();
                    }
                    acLyrTbl.Add(acLyrTblRec);
                    tr.AddNewlyCreatedDBObject(acLyrTblRec, true);
                }
                if (!acLyrTbl.Has("dmx"))
                {
                    acLyrTblRec            = new LayerTableRecord();
                    acLyrTblRec.Color      = Color.FromColorIndex(ColorMethod.ByAci, 8);
                    acLyrTblRec.Name       = "dmx";
                    acLyrTblRec.LineWeight = LineWeight.LineWeight015;
                    if (acLyrTbl.IsWriteEnabled == false)
                    {
                        acLyrTbl.UpgradeOpen();
                    }
                    acLyrTbl.Add(acLyrTblRec);
                    tr.AddNewlyCreatedDBObject(acLyrTblRec, true);
                }


                //-------------------------------------------------------------------------------------------
                TextStyleTable st = tr.GetObject(acCurDb.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
                if (!st.Has("EN"))
                {
                    TextStyleTableRecord str = new TextStyleTableRecord()
                    {
                        Name     = "En",
                        FileName = "times.ttf",
                        XScale   = 0.85,
                    };
                    st.Add(str);
                    tr.AddNewlyCreatedDBObject(str, true);
                }
                else
                {
                    TextStyleTableRecord str = tr.GetObject(st["En"], OpenMode.ForWrite) as TextStyleTableRecord;
                    str.FileName = "times.ttf";
                    str.XScale   = 0.85;
                }
                if (!st.Has("fsdb"))
                {
                    TextStyleTableRecord str2 = new TextStyleTableRecord()
                    {
                        Name            = "fsdb",
                        FileName        = "fsdb_e.shx",
                        BigFontFileName = "fsdb.shx",
                        XScale          = 0.75,
                    };
                    ObjectId textstyleid = st.Add(str2);
                    tr.AddNewlyCreatedDBObject(str2, true);
                }
                else
                {
                    TextStyleTableRecord str = tr.GetObject(st["fsdb"], OpenMode.ForWrite) as TextStyleTableRecord;
                    str.FileName        = "fsdb_e.shx";
                    str.BigFontFileName = "fsdb.shx";
                    str.XScale          = 0.75;
                }
                if (!st.Has("仿宋"))
                {
                    TextStyleTableRecord str2 = new TextStyleTableRecord()
                    {
                        Name     = "仿宋",
                        FileName = "仿宋_GB2312.ttf",
                        XScale   = 0.8,
                    };
                    ObjectId textstyleid = st.Add(str2);
                    tr.AddNewlyCreatedDBObject(str2, true);
                }
                else
                {
                    TextStyleTableRecord str = tr.GetObject(st["仿宋"], OpenMode.ForWrite) as TextStyleTableRecord;
                    str.FileName = "仿宋_GB2312.ttf";
                    str.XScale   = 0.8;
                }
                if (!st.Has("钢筋"))
                {
                    TextStyleTableRecord str2 = new TextStyleTableRecord()
                    {
                        Name     = "钢筋",
                        FileName = "FS-GB2312-Rebar.ttf",
                        XScale   = 0.8,
                    };
                    ObjectId textstyleid = st.Add(str2);
                    tr.AddNewlyCreatedDBObject(str2, true);
                }
                else
                {
                    TextStyleTableRecord str = tr.GetObject(st["钢筋"], OpenMode.ForWrite) as TextStyleTableRecord;
                    str.FileName = "FS-GB2312-Rebar.ttf";
                    str.XScale   = 0.8;
                }



                //-------------------------------------------------------------------------------------------
                DimStyleTable dst = (DimStyleTable)tr.GetObject(acCurDb.DimStyleTableId, OpenMode.ForWrite);
                foreach (int thescale in new int[] { 50, 75, 100, 125, 150, 200 })
                {
                    string scname            = "1-" + thescale.ToString();
                    DimStyleTableRecord dstr = new DimStyleTableRecord();
                    if (!dst.Has(scname))
                    {
                        dstr.Name       = "1-" + thescale.ToString();
                        dstr.Dimscale   = thescale;
                        dstr.Dimtxsty   = st["仿宋"];
                        dstr.Dimclrd    = Color.FromColorIndex(ColorMethod.ByAci, 6);
                        dstr.Dimclre    = Color.FromColorIndex(ColorMethod.ByAci, 6);
                        dstr.Dimdli     = 5.0;
                        dstr.Dimexe     = 1.0;
                        dstr.Dimexo     = 1.0;
                        dstr.DimfxlenOn = true;
                        dstr.Dimfxlen   = 4;
                        dstr.Dimtxt     = 2.5;
                        dstr.Dimasz     = 1.5;
                        dstr.Dimtix     = true;
                        dstr.Dimtmove   = 1;
                        dstr.Dimtad     = 1;
                        dstr.Dimgap     = 0.8;
                        dstr.Dimdec     = 0;
                        dstr.Dimtih     = false;
                        dstr.Dimtoh     = false;
                        dstr.Dimdsep    = '.';
                        //dstr.Dimlfac = 0.1;
                        dst.Add(dstr);
                        tr.AddNewlyCreatedDBObject(dstr, true);
                    }
                    else
                    {
                        dstr            = tr.GetObject(dst[scname], OpenMode.ForWrite) as DimStyleTableRecord;
                        dstr.Name       = "1-" + thescale.ToString();
                        dstr.Dimscale   = thescale;
                        dstr.Dimtxsty   = st["fsdb"];
                        dstr.Dimclrd    = Color.FromColorIndex(ColorMethod.ByAci, 6);
                        dstr.Dimclre    = Color.FromColorIndex(ColorMethod.ByAci, 6);
                        dstr.Dimdli     = 5.0;
                        dstr.Dimexe     = 1.0;
                        dstr.Dimexo     = 1.0;
                        dstr.DimfxlenOn = true;
                        dstr.Dimfxlen   = 4;
                        dstr.Dimtxt     = 2.5;
                        dstr.Dimasz     = 1.5;
                        dstr.Dimtix     = true;
                        dstr.Dimtmove   = 1;
                        dstr.Dimtad     = 1;
                        dstr.Dimgap     = 0.8;
                        dstr.Dimdec     = 0;
                        dstr.Dimtih     = false;
                        dstr.Dimtoh     = false;
                        dstr.Dimdsep    = '.';
                        dstr.Dimlfac    = 0.1;
                    }
                }
                //-------------------------------------------------------------------------------------------
                // 自定义块
                //-------------------------------------------------------------------------------------------
                BlockTable       bt  = (BlockTable)tr.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = new BlockTableRecord();

                //-------------------------------------------------------------------------------------------
                if (!bt.Has("BG"))
                {
                    btr.Name = "BG";
                    bt.UpgradeOpen();
                    bt.Add(btr);
                    tr.AddNewlyCreatedDBObject(btr, true);
                    Polyline Paa = new Polyline()
                    {
                        //Color = Color.FromColorIndex(ColorMethod.ByAci, 9),
                        //Layer = "标注",
                    };
                    Paa.AddVertexAt(0, new Point2d(0, 0), 0, 0, 200);
                    Paa.AddVertexAt(1, new Point2d(0, 200), 0, 0, 0);
                    btr.AppendEntity(Paa);
                    tr.AddNewlyCreatedDBObject(Paa, true);
                    AttributeDefinition curbg = new AttributeDefinition();
                    curbg.Position    = new Point3d(120, 200, 0);
                    curbg.Height      = 250;
                    curbg.WidthFactor = 0.75;
                    curbg.Tag         = "标高";
                    //curbg.Layer = "标注";
                    curbg.TextStyleId = st["fsdb"];
                    btr.AppendEntity(curbg);
                    tr.AddNewlyCreatedDBObject(curbg, true);
                }
                //-------------------------------------------------------------------------------------------
                if (!bt.Has("ZP"))
                {
                    BlockTableRecord btr2 = new BlockTableRecord();
                    btr2.Name = "ZP";
                    bt.UpgradeOpen();
                    bt.Add(btr2);
                    tr.AddNewlyCreatedDBObject(btr2, true);
                    Polyline Paa2 = new Polyline()
                    {
                        Color = Color.FromColorIndex(ColorMethod.ByAci, 9),
                    };
                    Paa2.AddVertexAt(0, new Point2d(0 - 350, 0), 0, 0, 80);
                    Paa2.AddVertexAt(1, new Point2d(200 - 350, 0), 0, 0, 0);
                    Paa2.AddVertexAt(2, new Point2d(900 - 350, 0), 0, 0, 0);
                    btr2.AppendEntity(Paa2);
                    tr.AddNewlyCreatedDBObject(Paa2, true);
                    AttributeDefinition curzp = new AttributeDefinition();
                    curzp.Position    = new Point3d(220 - 350, 0, 0);
                    curzp.Height      = 250;
                    curzp.WidthFactor = 0.75;
                    curzp.Tag         = "左坡";
                    curzp.TextStyleId = st["fsdb"];
                    btr2.AppendEntity(curzp);
                    tr.AddNewlyCreatedDBObject(curzp, true);
                }

                //-------------------------------------------------------------------------------------------
                if (!bt.Has("YP"))
                {
                    BlockTableRecord btr3 = new BlockTableRecord();
                    btr3.Name = "YP";
                    bt.UpgradeOpen();
                    bt.Add(btr3);
                    tr.AddNewlyCreatedDBObject(btr3, true);
                    Polyline Paa3 = new Polyline()
                    {
                        Color = Color.FromColorIndex(ColorMethod.ByAci, 9),
                    };
                    Paa3.AddVertexAt(0, new Point2d(0 + 350, 0), 0, 0, 80);
                    Paa3.AddVertexAt(1, new Point2d(-200 + 350, 0), 0, 0, 0);
                    Paa3.AddVertexAt(2, new Point2d(-900 + 350, 0), 0, 0, 0);
                    btr3.AppendEntity(Paa3);
                    tr.AddNewlyCreatedDBObject(Paa3, true);
                    AttributeDefinition curyp = new AttributeDefinition();
                    curyp.Position       = new Point3d(-220 + 350, 0, 0);
                    curyp.HorizontalMode = TextHorizontalMode.TextRight;
                    curyp.AlignmentPoint = curyp.Position;
                    curyp.Height         = 250;
                    curyp.WidthFactor    = 0.75;
                    curyp.Tag            = "右坡";
                    curyp.TextStyleId    = st["fsdb"];
                    btr3.AppendEntity(curyp);
                    tr.AddNewlyCreatedDBObject(curyp, true);
                }
                //-------------------------------------------------------------------------------------------

                //-------------------------------------------------------------------------------------------
                tr.Commit();
            }
        }
示例#10
0
        public static void AddDimStyle(DimStyle dimStyle)
        {
            Document document = Active.Document;
            Database database = document.Database;

            try
            {
                DimStyleTable        dimStyleTable        = GetDimStyleTable();
                TextStyleTableRecord textStyleTableRecord = GetTextStyle(dimStyle.TextStyle);

                using (Transaction transaction = database.TransactionManager.StartTransaction())
                {
                    LinetypeTableRecord lineTypeTableRecord = GetLineType(transaction, "ByLayer");
                    if (textStyleTableRecord != null & lineTypeTableRecord != null)
                    {
                        DimStyleTableRecord dimStyleTableRecord = new DimStyleTableRecord();
                        dimStyleTableRecord.Name = dimStyle.Name;

                        // Lines & Arrows
                        dimStyleTableRecord.Dimasz     = dimStyle.TextHeight;
                        dimStyleTableRecord.Dimlwd     = LineWeight.ByLayer;
                        dimStyleTableRecord.Dimlwe     = LineWeight.ByLayer;
                        dimStyleTableRecord.Dimsd1     = false;
                        dimStyleTableRecord.Dimsd2     = false;
                        dimStyleTableRecord.Dimclrd    = Color.FromColorIndex(ColorMethod.ByAci, Constants.COLOR_INDEX_BYLAYER);
                        dimStyleTableRecord.Dimltype   = lineTypeTableRecord.ObjectId;
                        dimStyleTableRecord.Dimdle     = 0;
                        dimStyleTableRecord.Dimltex1   = lineTypeTableRecord.ObjectId;
                        dimStyleTableRecord.Dimltex2   = lineTypeTableRecord.ObjectId;
                        dimStyleTableRecord.Dimse1     = false;
                        dimStyleTableRecord.Dimse2     = false;
                        dimStyleTableRecord.DimfxlenOn = false;
                        dimStyleTableRecord.Dimfxlen   = 1;
                        dimStyleTableRecord.Dimclre    = Color.FromColorIndex(ColorMethod.ByAci, Constants.COLOR_INDEX_BYLAYER);
                        dimStyleTableRecord.Dimexe     = 0.18;
                        dimStyleTableRecord.Dimexo     = 0;

                        // Text
                        dimStyleTableRecord.Dimtfill = 0;
                        dimStyleTableRecord.Dimfrac  = 0;
                        dimStyleTableRecord.Dimclrt  = Color.FromColorIndex(ColorMethod.ByAci, Constants.COLOR_INDEX_BYLAYER);
                        dimStyleTableRecord.Dimtxt   = dimStyle.TextHeight;
                        dimStyleTableRecord.Dimgap   = 0.5;
                        dimStyleTableRecord.Dimtih   = false;
                        dimStyleTableRecord.Dimtoh   = false;
                        dimStyleTableRecord.Dimjust  = 0;
                        dimStyleTableRecord.Dimtad   = 1;
                        dimStyleTableRecord.Dimtxsty = textStyleTableRecord.ObjectId;

                        // Fit
                        dimStyleTableRecord.Dimtofl  = true;
                        dimStyleTableRecord.Dimsoxd  = false;
                        dimStyleTableRecord.Dimtix   = false;
                        dimStyleTableRecord.Dimscale = dimStyle.DimScale;
                        dimStyleTableRecord.Dimatfit = 3;
                        dimStyleTableRecord.Dimtmove = 0;

                        // Primary Units
                        dimStyleTableRecord.Dimdsep  = Char.Parse(".");
                        dimStyleTableRecord.Dimpost  = "";
                        dimStyleTableRecord.Dimrnd   = 0;
                        dimStyleTableRecord.Dimlfac  = 1;
                        dimStyleTableRecord.Dimlunit = 2;
                        dimStyleTableRecord.Dimazin  = 2;
                        dimStyleTableRecord.Dimzin   = 8;
                        dimStyleTableRecord.Dimdec   = 1;

                        // Alternate Units
                        dimStyleTableRecord.Dimalt = false;

                        // Tolerances
                        dimStyleTableRecord.Dimtol = false;

                        dimStyleTable.Add(dimStyleTableRecord);
                        transaction.AddNewlyCreatedDBObject(dimStyleTableRecord, true);
                    }//if

                    transaction.Commit();
                }//using
            }
            catch (Exception ex)
            {
                Active.WriteMessage(ex.Message);
                throw;
            }
        }
示例#11
0
        public static void CADini()
        {
            Dictionary <string, short> ldic = new Dictionary <string, short>();

            ldic["粗线"]  = 4;
            ldic["细线"]  = 2;
            ldic["标注"]  = 7;
            ldic["中心线"] = 1;
            ldic["虚线"]  = 3;
            ldic["图框"]  = 8;

            // Get the current document and database
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            acCurDb.LoadLineTypeFile("CENTER", "acad.lin");
            acCurDb.LoadLineTypeFile("DASHED", "acad.lin");
            // Start a transaction
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Layer table for read
                LayerTable acLyrTbl;
                acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) as LayerTable;
                LinetypeTable acLinTbl;
                acLinTbl = acTrans.GetObject(acCurDb.LinetypeTableId, OpenMode.ForRead) as LinetypeTable;
                foreach (string key in ldic.Keys)
                {
                    short cid = ldic[key];
                    using (LayerTableRecord acLyrTblRec = new LayerTableRecord())
                    {
                        acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid);
                        if (cid != 4)
                        {
                            acLyrTblRec.LineWeight = LineWeight.LineWeight013;
                        }
                        else
                        {
                            acLyrTblRec.LineWeight = LineWeight.LineWeight030;
                        }
                        if (cid == 1)
                        {
                            acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"];
                        }
                        if (cid == 3)
                        {
                            acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"];
                        }
                        if (cid == 8)
                        {
                            acLyrTblRec.IsPlottable = false;
                        }
                        acLyrTblRec.Name = key;
                        acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForWrite);
                        acLyrTbl.Add(acLyrTblRec);
                    }
                }

                TextStyleTable       st  = acTrans.GetObject(acCurDb.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
                TextStyleTableRecord str = new TextStyleTableRecord()
                {
                    Name     = "En",
                    FileName = "ARIALNBI",
                };
                st.Add(str);
                acTrans.AddNewlyCreatedDBObject(str, true);
                TextStyleTableRecord str2 = new TextStyleTableRecord()
                {
                    Name            = "fsdb",
                    FileName        = "fsdb_e.shx",
                    BigFontFileName = "fsdb.shx",
                    XScale          = 0.75,
                };
                ObjectId textstyleid = st.Add(str2);
                acTrans.AddNewlyCreatedDBObject(str2, true);


                DimStyleTable dst = (DimStyleTable)acTrans.GetObject(acCurDb.DimStyleTableId, OpenMode.ForWrite);

                foreach (int thescale in new int[] { 75, 100 })
                {
                    DimStyleTableRecord dstr = new DimStyleTableRecord()
                    {
                        Name       = "1-" + thescale.ToString(),
                        Dimscale   = thescale,
                        Dimtxsty   = textstyleid,
                        Dimclrd    = Color.FromColorIndex(ColorMethod.ByAci, 6),
                        Dimclre    = Color.FromColorIndex(ColorMethod.ByAci, 6),
                        Dimdli     = 5.0,
                        Dimexe     = 1.0,
                        Dimexo     = 1.0,
                        DimfxlenOn = true,
                        Dimfxlen   = 4,
                        Dimtxt     = 2,
                        Dimasz     = 1.5,
                        Dimtix     = true,
                        Dimtmove   = 1,
                        Dimtad     = 1,
                        Dimgap     = 0.8,
                        Dimdec     = 0,
                        Dimtih     = false,
                        Dimtoh     = false,
                        Dimdsep    = '.',
                        Dimlfac    = 0.1,
                    };
                    ObjectId dsId = dst.Add(dstr);
                    acTrans.AddNewlyCreatedDBObject(dstr, true);
                }

                //-------------------------------------------------------------------------------------------
                // 自定义块
                //-------------------------------------------------------------------------------------------
                BlockTable       bt  = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = new BlockTableRecord();
                btr.Name = "BG";
                bt.UpgradeOpen();
                ObjectId btrId = bt.Add(btr);
                acTrans.AddNewlyCreatedDBObject(btr, true);
                Polyline Paa = new Polyline()
                {
                    Color = Color.FromColorIndex(ColorMethod.ByAci, 9),
                };
                Paa.AddVertexAt(0, new Point2d(0, 0), 0, 0, 200);
                Paa.AddVertexAt(1, new Point2d(0, 200), 0, 0, 0);
                btr.AppendEntity(Paa);
                acTrans.AddNewlyCreatedDBObject(Paa, true);
                AttributeDefinition curbg = new AttributeDefinition();
                curbg.Position    = new Point3d(120, 200, 0);
                curbg.Height      = 200;
                curbg.WidthFactor = 0.75;
                curbg.Tag         = "标高";
                curbg.TextStyleId = textstyleid;
                btr.AppendEntity(curbg);
                acTrans.AddNewlyCreatedDBObject(curbg, true);
                //-------------------------------------------------------------------------------------------
                BlockTableRecord btr2 = new BlockTableRecord();
                btr2.Name = "ZP";
                bt.UpgradeOpen();
                bt.Add(btr2);
                acTrans.AddNewlyCreatedDBObject(btr2, true);
                Polyline Paa2 = new Polyline()
                {
                    Color = Color.FromColorIndex(ColorMethod.ByAci, 9),
                };
                Paa2.AddVertexAt(0, new Point2d(0 - 350, 0), 0, 0, 80);
                Paa2.AddVertexAt(1, new Point2d(200 - 350, 0), 0, 0, 0);
                Paa2.AddVertexAt(2, new Point2d(700 - 350, 0), 0, 0, 0);
                btr2.AppendEntity(Paa2);
                acTrans.AddNewlyCreatedDBObject(Paa2, true);
                AttributeDefinition curzp = new AttributeDefinition();
                curzp.Position    = new Point3d(220 - 350, 0, 0);
                curzp.Height      = 200;
                curzp.WidthFactor = 0.75;
                curzp.Tag         = "左坡";
                curzp.TextStyleId = textstyleid;
                btr2.AppendEntity(curzp);
                acTrans.AddNewlyCreatedDBObject(curzp, true);
                //-------------------------------------------------------------------------------------------
                BlockTableRecord btr3 = new BlockTableRecord();
                btr3.Name = "YP";
                bt.UpgradeOpen();
                bt.Add(btr3);
                acTrans.AddNewlyCreatedDBObject(btr3, true);
                Polyline Paa3 = new Polyline()
                {
                    Color = Color.FromColorIndex(ColorMethod.ByAci, 9),
                };
                Paa3.AddVertexAt(0, new Point2d(0 + 350, 0), 0, 0, 80);
                Paa3.AddVertexAt(1, new Point2d(-200 + 350, 0), 0, 0, 0);
                Paa3.AddVertexAt(2, new Point2d(-700 + 350, 0), 0, 0, 0);
                btr3.AppendEntity(Paa3);
                acTrans.AddNewlyCreatedDBObject(Paa3, true);
                AttributeDefinition curyp = new AttributeDefinition();
                curyp.Position       = new Point3d(-220 + 350, 0, 0);
                curyp.HorizontalMode = TextHorizontalMode.TextRight;
                curyp.AlignmentPoint = curyp.Position;
                curyp.Height         = 200;
                curyp.WidthFactor    = 0.75;
                curyp.Tag            = "右坡";
                curyp.TextStyleId    = textstyleid;
                btr3.AppendEntity(curyp);
                acTrans.AddNewlyCreatedDBObject(curyp, true);
                //-------------------------------------------------------------------------------------------

                //-------------------------------------------------------------------------------------------
                acTrans.Commit();
            }
        }
示例#12
0
        public ObjectId ISO25(String dimStyleName)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            ObjectId dimstyleId;

            try
            {
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    DimStyleTable dt = (DimStyleTable)trans.GetObject(db.DimStyleTableId, OpenMode.ForWrite);
                    // 新建一个标注样式表记录.
                    DimStyleTableRecord dtr = new DimStyleTableRecord();
                    // 换算精度
                    dtr.Dimaltd = 3;
                    // 换算比例因子
                    dtr.Dimaltf = 0.03937008;
                    // 换算公差精度
                    dtr.Dimalttd = 3;
                    // 箭头大小
                    dtr.Dimasz = 2.5;
                    // 圆心标记大小
                    dtr.Dimcen = 2.5;
                    // 精度
                    dtr.Dimdec = 2;
                    // 尺寸线间距
                    dtr.Dimdli = 3.75;
                    // 小数分隔符
                    dtr.Dimdsep = ',';
                    //尺寸界线超出量
                    dtr.Dimexe = 1.25;
                    // 尺寸界线偏移
                    dtr.Dimexo = 0.625;
                    // 文字偏移
                    dtr.Dimgap = 0.625;
                    // 文字位置垂直
                    dtr.Dimtad = 1;
                    // 公差精度
                    dtr.Dimtdec = 2;
                    // 文字在内对齐
                    dtr.Dimtih = false;
                    // 尺寸线强制
                    dtr.Dimtofl = true;
                    // 文字外部对齐
                    dtr.Dimtoh = false;
                    // 公差位置垂直
                    dtr.Dimtolj = 0;
                    // 文字高度
                    dtr.Dimtxt = 2.5;
                    // 公差消零
                    dtr.Dimtzin = 8;
                    // 消零
                    dtr.Dimzin = 8;
                    //设置标注样式名称.
                    dtr.Name   = dimStyleName;
                    dimstyleId = dt.Add(dtr);
                    trans.AddNewlyCreatedDBObject(dtr, true);
                    trans.Commit();
                }
                return(dimstyleId);
            }
            catch
            {
                ObjectId NullId = ObjectId.Null;
                return(NullId);
            }
        }
示例#13
0
        public static void CreateModifyDimStyle(string DimStyleName, out string message)
        {
            // Initialise the message value that gets returned by an exception (or not!)
            message = string.Empty;
            try
            {
                using (Transaction tr = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())
                {
                    Database      db  = Application.DocumentManager.MdiActiveDocument.Database;
                    DimStyleTable dst = (DimStyleTable)tr.GetObject(db.DimStyleTableId, OpenMode.ForWrite, true);

                    // Initialise a DimStyleTableRecord
                    DimStyleTableRecord dstr = null;
                    // If the required dimension style exists
                    if (dst.Has(DimStyleName))
                    {
                        // get the dimension style table record open for writing
                        dstr = (DimStyleTableRecord)tr.GetObject(dst[DimStyleName], OpenMode.ForWrite);
                    }
                    else
                    {
                        // Initialise as a new dimension style table record
                        dstr = new DimStyleTableRecord();
                    }

                    // Set all the available dimension style properties
                    // Most/all of these match the variables in AutoCAD.
                    dstr.Name       = DimStyleName;
                    dstr.Annotative = AnnotativeStates.True;
                    dstr.Dimadec    = 2;
                    dstr.Dimalt     = false;
                    dstr.Dimaltd    = 2;
                    dstr.Dimaltf    = 25.4;
                    dstr.Dimaltrnd  = 0;
                    dstr.Dimalttd   = 2;
                    dstr.Dimalttz   = 0;
                    dstr.Dimaltu    = 2;
                    dstr.Dimaltz    = 0;
                    dstr.Dimapost   = "";
                    dstr.Dimarcsym  = 0;
                    dstr.Dimasz     = 3.5;
                    dstr.Dimatfit   = 3;
                    dstr.Dimaunit   = 0;
                    dstr.Dimazin    = 2;
                    dstr.Dimblk     = ObjectId.Null;
                    dstr.Dimblk1    = ObjectId.Null;
                    dstr.Dimblk2    = ObjectId.Null;
                    dstr.Dimcen     = 0.09;
                    dstr.Dimclrd    = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 7);
                    dstr.Dimclre    = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 7);;
                    dstr.Dimclrt    = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 2);;
                    dstr.Dimdec     = 2;
                    dstr.Dimdle     = 0;
                    dstr.Dimdli     = 7;
                    dstr.Dimdsep    = Convert.ToChar(".");
                    dstr.Dimexe     = 1;
                    dstr.Dimexo     = 2;
                    dstr.Dimfrac    = 0;
                    dstr.Dimfxlen   = 0.18;
                    dstr.DimfxlenOn = false;
                    dstr.Dimgap     = 1;
                    dstr.Dimjogang  = 0;
                    dstr.Dimjust    = 0;
                    dstr.Dimldrblk  = ObjectId.Null;
                    dstr.Dimlfac    = 1;
                    dstr.Dimlim     = false;

                    ObjectId ltId = GetLinestyleID("Continuous");
                    dstr.Dimltex1 = ltId;
                    dstr.Dimltex2 = ltId;
                    dstr.Dimltype = ltId;

                    dstr.Dimlunit    = 2;
                    dstr.Dimlwd      = LineWeight.LineWeight015;
                    dstr.Dimlwe      = LineWeight.LineWeight015;
                    dstr.Dimpost     = "";
                    dstr.Dimrnd      = 0;
                    dstr.Dimsah      = false;
                    dstr.Dimscale    = 1;
                    dstr.Dimsd1      = false;
                    dstr.Dimsd2      = false;
                    dstr.Dimse1      = false;
                    dstr.Dimse2      = false;
                    dstr.Dimsoxd     = false;
                    dstr.Dimtad      = 2;
                    dstr.Dimtdec     = 2;
                    dstr.Dimtfac     = 1;
                    dstr.Dimtfill    = 0;
                    dstr.Dimtfillclr = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 0);
                    dstr.Dimtih      = false;
                    dstr.Dimtix      = false;
                    dstr.Dimtm       = 0;
                    dstr.Dimtmove    = 0;
                    dstr.Dimtofl     = false;
                    dstr.Dimtoh      = false;
                    dstr.Dimtol      = false;
                    dstr.Dimtolj     = 1;
                    dstr.Dimtp       = 0;
                    dstr.Dimtsz      = 0;
                    dstr.Dimtvp      = 0;

                    // Test for the text style to be used
                    ObjectId tsId = ObjectId.Null;
                    // If it doesn't exist
                    if (!CheckTextStyle("BF-标注文字"))
                    {
                        // Create the required text style
                        CreateTextStyle("BF-标注文字", "simplex.shx", 0, out string massage);
                        tsId = GetTextStyleId("BF-标注文字");
                    }
                    else
                    {
                        // Get the ObjectId of the text style
                        tsId = GetTextStyleId("BF-标注文字");
                    }

                    dstr.Dimtxsty        = tsId;
                    dstr.Dimtxt          = 2.5;
                    dstr.Dimtxtdirection = false;
                    dstr.Dimtzin         = 0;
                    dstr.Dimupt          = false;
                    dstr.Dimzin          = 0;

                    // If the dimension style doesn't exist
                    if (!dst.Has(DimStyleName))
                    {
                        // Add it to the dimension style table and collect its Id
                        Object dsId = dst.Add(dstr);
                        // Add the new dimension style table record to the document
                        tr.AddNewlyCreatedDBObject(dstr, true);
                    }

                    // Commit the changes.
                    tr.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
                message = e.Message.ToString();
            }
        }
示例#14
0
        public static ObjectId Create_HDC_DimensionStyle(string StyleName)
        {
            var DimId = ObjectId.Null;

            using (Transaction T = AC.DB.TransactionManager.StartTransaction())
            {
                DimStyleTable DST = T.GetObject(AC.DB.DimStyleTableId, OpenMode.ForWrite) as DimStyleTable;

                switch (StyleName)
                {
                case "HDC_Dim_Style":

                    #region 생성
                    if (!DST.Has(StyleName))
                    {
                        DST.UpgradeOpen();

                        var dstr = new DimStyleTableRecord()
                        {
                            Name    = StyleName,              // 스타일 이름
                            Dimasz  = 0,                      // 화살표 크기
                            Dimtxt  = 100,                    // 문자 크기
                            Dimexo  = 100,                    // 원점에서 간격띄우기 값
                            Dimclrt = ColorIndex.Yellow,      // 문자 색상
                            Dimclrd = ColorIndex.Yellow,      // 치수선 생상
                            Dimclre = ColorIndex.Gray,        // 치수보조선 색생
                            Dimtad  = 0,                      // 1: 치수선 위에 입력, 0: 치수선 상에 입력
                            Dimtoh  = false,                  // 문자 정렬(On/On: 수평, Off/Off: 치수선, On/Off: ISO)
                            Dimtih  = false,                  // 문자 정렬(On/On: 수평, Off/Off: 치수선, On/Off: ISO)
                            Dimdec  = 0,                      // 소수점 자릿수
                            Dimsd1  = true,                   // 치수선1 억제
                            Dimsd2  = true,                   // 치수선2 억제
                            Dimse1  = true,                   // 치수보조선1 억제
                            Dimse2  = true,                   // 치수보조선1 억제
                            Dimtix  = true,
                        };

                        DimId = DST.Add(dstr);
                        T.AddNewlyCreatedDBObject(dstr, true);
                    }
                    #endregion

                    #region 수정
                    else
                    {
                        DimId = DST[StyleName];

                        var dstr = T.GetObject(DimId, OpenMode.ForWrite) as DimStyleTableRecord;

                        dstr.Name    = StyleName;
                        dstr.Dimasz  = 0;
                        dstr.Dimtxt  = 100;
                        dstr.Dimexo  = 100;
                        dstr.Dimgap  = 50;
                        dstr.Dimclrt = ColorIndex.Yellow;
                        dstr.Dimclrd = ColorIndex.Yellow;
                        dstr.Dimclre = ColorIndex.Gray;
                        dstr.Dimtad  = 0;
                        dstr.Dimtoh  = false;
                        dstr.Dimtih  = false;
                        dstr.Dimdec  = 0;
                        dstr.Dimsd1  = true;                    // 치수선1 억제
                        dstr.Dimsd2  = true;                    // 치수선2 억제
                        dstr.Dimse1  = true;                    // 치수보조선1 억제
                        dstr.Dimse2  = true;                    // 치수보조선1 억제
                        dstr.Dimtix  = true;
                    }
                    #endregion

                    T.Commit();
                    break;

                case "HDC_도면 치수선":

                    #region 생성
                    if (!DST.Has(StyleName))
                    {
                        DST.UpgradeOpen();

                        var dstr = new DimStyleTableRecord();
                        dstr.Name = StyleName;                                   // 스타일 이름

                        dstr.Dimasz  = 10;                                       // 화살표 크기
                        dstr.Dimblk  = GetArrowObjectId("DIMBLK", "_ARCHTICK");
                        dstr.Dimblk1 = GetArrowObjectId("DIMBLK1", "_ARCHTICK"); // 화살표 모양 (_ARCHTICK : 건축 눈금)
                        dstr.Dimblk2 = GetArrowObjectId("DIMBLK2", "_ARCHTICK"); // 화살표 모양 (_ARCHTICK : 건축 눈금)

                        dstr.Dimtxt = 100;                                       // 문자 크기
                        dstr.Dimexo = 150;                                       // 원점에서 간격띄우기 값

                        dstr.Dimclrt = ColorIndex.Green;                         // 문자 색상
                        dstr.Dimclrd = ColorIndex.RGB(255, 63, 0);               // 치수선 생상
                        dstr.Dimclre = ColorIndex.RGB(255, 63, 0);               // 치수보조선 색생

                        dstr.Dimtad = 1;                                         // 1: 치수선 위에 입력, 0: 치수선 상에 입력
                        dstr.Dimtoh = false;                                     // 문자 정렬(On/On: 수평, Off/Off: 치수선, On/Off: ISO)
                        dstr.Dimtih = false;                                     // 문자 정렬(On/On: 수평, Off/Off: 치수선, On/Off: ISO)
                        dstr.Dimdec = 0;                                         // 소수점 자릿수
                        dstr.Dimsd1 = false;                                     // 치수선1 억제
                        dstr.Dimsd2 = false;                                     // 치수선2 억제
                        dstr.Dimse1 = false;                                     // 치수보조선1 억제
                        dstr.Dimse2 = false;                                     // 치수보조선1 억제

                        DimId = DST.Add(dstr);

                        T.AddNewlyCreatedDBObject(dstr, true);
                    }
                    #endregion

                    #region 수정
                    else
                    {
                        DimId = DST[StyleName];

                        var dstr = T.GetObject(DimId, OpenMode.ForWrite) as DimStyleTableRecord;

                        dstr.Name = StyleName;

                        dstr.Dimasz  = 10;
                        dstr.Dimblk  = GetArrowObjectId("DIMBLK", "_ARCHTICK");
                        dstr.Dimblk1 = GetArrowObjectId("DIMBLK1", "_ARCHTICK");
                        dstr.Dimblk2 = GetArrowObjectId("DIMBLK2", "_ARCHTICK");

                        dstr.Dimtxt = 100;
                        dstr.Dimexo = 150;
                        dstr.Dimgap = 50;

                        dstr.Dimclrt = ColorIndex.Green;
                        dstr.Dimclrd = ColorIndex.RGB(255, 63, 0);
                        dstr.Dimclre = ColorIndex.RGB(255, 63, 0);

                        dstr.Dimtad = 1;
                        dstr.Dimtoh = false;
                        dstr.Dimtih = false;
                        dstr.Dimdec = 0;
                        dstr.Dimsd1 = false;                     // 치수선1 억제
                        dstr.Dimsd2 = false;                     // 치수선2 억제
                        dstr.Dimse1 = false;                     // 치수보조선1 억제
                        dstr.Dimse2 = false;                     // 치수보조선1 억제
                                                                 //dstr.Dimfxlen = 700;
                                                                 //dstr.Dimtix = true;
                    }
                    #endregion

                    T.Commit();
                    break;
                }
            }

            return(DimId);
        }
示例#15
0
        /// <summary>
        /// 치수선 스타일 만들기
        /// </summary>
        /// <param name="StyleName"></param>
        public static ObjectId Create_DimensionStyle(string StyleName)
        {
            var DimId = ObjectId.Null;

            #region T
            using (Transaction T = AC.DB.TransactionManager.StartTransaction())
            {
                DimStyleTable DST = T.GetObject(AC.DB.DimStyleTableId, OpenMode.ForWrite) as DimStyleTable;

                if (!DST.Has(StyleName))
                {
                    #region 생성
                    DST.UpgradeOpen();

                    var dstr = new DimStyleTableRecord()
                    {
                        Name    = StyleName,            // 스타일 이름
                        Dimasz  = 100,                  // 화살표 크기
                        Dimtxt  = 50,                   // 문자 크기
                        Dimexo  = 50,                   // 원점에서 간격띄우기 값
                        Dimclrt = ColorIndex.Yellow,    // 문자 색상
                        Dimclrd = ColorIndex.Yellow,    // 치수선 생상
                        Dimclre = ColorIndex.Gray,      // 치수보조선 색생
                        Dimtad  = 0,                    // 1: 치수선 위에 입력, 0: 치수선 상에 입력
                        Dimtoh  = false,                // 문자 정렬(On/On: 수평, Off/Off: 치수선, On/Off: ISO)
                        Dimtih  = false,                // 문자 정렬(On/On: 수평, Off/Off: 치수선, On/Off: ISO)
                        Dimdec  = 0,                    // 소수점 자릿수
                    };

                    DimId = DST.Add(dstr);

                    T.AddNewlyCreatedDBObject(dstr, true);
                    #endregion
                }
                else
                {
                    #region 수정
                    DimId = DST[StyleName];

                    var dstr = T.GetObject(DimId, OpenMode.ForWrite) as DimStyleTableRecord;

                    dstr.Name    = StyleName;
                    dstr.Dimasz  = 50;
                    dstr.Dimtxt  = 50;
                    dstr.Dimexo  = 0;
                    dstr.Dimgap  = 50;
                    dstr.Dimclrt = ColorIndex.Yellow;
                    dstr.Dimclrd = ColorIndex.Yellow;
                    dstr.Dimclre = ColorIndex.Gray;
                    dstr.Dimtad  = 0;
                    dstr.Dimtoh  = false;
                    dstr.Dimtih  = false;
                    dstr.Dimdec  = 0;
                    #endregion
                }

                T.Commit();
            }
            #endregion

            return(DimId);
        }