Beispiel #1
0
        public void DisplaceBlock(BlockReference br)
        {
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Block table for read
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             OpenMode.ForWrite) as BlockTable;

                // Open the Block table record Model space for write
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForWrite) as BlockTableRecord;

                float Zbottom = (float)(ZOnSurface - Z0);

                // Position the center of the block
                br.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, Zbottom) -
                                                     Point3d.Origin));

                Matrix3d           curUCSMatrix = doc.Editor.CurrentUserCoordinateSystem;
                CoordinateSystem3d curUCS       = curUCSMatrix.CoordinateSystem3d;

                // Rotate the block around the axis that is defined by the points
                Vector3d vRot = new Point3d(X1, Y1, Z1).
                                GetVectorTo(new Point3d(X0, Y0, ZOnSurface));

                br.TransformBy(Matrix3d.Rotation(Slope, vRot, new Point3d(X0, Y0, ZOnSurface)));

                // Save the new objects to the database
                acTrans.Commit();
            }
        }
Beispiel #2
0
        public static ObjectId InsertBlock(Point3d anchorPoint, double Rotation, ObjectId BlockID)
        {
            // Get the current document and database
            Document acDoc              = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb            = acDoc.Database;
            ObjectContextCollection occ = acCurDb.ObjectContextManager.GetContextCollection("ACDB_ANNOTATIONSCALES");

            Transaction acTrans = acDoc.TransactionManager.TopTransaction;

            // Open the Block table for read
            BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

            BlockTableRecord blockDef = BlockID.GetObject(OpenMode.ForRead) as BlockTableRecord;

            // Open the Block table record Model space for write
            BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            // Insert the block into the current space
            using (BlockReference acBlkRef = new BlockReference(anchorPoint, BlockID))
            {
                Matrix3d           curUCSMatrix = Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem;
                CoordinateSystem3d curUCS       = curUCSMatrix.CoordinateSystem3d;

                acBlkRef.TransformBy(Matrix3d.Rotation(Rotation, curUCS.Zaxis, anchorPoint));
                //For some unknown reason this is needed in Civil3D
                //TODO: Find reason below line is needed and fix it
                acBlkRef.TransformBy(Matrix3d.Scaling(1000, anchorPoint));

                acBlkRef.AddContext(occ.GetContext("1:1"));

                acBlkTblRec = acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                acBlkTblRec.AppendEntity(acBlkRef);
                acTrans.AddNewlyCreatedDBObject(acBlkRef, true);

                // AttributeDefinitions
                foreach (ObjectId id in blockDef)
                {
                    DBObject            obj    = id.GetObject(OpenMode.ForRead);
                    AttributeDefinition attDef = obj as AttributeDefinition;
                    if ((attDef != null) && (!attDef.Constant))
                    {
                        //This is a non-constant AttributeDefinition
                        //Create a new AttributeReference
                        using (AttributeReference attRef = new AttributeReference())
                        {
                            attRef.SetAttributeFromBlock(attDef, acBlkRef.BlockTransform);
                            attRef.TextString = "0";
                            //Add the AttributeReference to the BlockReference
                            acBlkRef.AttributeCollection.AppendAttribute(attRef);
                            acTrans.AddNewlyCreatedDBObject(attRef, true);
                        }
                    }
                }

                return(acBlkRef.ObjectId);
            }
        }
Beispiel #3
0
        public static void TecTest()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            using (Transaction Tx = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord ms      = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
                RXObject         brClass = RXObject.GetClass(typeof(BlockReference));

                Point3d lastrightpt = new Point3d(0, 0, 0);

                foreach (ObjectId id in ms)
                {
                    if (id.ObjectClass == brClass)
                    {
                        BlockReference br = (BlockReference)Tx.GetObject(id, OpenMode.ForWrite);
                        ed.WriteMessage("NAME:{0}\n", br.Name);
                        Extents3d bounds = br.GeometricExtents;
                        ed.WriteMessage("BOUNDS: {0}\n", bounds.ToString());
                        Vector3d vec = (Vector3d)(lastrightpt - bounds.MinPoint);
                        ed.WriteMessage("VECTOR: {0}\n", vec.ToString());

                        Point3d  rightpt = new Point3d(bounds.MaxPoint.X, bounds.MinPoint.Y, 0);;
                        Vector3d newrp   = (Vector3d)(vec + rightpt.GetAsVector() + (new Vector3d(50, 0, 0)));
                        lastrightpt = new Point3d(newrp.X, newrp.Y, 0);
                        ed.WriteMessage("NEWLASTRIGHT SET to {0}\n", lastrightpt);
                        Matrix3d mat = Matrix3d.Displacement(vec);
                        br.TransformBy(mat);
                    }
                }
                Tx.Commit();
            }
        }
