Esempio n. 1
0
        public static BlockReference InsertBlockReference(this BlockTableRecord target, string blkName, Point3d insertPoint, Dictionary <string, string> attValues = null)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            Database    db = target.Database;
            Transaction tr = db.TransactionManager.TopTransaction;

            if (tr == null)
            {
                throw new AcRx.Exception(ErrorStatus.NoActiveTransactions);
            }
            BlockReference br    = null;
            BlockTable     bt    = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
            ObjectId       btrId = bt.GetBlock(blkName);

            if (btrId != ObjectId.Null)
            {
                br = new BlockReference(insertPoint, btrId);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);
                target.AppendEntity(br);
                tr.AddNewlyCreatedDBObject(br, true);
                br.AddAttributeReferences(attValues);
            }
            return(br);
        }
Esempio n. 2
0
        public void IncrementAttribute(BlockTableRecord TableRecord, int index, string prefix, string suffix)
        {
            string           startValue = this.dlg.StartValue;
            int              num        = 0;
            Stack <ObjectId> objectIds  = new Stack <ObjectId>();
            Stack <string>   strs       = new Stack <string>();

            while (true)
            {
                using (BlockReference blockRef = new BlockReference(Point3d.Origin, TableRecord.ObjectId))
                {
                    blockRef.Rotation     = this.dlg.BlockRotation;
                    blockRef.ScaleFactors = new Scale3d(this.dlg.BlockScale);
                    blockRef.TransformBy(this.ed.CurrentUserCoordinateSystem);
                    if (blockRef.Annotative == AnnotativeStates.True)
                    {
                        ObjectContextCollection contextCollection = this.db.ObjectContextManager.GetContextCollection("ACDB_ANNOTATIONSCALES");
                        Autodesk.AutoCAD.Internal.ObjectContexts.AddContext(blockRef, contextCollection.CurrentContext);
                    }
                    ObjectId objectId = this.db.GetCurrentSpace(OpenMode.ForWrite).Add(blockRef);
                    blockRef.AddAttributeReferences(index, string.Concat(prefix, startValue, suffix));
                    BlockJig     blockJig     = new BlockJig(blockRef, num, TableRecord.GetAttributesTextInfos());
                    PromptResult promptResult = this.ed.Drag(blockJig);
                    if (promptResult.Status == PromptStatus.Keyword)
                    {
                        blockRef.Erase();
                        if (num != 0)
                        {
                            objectIds.Pop().GetObject <BlockReference>(OpenMode.ForWrite).Erase();
                            this.db.TransactionManager.QueueForGraphicsFlush();
                            startValue = strs.Pop();
                            num--;
                        }
                        else
                        {
                            this.ed.WriteMessage("\nNothing to undo !");
                        }
                    }
                    else if (promptResult.Status == PromptStatus.OK)
                    {
                        this.db.TransactionManager.QueueForGraphicsFlush();
                        strs.Push(startValue);
                        objectIds.Push(objectId);
                        startValue = this.Increment(startValue);
                        num++;
                    }
                    else
                    {
                        blockRef.Erase();
                        break;
                    }
                }
            }
            this.dlg.txtValue.Text = startValue;
        }