Exemplo n.º 1
0
Arquivo: Txt.cs Projeto: 15831944/EM
        makeTextStyle(string nameStyle, AnnotativeStates annoState = AnnotativeStates.True, double xFactor = 0.8)
        {
            Database db = BaseObjs._db;

            TextStyleTable tst;
            ObjectId       idTxtStyle = ObjectId.Null;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    tst = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForWrite);
                    TextStyleTableRecord tstr = new TextStyleTableRecord();
                    tstr.Name           = nameStyle;
                    tstr.Annotative     = annoState;
                    tstr.FileName       = "romans.shx";
                    tstr.TextSize       = 0.0;
                    tstr.ObliquingAngle = 0.0;
                    tstr.IsVertical     = false;
                    tstr.IsShapeFile    = false;
                    tstr.XScale         = xFactor;

                    tst.Add(tstr);
                    idTxtStyle = tstr.ObjectId;
                    tr.AddNewlyCreatedDBObject(tstr, true);

                    tr.Commit();
                }// end using
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Txt.cs: line: 543");
            }
            return(idTxtStyle);
        }
Exemplo n.º 2
0
        public EntityDrawer(List <Entity> entities, AnnotativeStates annotative, Matrix3d transformFromUcsToWcs)
            : base()
        {
            _ucs        = transformFromUcsToWcs;
            _annotative = annotative;

            _db       = Tools.GetAcadDatabase();
            _entities = entities;
        }
Exemplo n.º 3
0
        public MultiEntity(Point3d insertPoint, Point3d originWcs, List <Entity> entities, AnnotativeStates annotative, Matrix3d transformFromUcsToWcs)
            : base()
        {
            _innerBlockTransform = Matrix3d.Identity;
            _ucs            = transformFromUcsToWcs;
            _insertPointUcs = insertPoint;
            _annotative     = annotative;
            _originWcs      = originWcs;

            _db       = Tools.GetAcadDatabase();
            _entities = entities;
        }
        public SimpleEntityOverrideEx(Point3d origin, AnnotativeStates annotativeState, List <Entity> entities, Matrix3d ucs)
            : base()
        {
            _ucs = ucs;

            _origin          = origin.TransformBy(_ucs);
            _annotativeState = annotativeState;

            _db       = Tools.GetAcadDatabase();
            _entities = entities;

            _blockId     = ObjectId.Null;
            _insertPoint = Point3d.Origin;

            _createBlockRecord(_name, _annotativeState, _origin);
        }
Exemplo n.º 5
0
Arquivo: Txt.cs Projeto: 15831944/EM
        addText(string contents, Point3d pnt3d, double angle, AttachmentPoint attachPoint,
                string nameStyle = "Annotative", AnnotativeStates annoState = AnnotativeStates.True)
        {
            ObjectId idTxt = ObjectId.Null;
            Database DB    = BaseObjs._db;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    BlockTableRecord ms  = Blocks.getBlockTableRecordMS();
                    TextStyleTable   tst = (TextStyleTable)tr.GetObject(DB.TextStyleTableId, OpenMode.ForRead);

                    ObjectId idTxtStyle = ObjectId.Null;

                    if (!tst.Has(nameStyle))
                    {
                        makeTextStyle(nameStyle, annoState);
                        idTxtStyle = tst[nameStyle];
                    }

                    using (DBText txt = new DBText())
                    {
                        txt.SetDatabaseDefaults();
                        txt.TextString = contents;
                        txt.Position   = pnt3d;

                        txt.Rotation    = angle;
                        txt.Justify     = attachPoint;
                        txt.TextStyleId = idTxtStyle;

                        ms.AppendEntity(txt);
                        tr.AddNewlyCreatedDBObject(txt, true);
                        tr.Commit();
                    }
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Txt.cs: line: 161");
            }
            return(idTxt);
        }
        private void _createBlockRecord(string name, AnnotativeStates annotativeState, Point3d origin, bool eraseSource = true)
        {
            BlockTableRecord btr = new BlockTableRecord();

            btr.Name       = name;
            btr.Origin     = origin;
            btr.Annotative = annotativeState;

            if (eraseSource)
            {
                Tools.StartTransaction(() =>
                {
                    if (_blockRecordId != ObjectId.Null)
                    {
                        BlockTableRecord btrOld = _blockRecordId.GetObjectForWrite <BlockTableRecord>();
                        btrOld.Erase();
                    }
                });
            }

            Tools.StartTransaction(() =>
            {
                var bt = _db.BlockTableId.GetObjectForWrite <BlockTable>(false);

                bt.UpgradeOpen();
                ObjectId btrId = bt.Add(btr);

                _db.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(btr, true);
                this._blockRecordId = btrId;

                foreach (Entity ent in _entities)
                {
                    btr.AppendEntity(ent);
                    _db.TransactionManager.TopTransaction.AddNewlyCreatedDBObject(ent, true);
                }
            });
        }