Beispiel #4
0
        //******************* wstawianie bloku
        public void wstawblok(
            Database db,
            Editor ed,
            Point3d pnkwstaw,
            double kat,
            string attText,
            double atangle,
            string blockName,
            string attTag,
            string warstwa
            )
        {
            using (Transaction tr1 = db.TransactionManager.StartTransaction())
            {
                BlockTable       bt  = (BlockTable)tr1.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)tr1.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                using (BlockReference br = new BlockReference(Point3d.Origin, bt[blockName]))
                {
                    br.Rotation = RadiansToDegrees(kat);
                    br.Layer    = warstwa;
                    br.TransformBy(Matrix3d
                                   .Displacement(pnkwstaw - Point3d.Origin)
                                   .PreMultiplyBy(ed.CurrentUserCoordinateSystem));

                    btr.AppendEntity(br);
                    tr1.AddNewlyCreatedDBObject(br, true);
                    InsertAttibuteInBlockRef(br, attTag, attText, atangle, tr1);
                }
                tr1.Commit();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Вставка вхождения блока
        /// </summary>
        public static BlockReference InsertBlockRef(
            ObjectId btrId,
            Point3d pt,
            [NotNull] BlockTableRecord owner,
            [NotNull] Transaction t,
            double scale = 1)
        {
            var db    = owner.Database;
            var blRef = new BlockReference(pt, btrId)
            {
                Position = pt
            };

            if (blRef.Annotative == AnnotativeStates.True)
            {
                // Установка аннотативного масштаба
                blRef.AddContext(db.Cannoscale);
            }
            else if (Math.Abs(scale - 1) > 0.001)
            {
                blRef.TransformBy(Matrix3d.Scaling(scale, pt));
            }

            owner.AppendEntity(blRef);
            t.AddNewlyCreatedDBObject(blRef, true);
            AddAttributes(blRef, btrId.GetObjectT <BlockTableRecord>(), t);
            return(blRef);
        }
Beispiel #6
0
        private void addVerticalSectionMark()
        {
            // Определение X сечения в панели
            // Если есть окно, то сечение по первому окну
            var    win  = panelBase.Panel.windows?.window?.First();
            double xSec = (win == null) ? 750 : win.posi.X + 250;

            double yTop = yDimLineTopMax + 230;
            double yBot = yDimLineBotMin - 145;

            Point3d        ptTopCross    = new Point3d(xSec, yTop, 0);
            Point3d        ptBotCross    = new Point3d(xSec, yBot, 0);
            BlockReference blRefCrossTop = CreateBlRefInBtrDim(ptTopCross, panelBase.Service.Env.IdBtrCross, Settings.Default.SheetScale);

            if (blRefCrossTop == null)
            {
                return;
            }
            var attrRefTop = addAttrToBlockCross(blRefCrossTop, "2");

            BlockReference blRefCrossBot = CreateBlRefInBtrDim(ptBotCross, panelBase.Service.Env.IdBtrCross, Settings.Default.SheetScale);

            if (blRefCrossBot == null)
            {
                return;
            }
            Matrix3d matrixMirrBotCross = Matrix3d.Mirroring(new Line3d(ptBotCross,
                                                                        new Point3d(ptBotCross.X + 1, ptBotCross.Y, ptBotCross.Z)));

            blRefCrossBot.TransformBy(matrixMirrBotCross);
            var attrRefBot = addAttrToBlockCross(blRefCrossBot, "2");

            attrRefBot.TransformBy(Matrix3d.Mirroring(new Line3d(attrRefBot.AlignmentPoint,
                                                                 new Point3d(attrRefBot.AlignmentPoint.X + 1, attrRefBot.AlignmentPoint.Y, attrRefBot.AlignmentPoint.Z))));
        }
Beispiel #7
0
            public ObjectId AppendBlock(Point3d position, Point3d valuePoint)
            {
                Matrix3d rot = Matrix3d.Rotation(this.SpecifyAngle, this.Matrix.CoordinateSystem3d.Zaxis, position);

                if (this.SpecifyAngle != 0d)
                {
                    position   = position.TransformBy(rot);
                    valuePoint = valuePoint.TransformBy(rot);
                }

                double value = Mode == DirectionMode.Horizontal ?
                               _calcValue(position, valuePoint).X :
                               _calcValue(position, valuePoint).Y;

                ObjectId brId = BlockTools.AddBlockRefToModelSpace(this.BlockTableRecordId,
                                                                   new List <string>(new[] { Math.Abs(Math.Round(value * 1000d, 0)).ToString() }), position, Matrix);

                using (Transaction trans = Tools.StartTransaction())
                {
                    BlockReference br = (BlockReference)trans.GetObject(brId, OpenMode.ForRead);
                    br.UpgradeOpen();
                    if (value < 0)
                    {
                        Mirror(br);
                    }
                    if (this.SpecifyAngle != 0d)
                    {
                        br.TransformBy(rot);
                    }
                    trans.Commit();
                }
                return(brId);
            }
Beispiel #8
0
        public BlockInsertJig([NotNull] BlockReference br) : base(br)
        {
            var ed = AcadHelper.Doc.Editor;

            br.TransformBy(ed.CurrentUserCoordinateSystem);
            mCenterPt = br.Position;
        }
Beispiel #9
0
        public static void MirroringBlockByXAxis(BlockReference br)
        {
            CoordinateSystem.CoordinateTools.MirrorAtXAxis(br, br.Position);
            Matrix3d mat = Matrix3d.Mirroring(new Plane(br.Position, br.BlockTransform.CoordinateSystem3d.Zaxis));

            br.TransformBy(mat);
        }
Beispiel #10
0
        private void FixOrientation(Part part, Point3d loc, double orientationAngle, BlockReference blkRef)
        {
            var pivotVector = part.PivotPoint - Point3d.Origin;

            blkRef.Position = blkRef.Position.Add(pivotVector);
            blkRef.TransformBy(Matrix3d.Rotation(orientationAngle, _acad.UCS.Zaxis, loc));
            blkRef.Position = blkRef.Position.Add(new Vector3d(part.Height, 0, 0));
        }
Beispiel #11
0
        public static ObjectId AppendBlockItem(Point3d insertPoint, ObjectId blockTableRecordId,
                                               List <string> attrTextValues, Matrix3d toWcsTransform)
        {
            ObjectId resBlockId = ObjectId.Null;

            Tools.StartTransaction(() =>
            {
                Transaction trans = Tools.GetTopTransaction();

                // Add a block reference to the model space
                BlockTableRecord ms = Tools.GetAcadBlockTableRecordModelSpace(OpenMode.ForWrite);

                BlockTableRecord btr = blockTableRecordId.GetObjectForRead <BlockTableRecord>();

                BlockReference br = new BlockReference(insertPoint, blockTableRecordId);
                br.SetDatabaseDefaults();
                br.TransformBy(toWcsTransform);

                ObjectContextManager ocm    = btr.Database.ObjectContextManager;
                ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");

                if (btr.Annotative == AnnotativeStates.True)
                {
                    br.AddContext(occ.CurrentContext);
                }

                resBlockId = ms.AppendEntity(br);
                trans.AddNewlyCreatedDBObject(br, true);

                // Add attributes from the block table record
                List <AttributeDefinition> attributes = GetAttributes(btr, trans);
                int i = 0;
                foreach (AttributeDefinition acAtt in attributes)
                {
                    if (!acAtt.Constant)
                    {
                        using (AttributeReference acAttRef = new AttributeReference())
                        {
                            acAttRef.SetAttributeFromBlock(acAtt, br.BlockTransform);

                            if (attrTextValues != null)
                            {
                                acAttRef.TextString = attrTextValues[i++];
                            }
                            else
                            {
                                acAttRef.TextString = acAtt.TextString;
                            }

                            br.AttributeCollection.AppendAttribute(acAttRef);
                            trans.AddNewlyCreatedDBObject(acAttRef, true);
                        }
                    }
                }
                br.RecordGraphicsModified(true);
            });
            return(resBlockId);
        }
Beispiel #12
0
        protected virtual void Place(BlockReference blkRef)
        {
            var pivotVector      = CurrentPart.PivotPoint - Point3d.Origin;
            var orientationAngle = PartOrientationAngle * Math.PI / 180.0;

            blkRef.Position = blkRef.Position.Add(pivotVector);
            blkRef.TransformBy(Matrix3d.Rotation(orientationAngle, _acad.UCS.Zaxis, CurrentPoint));
            blkRef.Position = blkRef.Position.Add(new Vector3d(CurrentPart.Height, 0, 0));
        }
Beispiel #13
0
        private void InitContent(BordeoL135Panel panel, Transaction tr)
        {
            Dictionary <LBlockType, AutoCADBlock>
            blocks2D                 = new Dictionary <LBlockType, AutoCADBlock>(),
                blocks3D             = new Dictionary <LBlockType, AutoCADBlock>();
            RivieraLBlock rBlock     = (panel.Block as RivieraLBlock);
            AutoCADBlock  block2d    = new AutoCADBlock(String.Format(rBlock.Block2DName, rBlock.BlockName), rBlock.GetBlockFilePath(), tr);
            AutoCADBlock  block3d    = new AutoCADBlock(String.Format(rBlock.Block3DName, rBlock.BlockName), rBlock.GetBlockFilePath(false), tr);
            AutoCADBlock  varBlock2d = new AutoCADBlock(String.Format(SUFFIX_BLOCK2D, rBlock.VariantBlockName), rBlock.GetBlockFilePath(rBlock.VariantBlockName), tr);
            AutoCADBlock  varBlock3d = new AutoCADBlock(String.Format(SUFFIX_BLOCK3D, rBlock.VariantBlockName), rBlock.GetBlockFilePath(rBlock.VariantBlockName, false), tr);

            (panel.Block as RivieraLBlock).LoadBlocks(Application.DocumentManager.MdiActiveDocument, tr, out blocks2D, out blocks3D);
            string blockName        = block2d.Blockname.Substring(0, block2d.Blockname.Length - 2),
                   variantBlockName = varBlock2d != null?varBlock2d.Blockname.Substring(0, varBlock2d.Blockname.Length - 2) : null;

            AutoCADBlock blockRecord = blocks2D[LBlockType.LEFT_SAME_SIZE];

            blockRecord.Open(tr, OpenMode.ForWrite);
            blockRecord.Clear(tr);
            String code           = blockName.Substring(0, 6);
            Double frente1        = 18d.GetPanel135DrawingSize() * Math.Sin(Math.PI / 4),
                   frente2        = 18d.GetPanel135DrawingSize() + 18d.GetPanel135DrawingSize() * Math.Cos(Math.PI / 4);
            BlockReference blkRef = block2d.CreateReference(new Point3d(), 0);

            //Se rota 270°

            blkRef.TransformBy(Matrix3d.Rotation(-3 * Math.PI / 4, Vector3d.ZAxis, new Point3d()));
            Vector3d offset = new Vector3d(frente2, frente1, 0);

            //Offset BR2020
            if (code == CODE_PANEL_90)
            {
                offset = new Vector3d(offset.X + 0.1002d, offset.Y + 0.1002d, 0);
            }
            //Offset BR2030
            else
            {
                offset = new Vector3d(offset.X + 0.0709d, offset.Y + 0.0293d, 0);
            }
            //Se traslada el punto final al punto inicial
            blkRef.TransformBy(Matrix3d.Displacement(new Vector3d(offset.X, offset.Y, 0)));
            blockRecord.Draw(tr, blkRef);
        }
Beispiel #14
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;
        }
