Ejemplo n.º 1
0
        public static void ManualInsertbAttribute(string nameBlock)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTable blockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                if (!blockTable.Has(nameBlock))
                {
                    ed.WriteMessage("\nНезнайдено блок '{0}' у таблиці блоків креслення.", nameBlock);
                    return;
                }
                AcDb.BlockTableRecord curSpace       = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);
                AcDb.BlockReference   blockReference = new AcDb.BlockReference(AcGe.Point3d.Origin, blockTable[nameBlock]);
                blockReference.TransformBy(ed.CurrentUserCoordinateSystem);
                curSpace.AppendEntity(blockReference);
                tr.AddNewlyCreatedDBObject(blockReference, true);

                AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(blockTable[nameBlock], AcDb.OpenMode.ForRead);
                AcDb.DBText           text;
                foreach (AcDb.ObjectId id in btr)
                {
                    if (id.ObjectClass.Name == "AcDbAttributeDefinition")
                    {
                        AcDb.AttributeDefinition attDef =
                            (AcDb.AttributeDefinition)tr.GetObject(id, AcDb.OpenMode.ForRead);

                        text = new AcDb.DBText
                        {
                            TextString = "jig_test"
                        };

                        TextPlacementJig jig = new TextPlacementJig(text);

                        //PromptResult pr = ed.Drag(jig);

                        AcEd.PromptStatus stat = AcEd.PromptStatus.Keyword;
                        while (stat == AcEd.PromptStatus.Keyword)
                        {
                            AcEd.PromptResult pr = ed.Drag(jig);
                            stat = pr.Status;
                            if (stat != AcEd.PromptStatus.OK && stat != AcEd.PromptStatus.Keyword)
                            {
                                return;
                            }
                        }

                        AcDb.AttributeReference attRef = new AcDb.AttributeReference();
                        attRef.SetAttributeFromBlock(attDef, blockReference.BlockTransform);
                        AcDb.ObjectId attId = blockReference.AttributeCollection.AppendAttribute(attRef);
                        tr.AddNewlyCreatedDBObject(attRef, true);


                        tr.Commit();
                        //if (pr.Status != PromptStatus.OK) blockReference.Erase();
                    }
                }

                //tr.Commit();
            }
        }
Ejemplo n.º 2
0
        private bool GetExcelExportAtts()
        {
            _AttributesForExcelExport.Clear();
            _ColsForExcel.Clear();

            var doc = _AcAp.Application.DocumentManager.MdiActiveDocument;

            using (var trans = doc.TransactionManager.StartTransaction())
            {
                //var blockRefs = _BlocksForExcelExport.Select(oid => (_AcDb.BlockReference)trans.GetObject(oid, _AcDb.OpenMode.ForRead)).ToList();
                //List<_AcDb.ObjectId> btrOids = new List<_AcDb.ObjectId>();

                var           br   = (_AcDb.BlockReference)trans.GetObject(_BlocksForExcelExport[0], _AcDb.OpenMode.ForRead);
                var           bd   = (_AcDb.BlockTableRecord)trans.GetObject(br.BlockTableRecord, _AcDb.OpenMode.ForRead);
                List <string> atts = new List <string>();
                foreach (_AcDb.ObjectId oid in bd)
                {
                    _AcDb.AttributeDefinition adef = trans.GetObject(oid, _AcDb.OpenMode.ForRead) as _AcDb.AttributeDefinition;
                    if (adef != null)
                    {
                        string tagUC = adef.Tag.ToUpperInvariant();
                        _AttributesForExcelExport.Add(tagUC);
                    }
                }

                _ColsForExcel.Add(BLOCK_NAME, new List <string> {
                });
                _ColsForExcel.Add(HANDLE, new List <string> {
                });
                _ColsForExcel.Add(DWGPATH, new List <string> {
                });
                foreach (var att in _AttributesForExcelExport)
                {
                    if (!_ColsForExcel.ContainsKey(att))
                    {
                        _ColsForExcel.Add(att, new List <string> {
                        });
                    }
                }

                //_ColsForExcel.Add(BLOCK_NAME, new List<string> { BLOCK_NAME });
                //_ColsForExcel.Add(HANDLE, new List<string> { HANDLE });
                //_ColsForExcel.Add(DWGPATH, new List<string> { DWGPATH });
                //foreach (var att in _AttributesForExcelExport)
                //{
                //    if (!_ColsForExcel.ContainsKey(att))
                //    {
                //        _ColsForExcel.Add(att, new List<string> { att });
                //    }
                //}

                trans.Commit();
            }
            return(true);
        }