Exemplo n.º 7
0
        public static ObjectId CreateBlockTableRecordEx(Point3d origin, string name, List <Entity> entities, AnnotativeStates aState, Transaction trans, bool commit, bool rewriteBlock = false)
        {
            var bt = (BlockTable)trans.GetObject(Tools.GetAcadDatabase().BlockTableId, OpenMode.ForRead);

            // Validate the provided symbol table name

            if (name != "*U")
            {
                SymbolUtilityServices.ValidateSymbolName(
                    name,
                    false
                    );

                // Only set the block name if it isn't in use

                if (bt.Has(name))
                {
                    //throw new ArgumentException(string.Format("A block with this name \"{0}\" already exists.", name));
                    if (!rewriteBlock)
                    {
                        return(bt[name]);
                    }
                    else
                    {
                        throw new ArgumentException(string.Format("A block with this name \"{0}\" already exists.", name));
                    }
                }
            }

            // Create our new block table record...

            BlockTableRecord btr = new BlockTableRecord();

            // ... and set its properties

            btr.Name       = name;
            btr.Origin     = origin;
            btr.Annotative = aState;


            // Add the new block to the block table

            bt.UpgradeOpen();
            ObjectId btrId = bt.Add(btr);

            trans.AddNewlyCreatedDBObject(btr, true);

            foreach (Entity ent in entities)
            {
                btr.AppendEntity(ent);
                trans.AddNewlyCreatedDBObject(ent, true);
            }


            // Commit the transaction

            if (commit)
            {
                trans.Commit();
            }

            return(btr.Id);
        }
Exemplo n.º 8
0
 public static ObjectId CreateBlockTableRecordEx(Point3d origin, string name, List <Entity> entities, AnnotativeStates aState, bool rewriteBlock = false)
 {
     using (Transaction trans = Tools.StartTransaction())
     {
         var res = CreateBlockTableRecordEx(origin, name, entities, aState, trans, true, rewriteBlock);
         return(res);
     }
 }
Exemplo n.º 9
0
        public static ObjectId CreateBlockTableRecord(string name, Point3d origin, IEnumerable <Entity> entities, AnnotativeStates annotative, bool getIfExists = false)
        {
            ObjectId btrId = ObjectId.Null;

            Tools.StartTransaction(() =>
            {
                Transaction trans = Tools.GetAcadDatabase().TransactionManager.TopTransaction;

                var bt = Tools.GetAcadDatabase().BlockTableId.GetObjectForRead <BlockTable>();

                if (name != "*U")
                {
                    SymbolUtilityServices.ValidateSymbolName(
                        name,
                        false
                        );

                    if (bt.Has(name))
                    {
                        if (!getIfExists)
                        {
                            btrId = bt[name];
                        }
                        else
                        {
                            throw new ArgumentException(string.Format("A block with this name \"{0}\" already exists.", name));
                        }
                    }
                }

                BlockTableRecord btr = new BlockTableRecord
                {
                    Name       = name,
                    Origin     = origin,
                    Annotative = annotative
                };

                bt.UpgradeOpen();
                btrId = bt.Add(btr);
                trans.AddNewlyCreatedDBObject(btr, true);

                foreach (Entity ent in entities)
                {
                    btr.AppendEntity(ent);
                    trans.AddNewlyCreatedDBObject(ent, true);
                }
            });
            return(btrId);
        }