Beispiel #15
0
        public BlockReference copyBlockReference(ref BlockReference bref, ref BlockTableRecord br)
        {
            BlockReference newbref = new BlockReference(Point3d.Origin, br.ObjectId);

            newbref.TransformBy(bref.BlockTransform);
            newbref.BlockUnit = bref.BlockUnit;
            newbref.Normal    = bref.Normal;
            newbref.Layer     = bref.Layer.Split('|').Last();

            return(newbref);
        }
        public void GBL()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("\n百福工具箱——修改图块比例大小");
            //创建选择集
            PromptSelectionOptions pso = new PromptSelectionOptions
            {
                MessageForAdding = "\n请选择需要修改的图块"
            };

            TypedValue[] values = new TypedValue[]
            {
                //new TypedValue((int)DxfCode.BlockName,"BFA3H")
                new TypedValue((int)DxfCode.Start, "Insert")
            };
            SelectionFilter       filter = new SelectionFilter(values);
            PromptSelectionResult pst;

            do
            {
                pst = ed.GetSelection(pso, filter);
                pso.MessageForAdding = "\n未选择任何有效图块,请选择需要修改的图块";
            }while (pst.Status == PromptStatus.Error || pst.Status == PromptStatus.Cancel);

            SelectionSet ss = pst.Value;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in ss.GetObjectIds())
                {
                    BlockReference      blockRef = (BlockReference)trans.GetObject(id, OpenMode.ForWrite);
                    Point3d             pt0      = blockRef.Position;
                    double              yScale   = blockRef.ScaleFactors.X;
                    PromptDoubleOptions pdo      = new PromptDoubleOptions("\n原图框比例为 1:<" + yScale.ToString() + ">,需修改为1")
                    {
                        AllowNegative = false,//不允许输入负数
                        AllowNone     = false
                    };
                    PromptDoubleResult pds = ed.GetDouble(pdo);
                    if (pds.Status == PromptStatus.OK)
                    {
                        double scale = pds.Value / yScale;
                        blockRef.TransformBy(Matrix3d.Scaling(scale, pt0));
                        //更新当前页面
                        Application.DocumentManager.MdiActiveDocument.Editor.Regen();
                    }
                }
                trans.Commit();
            }
        }
Beispiel #17
0
        /// <summary>
        /// Sets the instance content, depending on the if the application view
        /// is on 2D or 3D
        /// </summary>
        /// <param name="is2DBlock">if set to <c>true</c> [is a 2D block] otherwise a 3D block.</param>
        /// <param name="doc">The active document.</param>
        /// <param name="blkRef">The Block reference</param>
        /// <param name="tr">The active transaction.</param>
        public override bool SetContent(Boolean is2DBlock, out BlockReference blkRef, Document doc, Transaction tr)
        {
            Boolean blockIsLoaded = base.SetContent(is2DBlock, out blkRef, doc, tr);

            if (blockIsLoaded && !is2DBlock)
            {
                //Se rota el bloque para la vista 3D
                Point3d  insPoint = blkRef.Position;
                Vector3d v        = Vector3d.XAxis;
                blkRef.TransformBy(Matrix3d.Rotation(Math.PI / 2, v, blkRef.Position));
            }
            return(blockIsLoaded);
        }
Beispiel #18
0
        public void MoveBlock()
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            // LOcal do arquivo de dados: O diretório do .dwg onde está send
            // executado o programa.
            string curDwgPath = AcAp.GetSystemVariable("DWGPREFIX").ToString();

            // Cria um StreamReader para ler o arquivo 'moveblocks.txt', que contém
            // os dados para mover os blocos.
            var fileData = new StreamReader(curDwgPath + "\\moveBlocks.txt");

            // Armazenará uma linha que será lida do 'moveBlocks.txt'
            string[] sFileLine;

            string blockId;

            string[] coords;
            string   coordX;
            string   coordY;
            Point3d  oldPos;
            Point3d  newPos;
            Vector3d vector;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                while (!fileData.EndOfStream)
                {
                    sFileLine = fileData.ReadLine().Split(';');
                    blockId   = sFileLine[0];
                    coords    = sFileLine[1].Split(',');
                    coordX    = coords[0];
                    coordY    = coords[1];

                    DBObject     dbModelSpace = tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
                    ObjectId     extId        = dbModelSpace.ExtensionDictionary;
                    DBDictionary dbExt        = (DBDictionary)tr.GetObject(extId, OpenMode.ForRead);

                    BlockReference blkRef      = GetRefBlkFromIndex(db, dbExt, blockId);
                    BlockReference blkRefWrite = (BlockReference)tr.GetObject(blkRef.Id, OpenMode.ForWrite);

                    oldPos = blkRef.Position;
                    newPos = new Point3d(Convert.ToDouble(coordX), Convert.ToDouble(coordY), 0);
                    vector = oldPos.GetVectorTo(newPos);

                    blkRefWrite.TransformBy(Matrix3d.Displacement(vector));
                }
                tr.Commit();
            }
        }
        /// <summary>
        /// Creates the left reference.
        /// </summary>
        /// <param name="blockName">Name of the block.</param>
        /// <param name="block">The block.</param>
        /// <returns></returns>
        private BlockReference CreateLeftReference(string blockName, AutoCADBlock block)
        {
            String code = blockName.Substring(0, 6);
            double frente1 = int.Parse(blockName.Substring(6, 2)),
                   frente2 = int.Parse(blockName.Substring(8, 2));
            Double         f1, f2;
            Vector3d       offset = new Vector3d();
            BlockReference blkRef = block.CreateReference(new Point3d(), 0);

            if (code == CODE_PANEL_90)//Se rota 270°
            {
                blkRef.TransformBy(Matrix3d.Rotation(3 * Math.PI / 2, Vector3d.ZAxis, new Point3d()));
            }
            else //Se rota 225° para el panel de 135°
            {
                blkRef.TransformBy(Matrix3d.Rotation(-3 * Math.PI / 4, Vector3d.ZAxis, new Point3d()));
            }

            //Offset BR2020
            if (code == CODE_PANEL_90)
            {
                f1     = frente1.GetPanel90DrawingSize();
                f2     = frente2.GetPanel90DrawingSize();
                offset = new Vector3d(f2, f1, 0);
                offset = new Vector3d(offset.X + 0.1002d, offset.Y + 0.1002d, 0);
            }
            //Offset BR2030
            else
            {
                f1     = frente1.GetPanel135DrawingSize() * Math.Sin(Math.PI / 4);
                f2     = frente2.GetPanel135DrawingSize() + frente2.GetPanel135DrawingSize() * Math.Cos(Math.PI / 4);
                offset = new Vector3d(f2, f1, 0);
                offset = new Vector3d(offset.X + 0.07085210d, offset.Y + 0.02934790d, 0);
            }
            //Se desplaza en el punto final al inicial del bloque
            blkRef.TransformBy(Matrix3d.Displacement(new Vector3d(offset.X, offset.Y, 0)));
            return(blkRef);
        }
Beispiel #20
0
        public Handle InsertBlock(Transaction trans, string blockName, Point3d origin, double scale, double rotationDegrees, string layerName)
        {
            BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
            LayerTable lt = trans.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
            if (!bt.Has(blockName))
            {
                BlockDefinitionCreator bdc = new BlockDefinitionCreator();
                bdc.CreateBlock(blockName);
            }
            if (!lt.Has(layerName))
            {
                throw new ArgumentException("Layer doesn't exists.");
            }

            ObjectId btObjectId = bt[blockName];
            if (btObjectId != ObjectId.Null)
            {
                BlockReference blockRef = new BlockReference(origin, btObjectId);
                blockRef.Rotation = rotationDegrees * Math.PI / 180;
                blockRef.TransformBy(Matrix3d.Scaling(scale, origin));
                blockRef.Layer = layerName;

                BlockTableRecord currentSpaceId = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                currentSpaceId.AppendEntity(blockRef);
                trans.AddNewlyCreatedDBObject(blockRef, true);

                BlockTableRecord btr = trans.GetObject(btObjectId, OpenMode.ForRead) as BlockTableRecord;
                if (btr.HasAttributeDefinitions)
                {
                    foreach (ObjectId atId in btr)
                    {
                        Entity ent = trans.GetObject(atId, OpenMode.ForRead) as Entity;
                        if (ent is AttributeDefinition)
                        {
                            AttributeDefinition atd = ent as AttributeDefinition;
                            AttributeReference atr = new AttributeReference();
                            atr.SetAttributeFromBlock(atd, blockRef.BlockTransform);
                            blockRef.AttributeCollection.AppendAttribute(atr);
                            trans.AddNewlyCreatedDBObject(atr, true);
                        }
                    }
                }
                return blockRef.ObjectId.Handle;
            }
            else
            {
                return new Handle();
            }
        }