Ejemplo n.º 3
0
        private void insertBending(R.Raud _ALFA_, G.Point insertion)
        {
            string layerName = "K023TL";
            string blockName = getBendingBlockName(_ALFA_);

            _Ge.Point3d insertPointBlock = new _Ge.Point3d(insertion.X, insertion.Y, 0);

            using (_Db.BlockReference newBlockReference = new _Db.BlockReference(insertPointBlock, _c.blockTable[blockName]))
            {
                newBlockReference.Layer = layerName;
                _c.modelSpace.AppendEntity(newBlockReference);
                _c.trans.AddNewlyCreatedDBObject(newBlockReference, true);

                newBlockReference.TransformBy(_Ge.Matrix3d.Scaling(L._V_.Z_DRAWING_SCALE, insertPointBlock));

                _Db.BlockTableRecord blockBlockTable = _c.trans.GetObject(_c.blockTable[blockName], _Db.OpenMode.ForRead) as _Db.BlockTableRecord;
                if (blockBlockTable.HasAttributeDefinitions)
                {
                    foreach (_Db.ObjectId objID in blockBlockTable)
                    {
                        _Db.DBObject obj = _c.trans.GetObject(objID, _Db.OpenMode.ForRead) as _Db.DBObject;

                        if (obj is _Db.AttributeDefinition)
                        {
                            _Db.AttributeDefinition attDef = obj as _Db.AttributeDefinition;

                            if (!attDef.Constant)
                            {
                                using (_Db.AttributeReference attRef = new _Db.AttributeReference())
                                {
                                    attRef.SetAttributeFromBlock(attDef, newBlockReference.BlockTransform);
                                    attRef.Position = attDef.Position.TransformBy(newBlockReference.BlockTransform);
                                    setBendingBlockParameters(attRef, _ALFA_);
                                    newBlockReference.AttributeCollection.AppendAttribute(attRef);
                                    _c.trans.AddNewlyCreatedDBObject(attRef, true);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public LandBlockAttribJig(AcDb.BlockReference br)
     : base(br)
 {
     _attInfos = new Dictionary <string, TextInfo>();
     AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)br.BlockTableRecord.GetObject(AcDb.OpenMode.ForRead);
     foreach (AcDb.ObjectId id in btr)
     {
         if (id.ObjectClass.Name == "AcDbAttributeDefinition")
         {
             AcDb.AttributeDefinition attDef = (AcDb.AttributeDefinition)id.GetObject(AcDb.OpenMode.ForRead);
             TextInfo ti = new TextInfo()
             {
                 Position  = attDef.Position,
                 Alignment = attDef.AlignmentPoint,
                 IsAligned = attDef.Justify != AcDb.AttachmentPoint.BaseLeft,
                 Rotation  = attDef.Rotation
             };
             _attInfos.Add(attDef.Tag.ToUpper(), ti);
         }
     }
 }
Ejemplo n.º 5
0
        private void insertRow(G.Point insertion, T.TableBendingRow rowData, double scale, string tableBendingRow)
        {
            _Ge.Point3d insertPointBlock = new _Ge.Point3d(insertion.X, insertion.Y, 0);
            using (_Db.BlockReference newBlockReference = new _Db.BlockReference(insertPointBlock, _c.blockTable[tableBendingRow]))
            {
                newBlockReference.Layer = bendingLayer;
                _c.modelSpace.AppendEntity(newBlockReference);
                _c.trans.AddNewlyCreatedDBObject(newBlockReference, true);
                newBlockReference.TransformBy(_Ge.Matrix3d.Scaling(scale, insertPointBlock));

                _Db.BlockTableRecord blockBlockTable = _c.trans.GetObject(_c.blockTable[tableBendingRow], _Db.OpenMode.ForRead) as _Db.BlockTableRecord;
                if (blockBlockTable.HasAttributeDefinitions)
                {
                    foreach (_Db.ObjectId objID in blockBlockTable)
                    {
                        _Db.DBObject obj = _c.trans.GetObject(objID, _Db.OpenMode.ForRead) as _Db.DBObject;

                        if (obj is _Db.AttributeDefinition)
                        {
                            _Db.AttributeDefinition attDef = obj as _Db.AttributeDefinition;

                            if (!attDef.Constant)
                            {
                                using (_Db.AttributeReference attRef = new _Db.AttributeReference())
                                {
                                    attRef.SetAttributeFromBlock(attDef, newBlockReference.BlockTransform);
                                    attRef.Position = attDef.Position.TransformBy(newBlockReference.BlockTransform);
                                    setRowParameters(attRef, rowData);
                                    newBlockReference.AttributeCollection.AppendAttribute(attRef);
                                    _c.trans.AddNewlyCreatedDBObject(attRef, true);
                                }
                            }
                        }
                    }
                }
            }
        }