Exemplo n.º 10
0
Arquivo: Txt.cs Projeto: 15831944/EM
        addMText(string strCallout, Point3d pnt3d1, double dblRotation, double width, double txtSize = 0.09,
                 AttachmentPoint attachPnt  = AttachmentPoint.MiddleCenter, string nameStyle = "Annotative",
                 string nameLayer           = "TEXT", Color color = null, string justify = null,
                 AnnotativeStates annoState = AnnotativeStates.True,
                 double xFactor             = 0.8, bool bold = false,
                 bool backgroundFill        = false)
        {
            ObjectId idMtxt     = ObjectId.Null;
            ObjectId idTxtStyle = ObjectId.Null;
            Database DB         = BaseObjs._db;
            MText    mtext      = null;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    BlockTable       BT  = (BlockTable)tr.GetObject(DB.BlockTableId, OpenMode.ForRead);
                    BlockTableRecord MS  = (BlockTableRecord)tr.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                    TextStyleTable   TST = (TextStyleTable)tr.GetObject(DB.TextStyleTableId, OpenMode.ForRead);

                    if (!TST.Has(nameStyle))
                    {
                        idTxtStyle = makeTextStyle(nameStyle, annoState);
                    }
                    else
                    {
                        idTxtStyle = TST[nameStyle];
                        setTextStyleXScale(idTxtStyle, xFactor);
                    }

                    mtext = new MText();
                    mtext.SetDatabaseDefaults();

                    try
                    {
                        mtext.Layer = nameLayer;
                    }
                    catch (System.Exception ex)
                    {
                        BaseObjs.writeDebug(ex.Message + " Txt.cs: line: 61");
                    }

                    if (color == null)
                    {
                        color = new Color();
                        color = Color.FromColorIndex(ColorMethod.ByLayer, 256);
                    }

                    mtext.Color    = color;
                    mtext.Location = pnt3d1;

                    mtext.Rotation    = dblRotation;
                    mtext.Annotative  = annoState;
                    mtext.Width       = width;
                    mtext.TextStyleId = idTxtStyle;

                    mtext.TextHeight     = txtSize * Base_Tools45.Misc.getCurrAnnoScale();
                    mtext.BackgroundFill = backgroundFill;
                    if (backgroundFill)
                    {
                        mtext.BackgroundFillColor   = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 1);
                        mtext.UseBackgroundColor    = true;
                        mtext.BackgroundScaleFactor = 1.25;
                    }

                    if (justify == null)
                    {
                        justify = Pub.JUSTIFYLEFT;
                    }

                    string xScale = xFactor.ToString();

                    if (bold && xFactor != 0.8)
                    {
                        mtext.Contents = string.Format("{0}{{\\fromans.shx|b1|\\W{1};{2}}}", justify, xScale, strCallout);
                    }
                    else if (bold)
                    {
                        mtext.Contents = string.Format("{0}{{\\fromans.shx|b1|;{1}}}", justify, strCallout);
                    }
                    else
                    {
                        mtext.Contents = string.Format("{0}{{\\fromans.shx\\W{1};{2}}}", justify, xScale, strCallout);
                    }

                    mtext.Attachment = attachPnt;
                    MS.AppendEntity(mtext);
                    tr.AddNewlyCreatedDBObject(mtext, true);
                    idMtxt = mtext.ObjectId;
                    tr.Commit();
                }//end using
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Txt.cs: line: 108");
            }
            return(idMtxt);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 设置文字样式的有关属性
        /// </summary>
        /// <param name="styleId">文字样式的Id</param>
        /// <param name="textSize">高度</param>
        /// <param name="xscale">宽度因子</param>
        /// <param name="obliquingAngle">倾斜角度</param>
        /// <param name="isVertical">是否垂直</param>
        /// <param name="upsideDown">是否上下颠倒</param>
        /// <param name="backwards">是否反向</param>
        /// <param name="annotative">是否具有注释性</param>
        /// <param name="paperOrientation">文字方向与布局是否匹配</param>
        public static void SetTextStyleProp(this ObjectId styleId, double textSize, double xscale, double obliquingAngle, bool isVertical, bool upsideDown, bool backwards, AnnotativeStates annotative, bool paperOrientation)
        {
            //打开文字样式表记录
            TextStyleTableRecord str = styleId.GetObject(OpenMode.ForWrite) as TextStyleTableRecord;

            if (str == null)
            {
                return;                                          ////如果styleId表示是不是文字样式表记录,则返回
            }
            str.TextSize       = textSize;                       //高度
            str.XScale         = xscale;                         //宽度因子
            str.ObliquingAngle = obliquingAngle;                 //倾斜角度
            str.IsVertical     = isVertical;                     //是否垂直
            str.FlagBits       = (byte)0;
            str.FlagBits      += upsideDown ? (byte)2 : (byte)0; //是否上下颠倒
            str.FlagBits      += backwards ? (byte)4 : (byte)0;  //是否反向
            str.Annotative     = annotative;                     //是否具有注释性
            str.SetPaperOrientation(paperOrientation);           //文字方向与布局是否匹配
            str.DowngradeOpen();                                 //为了安全切换为读的状态
        }