Beispiel #21
0
        public static void Annotate(Polyline3d acPoly3d)
        {
            //Get lable point
            Point3d labelPoint3d = acPoly3d.GetPointAtDist(acPoly3d.Length / 2);
            Point3d labelPoint   = new Point3d(labelPoint3d.X, labelPoint3d.Y, 0);

            Database acCurDb;

            acCurDb = Application.DocumentManager.MdiActiveDocument.Database;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Block table for read
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

                ObjectId blkRecId = ObjectId.Null;

                if (!acBlkTbl.Has("PipeLabel"))
                {
                    Main.LoadBlocks();
                }

                Matrix3d           curUCSMatrix = Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem;
                CoordinateSystem3d curUCS       = curUCSMatrix.CoordinateSystem3d;


                //calculate angle of line
                Point3d start = acPoly3d.GetPointAtDist(0);
                Point3d end   = acPoly3d.GetPointAtDist(acPoly3d.Length);

                double angle = Math.Atan((end.Y - start.Y) / (end.X - start.X));

                // Insert the block into the current space
                using (BlockReference acBlkRef = new BlockReference(labelPoint, acBlkTbl["PipeLabel"]))
                {
                    acBlkRef.TransformBy(Matrix3d.Rotation(angle, curUCS.Zaxis, labelPoint));

                    BlockTableRecord acCurSpaceBlkTblRec;
                    acCurSpaceBlkTblRec = acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                    acCurSpaceBlkTblRec.AppendEntity(acBlkRef);
                    acTrans.AddNewlyCreatedDBObject(acBlkRef, true);
                }

                acTrans.Commit();
            }
        }
Beispiel #22
0
        public static void Normalize([NotNull] this BlockReference blRef)
        {
            // Корректировка масштабирования и зеркальности
            var scale1 = new Scale3d(1);

            if (blRef.ScaleFactors != scale1)
            {
                blRef.ScaleFactors = scale1;
            }

            if (Math.Abs(blRef.Rotation) > 0.0001)
            {
                var matRotate = Matrix3d.Rotation(-blRef.Rotation, Vector3d.ZAxis, blRef.Position);
                blRef.TransformBy(matRotate);
            }
        }
Beispiel #23
0
        private void addCheekViewBlock(bool doTrans, Matrix3d trans, double xPosView, bool isLeft)
        {
            // Добавление блока вида.
            // Если блока нет, то выход.
            if (panelBase.Service.Env.IdBtrView.IsNull)
            {
                return;
            }

            Point3d ptBlView = new Point3d(xPosView, 860, 0);

            if (doTrans)
            {
                ptBlView = ptBlView.TransformBy(trans);
            }
            BlockReference blRefView = CreateBlRefInBtrDim(ptBlView, panelBase.Service.Env.IdBtrView, Settings.Default.SheetScale);

            if (blRefView == null)
            {
                return;
            }

            // атрибут Вида
            if (!panelBase.Service.Env.IdAttrDefView.IsNull)
            {
                using (var attrDefView = panelBase.Service.Env.IdAttrDefView.GetObject(OpenMode.ForRead, false, true) as AttributeDefinition)
                {
                    var attrRefView = new AttributeReference();
                    attrRefView.SetAttributeFromBlock(attrDefView, blRefView.BlockTransform);
                    attrRefView.TextString = "А";

                    blRefView.AttributeCollection.AppendAttribute(attrRefView);
                    t.AddNewlyCreatedDBObject(attrRefView, true);

                    if ((!isLeft || doTrans) && !(!isLeft && doTrans))
                    {
                        attrRefView.TransformBy(Matrix3d.Mirroring(
                                                    new Line3d(attrRefView.AlignmentPoint, new Point3d(attrRefView.AlignmentPoint.X, 0, 0))));
                    }
                }
            }

            if ((!isLeft || doTrans) && !(!isLeft && doTrans))
            {
                blRefView.TransformBy(Matrix3d.Mirroring(new Line3d(ptBlView, new Point3d(ptBlView.X, 0, 0))));
            }
        }
Beispiel #24
0
 private void FixPartOrientation(Part part, Point3d loc, double orientationAngle, BlockReference blkRef)
 {
     blkRef.TransformBy(Matrix3d.Rotation(orientationAngle, _acad.UCS.Zaxis, loc));
     if (part.UsageType != UsageType.Head)
     {
         var vectorPivot = (part.PivotPoint - Point3d.Origin).RotateBy(-orientationAngle, Vector3d.ZAxis);
         blkRef.Position = blkRef.Position.Add(vectorPivot);
     }
     else
     {
         if (orientationAngle == 0)
         {
             var middleVector = new Vector3d(part.Width / 2.0, part.Height / 2.0, 0);
             var vectorPivot  = part.PivotPoint - Point3d.Origin;
             blkRef.Position = blkRef.Position.Subtract(middleVector.Subtract(vectorPivot));
         }
     }
 }
Beispiel #25
0
    public static ObjectId InsertBlockRefByDWGFile(Document doc, Transaction transaction, string dwgPath, Point3d point, Matrix3d?mtx, string blockName = "")
    {
        ObjectId objectId2 = ObjectId.Null;

        blockName = (string.IsNullOrEmpty(blockName) ? Guid.NewGuid().ToString("N") : Regex.Replace(blockName, "[\\u005c\\u003a]", "X"));
        BlockTableRecord block = GetBlock(doc, transaction, blockName, dwgPath);
        BlockTable       bt    = (BlockTable)transaction.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
        BlockTableRecord btr   = (BlockTableRecord)transaction.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

        using (BlockReference bref = new BlockReference(point, block.ObjectId))
        {
            if (mtx.HasValue)
            {
                bref.TransformBy(mtx.Value);
            }
            objectId2 = btr.AppendEntity(bref);
            transaction.AddNewlyCreatedDBObject(bref, true);
            return(objectId2);
        }
    }
Beispiel #26
0
            public void Mirror(BlockReference br)
            {
                using (Transaction trans = Tools.StartTransaction())
                {
                    Line3d line = new Line3d(this.Matrix.CoordinateSystem3d.Origin, this.Matrix.CoordinateSystem3d.Yaxis);

                    br = (BlockReference)trans.GetObject(br.Id, OpenMode.ForRead);
                    Matrix3d mat = br.BlockTransform;
                    if (Mode == DirectionMode.Horizontal)
                    {
                        mat = Matrix3d.Mirroring(new Plane(br.Position, br.BlockTransform.CoordinateSystem3d.Yaxis, br.Normal));
                    }
                    else
                    {
                        mat = Matrix3d.Mirroring(new Plane(br.Position, br.BlockTransform.CoordinateSystem3d.Xaxis, br.Normal));
                    }
                    br.UpgradeOpen();
                    br.TransformBy(mat);
                    trans.Commit();
                }
            }
Beispiel #27
0
        /// <summary>this inserts a block into another block, the block designated by oid is the receiver and receives a new copy of the block designated by blockname, this block is rotated by the specified number of degrees around it's x-axis</summary>
        public static Handle InsertRotated(ObjectId oid, string blockPath, string blockName, int rotation = 90)
        {
            Handle hd = new Handle();

            try {
                if (oid.IsErased == false & oid.IsEffectivelyErased == false)
                {
                    using (World.Docu.LockDocument()) {
                        using (Database db = World.Docu.Database) {
                            using (Transaction tr = db.TransactionManager.StartTransaction()) {
                                using (BlockReference br = (BlockReference)tr.GetObject(oid, OpenMode.ForWrite)) {
                                    if (AcadIO.Insert.DB.AddBlock(blockPath + "\\" + blockName) == false)
                                    {
                                        return(hd);
                                    }

                                    using (BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead)) {
                                        using (BlockReference bi = new BlockReference(Autodesk.AutoCAD.Geometry.Point3d.Origin, bt[blockPath])) {
                                            bi.TransformBy(Autodesk.AutoCAD.Geometry.Matrix3d.Rotation(rotation * Math.PI / 180, bi.BlockTransform.CoordinateSystem3d.Xaxis, new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0)));
                                            using (BlockTableRecord blockSpace = (BlockTableRecord)tr.GetObject(br.BlockTableRecord, OpenMode.ForWrite)) {
                                                blockSpace.AppendEntity(bi);
                                                tr.AddNewlyCreatedDBObject(bi, true);
                                                bi.LayerId = br.LayerId;
                                                hd         = bi.Handle;
                                            }
                                        }
                                    }
                                }
                                tr.Commit();
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex) {
                Err.Log(ex);
            }
            return(hd);
        }
Beispiel #28
0
        public void TestAnonyBlock()
        {
            Polyline pline = new Polyline(3);

            pline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
            pline.AddVertexAt(1, new Point2d(pline.GetPoint2dAt(0).X + 3, pline.GetPoint2dAt(0).Y), 0, 0.4, 0);
            pline.AddVertexAt(2, new Point2d(pline.GetPoint2dAt(1).X + 1.5, pline.GetPoint2dAt(1).Y), 0, 0, 0);
            pline.LineWeight = LineWeight.LineWeight020;

            AttributeDefinition ad = _createAttribute(pline.StartPoint, pline);

            Matrix3d ucs = CoordinateSystem.CoordinateTools.GetCurrentUcs();

            var btrId = BlockTools.CreateBlockTableRecordEx(Point3d.Origin, "test11111", new[] { (Entity)pline, (Entity)ad }.ToList(), AnnotativeStates.True);
            var brId  = BlockTools.AddBlockRefToModelSpace(btrId, new[] { "3" }.ToList(), new Point3d(10, 10, 10), ucs);

            using (Transaction trans = Tools.StartTransaction())
            {
                BlockReference br = (BlockReference)brId.GetObject(OpenMode.ForRead, false, true);
                br.UpgradeOpen();
                br.TransformBy(Matrix3d.Rotation(Math.PI / 2d, ucs.CoordinateSystem3d.Zaxis, br.Position));
                //br.Erase(true);
                trans.Commit();
            }

            AttributeReference ar;

            using (Transaction trans = Tools.StartTransaction())
            {
                BlockReference br = (BlockReference)brId.GetObject(OpenMode.ForRead, true, true);
                ar = br.GetAttributeByTag(ad.Tag, trans);
                ar = (AttributeReference)ar.Id.GetObject(OpenMode.ForRead, true, true);
                var anBtrId = BlockTools.GetAnonymCopy(brId, trans, false);
                var anBrId  = BlockTools.AddBlockRefToModelSpace(anBtrId, new[] { ar.TextString }.ToList(), new Point3d(0, 0, 0), ucs);

                trans.Commit();
            }
        }
Beispiel #29
0
        private void addHorizontalSectionMark()
        {
            double ySec   = panelBase.Height * 70 / 100; // сечение на высоте 70% от общей высоты панели
            double xLeft  = xDimLineLeftMin - 160;
            double xRight = xDimLineRightMax + 140;

            Point3d ptLeftCross  = new Point3d(xLeft, ySec, 0);
            Point3d ptRightCross = new Point3d(xRight, ySec, 0);

            BlockReference blRefCrossLeft = CreateBlRefInBtrDim(ptLeftCross, panelBase.Service.Env.IdBtrCross, Settings.Default.SheetScale);

            if (blRefCrossLeft == null)
            {
                return;
            }
            Matrix3d matrixMirrLeftCross = Matrix3d.Mirroring(new Line3d(ptLeftCross, ptRightCross));

            blRefCrossLeft.Rotation = 90d.ToRadians();
            blRefCrossLeft.TransformBy(matrixMirrLeftCross);
            var attrRefTop = addAttrToBlockCross(blRefCrossLeft, "1");

            attrRefTop.TransformBy(Matrix3d.Mirroring(new Line3d(attrRefTop.AlignmentPoint,
                                                                 new Point3d(attrRefTop.AlignmentPoint.X + 1, attrRefTop.AlignmentPoint.Y, attrRefTop.AlignmentPoint.Z))));
            attrRefTop.Rotation = 0;

            BlockReference blRefCrossRight = CreateBlRefInBtrDim(ptRightCross, panelBase.Service.Env.IdBtrCross, Settings.Default.SheetScale);

            if (blRefCrossRight == null)
            {
                return;
            }
            blRefCrossRight.Rotation = 270d.ToRadians();
            var attrRefBot = addAttrToBlockCross(blRefCrossRight, "1");

            attrRefBot.Rotation = 0;
        }
Beispiel #30
0
        /// <summary>
        /// Insert a block to the point
        /// </summary>
        /// <param name="insPt"></param>
        /// <param name="blockName"></param>
        public void InsertBlockToPoint(Point3d insPt, string blockName, string modifyProp1 = "", double modifyPropValue1 = 0,
                                       string modifyProp2 = "", double modifyPropValue2 = 0, string modifyProp3 = "", double modifyPropValue3 = 0)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db  = doc.Database;
            var ed  = doc.Editor;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                // check if the block table already has the 'blockName'" block
                var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                if (!bt.Has(blockName))
                {
                    try
                    {
                        // search for a dwg file named 'blockName' in AutoCAD search paths
                        var filename = HostApplicationServices.Current.FindFile(blockName + ".dwg", db, FindFileHint.Default);
                        // add the dwg model space as 'blockName' block definition in the current database block table
                        using (var sourceDb = new Database(false, true))
                        {
                            sourceDb.ReadDwgFile(filename, FileOpenMode.OpenForReadAndAllShare, true, "");
                            db.Insert(blockName, sourceDb, true);
                        }
                    }
                    catch
                    {
                        ed.WriteMessage($"\nBlock '{blockName}' not found.");
                        return;
                    }
                }

                // create a new block reference
                using (var br = new BlockReference(insPt, bt[blockName]))
                {
                    var space = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    space.AppendEntity(br);
                    tr.AddNewlyCreatedDBObject(br, true);

                    if (br.IsDynamicBlock)
                    {
                        var dynProps = br.DynamicBlockReferencePropertyCollection;
                        foreach (DynamicBlockReferenceProperty dynProp in dynProps)
                        {
                            if (!dynProp.ReadOnly && Regex.IsMatch(dynProp.PropertyName, modifyProp1, RegexOptions.IgnoreCase))
                            {
                                if (dynProp.PropertyName == modifyProp1)
                                {
                                    if (modifyPropValue1 != 0)
                                    {
                                        dynProp.Value = modifyPropValue1;
                                    }
                                }
                            }
                            else if (!dynProp.ReadOnly && Regex.IsMatch(dynProp.PropertyName, modifyProp2, RegexOptions.IgnoreCase))
                            {
                                if (dynProp.PropertyName == modifyProp2)
                                {
                                    if (modifyPropValue2 != 0)
                                    {
                                        dynProp.Value = modifyPropValue2;
                                    }
                                }
                            }
                            else if (!dynProp.ReadOnly && Regex.IsMatch(dynProp.PropertyName, modifyProp3, RegexOptions.IgnoreCase))
                            {
                                if (dynProp.PropertyName == modifyProp3)
                                {
                                    if (modifyPropValue3 != 0)
                                    {
                                        dynProp.Value = modifyPropValue3;
                                    }
                                }
                            }
                        }
                    }

                    if (direction == direction.top)
                    {
                        br.TransformBy(Matrix3d.Rotation(1.5708, br.Normal, br.Position));
                    }
                    else if (direction == direction.bottom)
                    {
                        //4.71239
                        br.TransformBy(Matrix3d.Rotation(4.71239, br.Normal, br.Position));
                    }
                    else if (direction == direction.left)
                    {
                        //3.14159
                        br.TransformBy(Matrix3d.Rotation(3.14159, br.Normal, br.Position));
                    }
                    else
                    {
                        br.Rotation = 0;
                    }
                }
                tr.Commit();
            }
        }
Beispiel #31
0
        /// <summary>
        /// /// * Insert Drawing As Block - DWG or DXF *
        /// the source drawig should be drawn as number of
        /// separate entites with or without attributes 
        /// 
        /// </summary>
        /// <param name="destinationDocument"></param>
        /// <param name="sourceDrawing"></param>
        /// <param name="insertionPoint"></param>
        /// <param name="transforMatrix"> </param>
        /// <exception cref="NotImplementedException">Not implemented for DXFs</exception>
        /// <returns>ObjectID of the Block Def that was imported.</returns>
        private void ReplaceBlockRefWithDWG(Document destinationDocument, string sourceDrawing, Point3d insertionPoint,
            Matrix3d transforMatrix)
        {
            Point3d oldPoint = insertionPoint.TransformBy(transforMatrix.Inverse());
            insertionPoint = new Point3d(0, 0, 0);

            Database destinationDb = destinationDocument.Database;
            Editor ed = destinationDocument.Editor;

            string blockname = sourceDrawing.Remove(0, sourceDrawing.LastIndexOf("\\", StringComparison.Ordinal) + 1);
            blockname = blockname.Substring(0, blockname.Length - 4); // remove the extension

            using (destinationDocument.LockDocument())
            {
                using (var inMemoryDb = new Database(false, true))
                {
                    if (sourceDrawing.LastIndexOf(".dwg", StringComparison.Ordinal) > 0)
                    {
                        inMemoryDb.ReadDwgFile(sourceDrawing, FileShare.ReadWrite, true, "");
                    }
                    else if (sourceDrawing.LastIndexOf(".dxf", StringComparison.Ordinal) > 0)
                    {
                        throw new NotImplementedException("DXFs not suppported");
                        //inMemoryDb.DxfIn(string filename, string logFilename);
                    }

                    using (var transaction = destinationDocument.TransactionManager.StartTransaction())
                    {
                        var destinationDatabaseBlockTable =
                            (BlockTable) transaction.GetObject(destinationDb.BlockTableId, OpenMode.ForRead);
                        ObjectId sourceBlockObjectId;
                        if (destinationDatabaseBlockTable.Has(blockname))
                        {

                            ed.WriteMessage("Block " + blockname +
                                            " already exists.\n Attempting to create block reference...");

                            var destinationDatabaseCurrentSpace =
                                (BlockTableRecord) destinationDb.CurrentSpaceId.GetObject(OpenMode.ForWrite);

                            var destinationDatabaseBlockDefinition =
                                (BlockTableRecord)
                                    transaction.GetObject(destinationDatabaseBlockTable[blockname], OpenMode.ForRead);
                            sourceBlockObjectId = destinationDatabaseBlockDefinition.ObjectId;

                            // Create a block reference to the existing block definition
                            using (var blockReference = new BlockReference(insertionPoint, sourceBlockObjectId))
                            {
                                //Matrix3d Mat = Matrix3d.Identity;   

                                Vector3d mov = new Vector3d(oldPoint.X, oldPoint.Y, oldPoint.Z);
                                mov = mov.TransformBy(transforMatrix);
                                blockReference.TransformBy(transforMatrix);
                                blockReference.TransformBy(Matrix3d.Displacement(mov));

                                blockReference.ScaleFactors = new Scale3d(1, 1, 1);
                                destinationDatabaseCurrentSpace.AppendEntity(blockReference);
                                transaction.AddNewlyCreatedDBObject(blockReference, true);
                                ed.Regen();
                                transaction.Commit();
                                // At this point the Bref has become a DBObject and can be disposed
                            }
                            return;
                        }

                        // There is not such block definition, so we are inserting/creating new one
                        sourceBlockObjectId = destinationDb.Insert(blockname, inMemoryDb, true);

                        #region Create Block Ref from the already imported Block Def

                        // We continue here the creation of the new block reference of the already imported block definition
                        var sourceDatabaseCurrentSpace =
                            (BlockTableRecord) destinationDb.CurrentSpaceId.GetObject(OpenMode.ForWrite);

                        using (var blockReference = new BlockReference(insertionPoint, sourceBlockObjectId))
                        {
                            blockReference.ScaleFactors = new Scale3d(1, 1, 1);
                            sourceDatabaseCurrentSpace.AppendEntity(blockReference);
                            transaction.AddNewlyCreatedDBObject(blockReference, true);

                            var blockTableRecord =
                                (BlockTableRecord) blockReference.BlockTableRecord.GetObject(OpenMode.ForRead);
                            var atcoll = blockReference.AttributeCollection;
                            foreach (ObjectId subid in blockTableRecord)
                            {
                                var entity = (Entity) subid.GetObject(OpenMode.ForRead);
                                var attributeDefinition = entity as AttributeDefinition;

                                if (attributeDefinition == null)
                                {
                                    continue;
                                }
                                var attributeReference = new AttributeReference();
                                attributeReference.SetPropertiesFrom(attributeDefinition);
                                attributeReference.Visible = attributeDefinition.Visible;
                                attributeReference.SetAttributeFromBlock(attributeDefinition,
                                    blockReference.BlockTransform);
                                attributeReference.HorizontalMode = attributeDefinition.HorizontalMode;
                                attributeReference.VerticalMode = attributeDefinition.VerticalMode;
                                attributeReference.Rotation = attributeDefinition.Rotation;
                                attributeReference.Position = attributeDefinition.Position +
                                                              insertionPoint.GetAsVector();
                                attributeReference.Tag = attributeDefinition.Tag;
                                attributeReference.FieldLength = attributeDefinition.FieldLength;
                                attributeReference.TextString = attributeDefinition.TextString;
                                attributeReference.AdjustAlignment(destinationDb);

                                atcoll.AppendAttribute(attributeReference);
                                transaction.AddNewlyCreatedDBObject(attributeReference, true);
                            }

                            var mov = new Vector3d(oldPoint.X, oldPoint.Y, oldPoint.Z);
                            mov = mov.TransformBy(transforMatrix);
                            blockReference.TransformBy(transforMatrix);
                            blockReference.TransformBy(Matrix3d.Displacement(mov));

                            transaction.Commit();
                        }

                        #endregion

                        ed.Regen();
                    }
                }
            }
        }
        public void TextWrite(double x0, double y0, double z0, double k)
        {
            Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;// Get the current document and database
            DocumentLock myLock = acDoc.LockDocument();
            Database AcDb = acDoc.Database;
            Editor ed = acDoc.Editor;
            double step = 0.5 * k;  //шаг уменьшения размера текста
            double FS1 = k * (5 - 2.3); //Размер стандартного шрифта
            using (Transaction acTrans = AcDb.TransactionManager.StartTransaction())// Start a transaction
            {
                BlockTable acBlkTbl;// Open the Block table record for read
                acBlkTbl = acTrans.GetObject(AcDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord acBlkTblRec;// Open the Block table record Model space for write
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                MText[][] MTX = new MText[11][];
                #region MTEXT
                MTX[0] = new MText[7];
                MTX[0][0] = new MyText(new Point3d(x0 + 1 * k, y0 - k, z0), TBx0_0.Text, FS1, AcDb);
                MTX[0][1] = new MyText(new Point3d(x0 + (1 + 10) * k, y0 - k, z0), TBx0_1.Text, FS1, AcDb);
                MTX[0][2] = new MyText(new Point3d(x0 + (1 + 20) * k, y0 - k, z0), TBx0_2.Text, FS1, AcDb);
                MTX[0][3] = new MyText(new Point3d(x0 + (1 + 30) * k, y0 - k, z0), TBx0_3.Text, FS1, AcDb);
                MTX[0][4] = new MyText(new Point3d(x0 + (1 + 40) * k, y0 - k, z0), CBx0_4.Text, FS1, AcDb);
                MTX[0][5] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - k, z0), TBx0_5.Text, FS1, AcDb);
                MTX[0][6] = new MyText(new Point3d(x0 + 125 * k, y0 - 5 * k, z0), TBx0_6.Text, k * 5, AcDb, AttachmentPoint.MiddleCenter);
                F.MtextSize(MTX[0][6], 115, 10, k, step, 3);

                MTX[1] = new MText[6];
                MTX[1][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 5) * k, z0), TBx1_0.Text, FS1, AcDb);
                MTX[1][1] = new MyText(new Point3d(x0 + (1 + 10) * k, y0 - (1 + 5) * k, z0), TBx1_1.Text, FS1, AcDb);
                MTX[1][2] = new MyText(new Point3d(x0 + (1 + 20) * k, y0 - (1 + 5) * k, z0), TBx1_2.Text, FS1, AcDb);
                MTX[1][3] = new MyText(new Point3d(x0 + (1 + 30) * k, y0 - (1 + 5) * k, z0), TBx1_3.Text, FS1, AcDb);
                MTX[1][4] = new MyText(new Point3d(x0 + (1 + 40) * k, y0 - (1 + 5) * k, z0), CBx1_4.Text, FS1, AcDb);
                MTX[1][5] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 5) * k, z0), TBx1_5.Text, FS1, AcDb);

                MTX[2] = new MText[7];
                MTX[2][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 10) * k, z0), TBx2_0.Text, FS1, AcDb);
                MTX[2][1] = new MyText(new Point3d(x0 + (1 + 10) * k, y0 - (1 + 10) * k, z0), TBx2_1.Text, FS1, AcDb);
                MTX[2][2] = new MyText(new Point3d(x0 + (1 + 20) * k, y0 - (1 + 10) * k, z0), TBx2_2.Text, FS1, AcDb);
                MTX[2][3] = new MyText(new Point3d(x0 + (1 + 30) * k, y0 - (1 + 10) * k, z0), TBx2_3.Text, FS1, AcDb);
                MTX[2][4] = new MyText(new Point3d(x0 + (1 + 40) * k, y0 - (1 + 10) * k, z0), СBx2_4.Text, FS1, AcDb);
                MTX[2][5] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 10) * k, z0), TBx2_5.Text, FS1, AcDb);
                MTX[2][6] = new MyText(new Point3d(x0 + 125 * k, y0 - 17.5 * k, z0), TBx2_6.Text, k * 5, AcDb, AttachmentPoint.MiddleCenter);
                F.MtextSize(MTX[2][6], 115, 15, k, step, 4);

                MTX[3] = new MText[6];
                MTX[3][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 15) * k, z0), TBx3_0.Text, FS1, AcDb);
                MTX[3][1] = new MyText(new Point3d(x0 + (1 + 10) * k, y0 - (1 + 15) * k, z0), TBx3_1.Text, FS1, AcDb);
                MTX[3][2] = new MyText(new Point3d(x0 + (1 + 20) * k, y0 - (1 + 15) * k, z0), TBx3_2.Text, FS1, AcDb);
                MTX[3][3] = new MyText(new Point3d(x0 + (1 + 30) * k, y0 - (1 + 15) * k, z0), TBx3_3.Text, FS1, AcDb);
                MTX[3][4] = new MyText(new Point3d(x0 + (1 + 40) * k, y0 - (1 + 15) * k, z0), CBx3_4.Text, FS1, AcDb);
                MTX[3][5] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 15) * k, z0), TBx3_5.Text, FS1, AcDb);

                MTX[4] = new MText[6];
                MTX[4][0] = new MyText(new Point3d(x0 + k, y0 - 21 * k, z0), "Изм", FS1, AcDb);
                MTX[4][1] = new MyText(new Point3d(x0 + (10 + 1) * k, y0 - 21 * k, z0), "Кол.уч.", FS1, AcDb);
                MTX[4][2] = new MyText(new Point3d(x0 + (20 + 1) * k, y0 - 21 * k, z0), "Лист", FS1, AcDb);
                MTX[4][3] = new MyText(new Point3d(x0 + (30 + 1) * k, y0 - 21 * k, z0), "№ док.", FS1, AcDb);
                MTX[4][4] = new MyText(new Point3d(x0 + (44 + 1) * k, y0 - 21 * k, z0), "Подп.", FS1, AcDb);
                MTX[4][5] = new MyText(new Point3d(x0 + (55 + 1) * k, y0 - 21 * k, z0), "Дата", FS1, AcDb);

                MTX[5] = new MText[7];
                MTX[5][0] = new MyText(new Point3d(x0 + 1 * k, y0 - 26 * k, z0), CBx5_0.Text, FS1, AcDb);
                MTX[5][1] = new MyText(new Point3d(x0 + (0.5 + 20) * k, y0 - 27.5 * k, z0), CBx5_1.Text, FS1, AcDb, AttachmentPoint.MiddleLeft);
                F.MtextSize(MTX[5][1], 19.4, k, 0.1);
                MTX[5][2] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 25) * k, z0), TBx5_2.Text, FS1, AcDb);
                MTX[5][3] = new MyText(new Point3d(x0 + 100 * k, y0 - 32.5 * k, z0), TBx5_3.Text, k * 4.5, AcDb, AttachmentPoint.MiddleCenter);
                F.MtextSize(MTX[5][3], 65, 15, k, step, 4);
                MTX[5][4] = new MyText(new Point3d(x0 + (135 + 1) * k, y0 - 26 * k, z0), "Стадия", FS1, AcDb);
                MTX[5][5] = new MyText(new Point3d(x0 + (150 + 1) * k, y0 - 26 * k, z0), "Лист", FS1, AcDb);
                MTX[5][6] = new MyText(new Point3d(x0 + (165 + 1) * k, y0 - 26 * k, z0), "Листов", FS1, AcDb);

                MTX[6] = new MText[6];
                MTX[6][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 30) * k, z0), CBx6_0.Text, FS1, AcDb);
                MTX[6][1] = new MyText(new Point3d(x0 + ( 0.5 + 20 ) * k, y0 - 32.5 * k, z0), CBx6_1.Text, FS1, AcDb, AttachmentPoint.MiddleLeft);
                F.MtextSize(MTX[6][1], 19.4, k, 0.1);
                MTX[6][2] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 30) * k, z0), TBx6_2.Text, FS1, AcDb);
                MTX[6][3] = new MyText(new Point3d(x0 + 142.5 * k, y0 - 35 * k, z0), CBx6_3.Text, k * 4, AcDb, AttachmentPoint.MiddleCenter);
                MTX[6][4] = new MyText(new Point3d(x0 + 157.5 * k, y0 - 35 * k, z0), TBx6_4.Text, k * 4, AcDb, AttachmentPoint.MiddleCenter);
                MTX[6][5] = new MyText(new Point3d(x0 + (1 + 175) * k, y0 - 35 * k, z0), TBx6_5.Text, k * 4, AcDb, AttachmentPoint.MiddleCenter);
                MTX[7] = new MText[3];
                MTX[7][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 35) * k, z0), CBx7_0.Text, FS1, AcDb);
                MTX[7][1] = new MyText(new Point3d(x0 + (0.5 + 20) * k, y0 - 37.5 * k, z0), CBx7_1.Text, FS1, AcDb, AttachmentPoint.MiddleLeft);
                F.MtextSize(MTX[7][1], 19.4, k, 0.1);
                MTX[7][2] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 35) * k, z0), TBx7_2.Text, FS1, AcDb);
                MTX[8] = new MText[5];
                MTX[8][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 40) * k, z0), CBx8_0.Text, FS1, AcDb);
                MTX[8][1] = new MyText(new Point3d(x0 + (0.5 + 20) * k, y0 - 42.5 * k, z0), CBx8_1.Text, k * 3, AcDb, AttachmentPoint.MiddleLeft);
                F.MtextSize(MTX[8][1], 19.4, k, 0.1);
                MTX[8][2] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 40) * k, z0), TBx8_2.Text, FS1, AcDb);
                MTX[8][3] = new MyText(new Point3d(x0 + 100 * k, y0 - 47.5 * k, z0), TBx8_3.Text, k * 4.5, AcDb, AttachmentPoint.MiddleCenter);
                F.MtextSize(MTX[8][3], 65, 15, k, step, 4);
                MTX[8][4] = new MyText(new Point3d(x0 + 185 * k, y0 - 47.5 * k, z0), TBx8_4.Text, k * 2.3, AcDb, AttachmentPoint.MiddleRight);
                MTX[9] = new MText[3];
                MTX[9][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 45) * k, z0), CBx9_0.Text, FS1, AcDb);
                MTX[9][1] = new MyText(new Point3d(x0 + (0.5 + 20) * k, y0 - 47.5 * k, z0), CBx9_1.Text, k * 3, AcDb, AttachmentPoint.MiddleLeft);
                F.MtextSize(MTX[9][1], 19.4, k, 0.1);
                MTX[9][2] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 45) * k, z0), TBx9_2.Text, FS1, AcDb);
                MTX[10] = new MText[3];
                MTX[10][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 50) * k, z0), CBx10_0.Text, FS1, AcDb);
                MTX[10][1] = new MyText(new Point3d(x0 + (0.5 + 20) * k, y0 - 52.5 * k, z0), CBx10_1.Text, k * 3, AcDb, AttachmentPoint.MiddleLeft);
                F.MtextSize(MTX[10][1], 19.4, k, 0.1);
                MTX[10][2] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 50) * k, z0), TBx10_2.Text, FS1, AcDb);

                //номер листа
                //if (isfirsttime && textb1_Copy47.Text != "-1")
                //{
                //    try
                //    {
                //        nomer_lista = int.Parse(textb1_Copy47.Text); isfirsttime = false;
                //    }
                //    catch (System.Exception ex)
                //    {
                //        nomer_lista = -1;
                //        Debug.Print("Обновление нумерации. " + ex.Message);
                //    }
                //}
                //else nomer_lista++;
                #endregion
                //Вставка подписей
                try
                {
                    if (CBx5_1.Text!="")
                        GetSign((int)CBx5_1.SelectedValue, new Point3d(x0 + (0.2 + 40) * k, y0 - (0 + 30) * k, z0));
                    if (CBx6_1.Text != "")
                        GetSign((int)CBx6_1.SelectedValue, new Point3d(x0 + (0.2 + 40) * k, y0 - (0 + 35) * k, z0));
                    if (CBx7_1.Text != "")
                        GetSign((int)CBx7_1.SelectedValue, new Point3d(x0 + (0.2 + 40) * k, y0 - (0 + 40) * k, z0));
                    if (CBx8_1.Text != "")
                        GetSign((int)CBx8_1.SelectedValue, new Point3d(x0 + (0.2 + 40) * k, y0 - (0 + 45) * k, z0));
                    if (CBx9_1.Text != "")
                        GetSign((int)CBx9_1.SelectedValue, new Point3d(x0 + (0.2 + 40) * k, y0 - (0 + 50) * k, z0));
                    if (CBx10_1.Text != "")
                        GetSign((int)CBx10_1.SelectedValue, new Point3d(x0 + (0.2 + 40) * k, y0 - (0 + 55) * k, z0));
                }
                catch (System.Exception SystEx)
                {
                    MessageBox.Show(SystEx.Message);
                }
                //Вставка логотипа
                string blockQualifiedFileName = logoStr;
                string blockName = "ETUlogo";
                Database tmpDb = new Database(false, true);
                tmpDb.ReadDwgFile(blockQualifiedFileName, System.IO.FileShare.Read, true, "");
                double scale = 1.0;
                Matrix3d Transform = Matrix3d.Identity;
                Transform = Transform * Matrix3d.Scaling(scale, Point3d.Origin);
                // add the block to the ActiveDrawing blockTable
                AcDb.Insert(blockName, tmpDb, true);
                Point3d insPt = new Point3d(x0 + 135 * k, y0 - 47.5 * k - 2.5 * k, z0);
                BlockTableRecord btr = (BlockTableRecord)acTrans.GetObject(AcDb.CurrentSpaceId, OpenMode.ForWrite);
                BlockReference br = new BlockReference(Point3d.Origin, acBlkTbl[blockName]);
                br.TransformBy(Matrix3d.Displacement(insPt - Point3d.Origin).PreMultiplyBy(ed.CurrentUserCoordinateSystem));
                btr.AppendEntity(br);
                acTrans.AddNewlyCreatedDBObject(br, true);

                //DBObjectCollection objColl = new DBObjectCollection();
                for (int i = 0; i < MTX.Length; i++)
                    for (int j = 0; j < MTX[i].Length; j++ )
                    {
                        acBlkTblRec.AppendEntity(MTX[i][j]);
                        if (i == 6 && j == 4) listobind = MTX[i][j].Id;

                        acTrans.AddNewlyCreatedDBObject(MTX[i][j], true);
                    }

                //foreach (MText[] ma in MTX)
                //    foreach (MText m in ma)
                //    {
                //        acBlkTblRec.AppendEntity(m);
                //        acTrans.AddNewlyCreatedDBObject(m, true);
                //    }
                //foreach (Entity en in objColl)
                //{
                //    acBlkTblRec.AppendEntity(en);
                //    acTrans.AddNewlyCreatedDBObject(en, true);
                //}
                acTrans.Commit();
            }
        }
        private void GetSign(int id, Point3d pnt)
        {
            Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;// Get the current document and database
            DocumentLock myLock = acDoc.LockDocument();
            Database acCurDb = acDoc.Database;
            Editor ed = acDoc.Editor;
            Transaction acTrans = acCurDb.TransactionManager.StartTransaction();
            BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
            BlockTableRecord acBlkTblRec;// Open the Block table record Model space for write
            acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            MySqlConnection conn = new MySqlConnection(DB.DBConnString);
            System.Data.DataTable data_bin = new System.Data.DataTable();
            MySqlDataAdapter dtAdptr = new MySqlDataAdapter("SELECT SignData,SName FROM userstable WHERE USER_ID = '" + id + "'", conn);
            MySqlCommandBuilder cmdBldr = new MySqlCommandBuilder(dtAdptr);
            dtAdptr.Fill(data_bin);
            //запись подписи во временную папку
            string savep = Environment.CurrentDirectory;
            string str = savep + "\\" + data_bin.Rows[0]["SName"].ToString() + ".dwg";
            byte[] sdata = (byte[])data_bin.Rows[0]["SignData"];
            FileStream fs = new FileStream(str, FileMode.Create, FileAccess.Write);
            fs.Write(sdata, 0, sdata.Length);
            fs.Flush();
            fs.Close();
            Random r = new Random();
            string blockQualifiedFileName = str;
            string blockName = "Block" + r.Next(50);
            Database tmpDb = new Database(false, true);
            tmpDb.ReadDwgFile(blockQualifiedFileName, FileOpenMode.OpenForReadAndAllShare, true, "");
            double scale = 1;
            Matrix3d Transform = Matrix3d.Identity;
            Transform = Transform * Matrix3d.Scaling(scale, Point3d.Origin);
            // add the block to the ActiveDrawing blockTable
            acCurDb.Insert(blockName, tmpDb, true);
            BlockTableRecord btr = (BlockTableRecord)acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite);
            BlockReference br = new BlockReference(Point3d.Origin, acBlkTbl[blockName]);
            br.TransformBy(Matrix3d.Scaling(0.01, Point3d.Origin));
            br.TransformBy(Matrix3d.Displacement(pnt - Point3d.Origin).PreMultiplyBy(ed.CurrentUserCoordinateSystem));
            btr.AppendEntity(br);
            acTrans.AddNewlyCreatedDBObject(br, true);
            acTrans.Commit();
        }
Beispiel #34
0
        /// <summary>
        /// Вставка вхождения блока
        /// </summary>
        /// <param name="blName">Имя блока</param>
        /// <param name="pt">Точка вставки</param>
        /// <param name="owner">Контейнер</param>        
        /// <param name="t"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        public static BlockReference InsertBlockRef(string blName, Point3d pt, BlockTableRecord owner, Transaction t, double scale = 1)
        {
            Database db = owner.Database;
            var bt = db.BlockTableId.GetObject( OpenMode.ForRead)as BlockTable;
            var btr = bt[blName].GetObject(OpenMode.ForRead) as BlockTableRecord;
            var blRef = new BlockReference(pt, btr.Id);
            blRef.Position = pt;
            if (blRef.Annotative == AnnotativeStates.True)
            {
                // Установка аннотативного масштаба
                blRef.AddContext(db.Cannoscale);
            }
            else if (scale != 1)
            {
                blRef.TransformBy(Matrix3d.Scaling(scale, pt));
            }
            blRef.SetDatabaseDefaults();

            owner.AppendEntity(blRef);
            t.AddNewlyCreatedDBObject(blRef, true);

            AddAttributes(blRef, btr, t);
            return blRef;
        }
        private static void placementAparts(Database db)
        {
            using (var t = db.TransactionManager.StartTransaction())
            {
                ObjectId idTextStylePik = db.GetTextStylePIK();

                var bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
                var ms = bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite) as BlockTableRecord;
                int countAparts;
                var btrApartGroups = getGroupedAparts(bt, out countAparts);
                Point3d pt = Point3d.Origin;
                Point3d ptCenterPlace;

                using (var progress = new ProgressMeter())
                {
                    progress.SetLimit(countAparts);
                    progress.Start("Расстановка квартир...");

                    foreach (var btrApartGroup in btrApartGroups)
                    {
                        progress.MeterProgress();

                        foreach (var idBtrApart in btrApartGroup)
                        {
                            var curPlaceWidth = placeWidth;

                            var blRefApart = new BlockReference(pt, idBtrApart);
                            blRefApart.SetDatabaseDefaults(db);
                            var extApart = blRefApart.GeometricExtents;
                            var lenApart = extApart.MaxPoint.X - extApart.MinPoint.X;
                            if (lenApart > placeWidth)
                            {
                                curPlaceWidth = lenApart + 1000;
                            }

                            ptCenterPlace = new Point3d(pt.X + curPlaceWidth*0.5, pt.Y - placeHeight*0.5, 0);

                            var ptBlCenter = extApart.Center();
                            // Перемещение блока в центр прямоугольной области
                            Matrix3d displace = Matrix3d.Displacement(ptCenterPlace - ptBlCenter);
                            blRefApart.TransformBy(displace);
                            ms.AppendEntity(blRefApart);
                            t.AddNewlyCreatedDBObject(blRefApart, true);

                            // Подпись квартиры
                            DBText text = new DBText();
                            text.SetDatabaseDefaults();
                            text.TextStyleId = idTextStylePik;
                            text.Height = 900;
                            text.TextString = getApartName(blRefApart.Name);
                            text.Position = new Point3d (pt.X+300, pt.Y+300,0);
                            ms.AppendEntity(text);
                            t.AddNewlyCreatedDBObject(text, true);

                            // Прямоугольник расположения квартиры
                            Polyline pl = new Polyline(4);
                            pl.AddVertexAt(0, pt.Convert2d(), 0, 0, 0);
                            pl.AddVertexAt(1, new Point2d (pt.X+ curPlaceWidth, pt.Y), 0, 0, 0);
                            pl.AddVertexAt(2, new Point2d(pt.X + curPlaceWidth, pt.Y-placeHeight), 0, 0, 0);
                            pl.AddVertexAt(3, new Point2d(pt.X, pt.Y - placeHeight), 0, 0, 0);
                            pl.Closed = true;
                            pl.SetDatabaseDefaults();
                            ms.AppendEntity(pl);
                            t.AddNewlyCreatedDBObject(pl, true);

                            pt = new Point3d(pt.X + curPlaceWidth, pt.Y, 0);
                        }
                        pt = new Point3d(0, pt.Y - placeHeight - 8000, 0);
                    }
                    progress.Stop();
                }
                t.Commit();
            }
        }