Exemple #1
0
        private void outputWeight(_Area_v2 a, int weight)
        {
            _Db.DBObject currentEntity = _c.trans.GetObject(a.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject;

            if (currentEntity is _Db.BlockReference)
            {
                _Db.BlockReference blockRef = currentEntity as _Db.BlockReference;

                foreach (_Db.ObjectId arId in blockRef.AttributeCollection)
                {
                    _Db.DBObject           obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite);
                    _Db.AttributeReference ar  = obj as _Db.AttributeReference;

                    if (ar != null)
                    {
                        if (ar.Tag == "SUMMA_OVRIG_ARMERING")
                        {
                            if (weight == 0)
                            {
                                write("[WARINING] Weight set to 'YYY'");
                                ar.TextString = "YYY";
                            }
                            else
                            {
                                ar.TextString = weight.ToString();
                            }
                        }
                    }
                }
            }

            _c.trans.Commit();
        }
Exemple #2
0
        private void createBlock(_Ge.Point3d center)
        {
            if (!_c.blockTable.Has(blockName))
            {
                write("Create missing block");

                _Db.BlockTableRecord btr = new _Db.BlockTableRecord();
                btr.Name = blockName;

                _Db.ObjectId btrId = _c.blockTable.Add(btr);
                _c.trans.AddNewlyCreatedDBObject(btr, true);

                createX(btr, 1.5, new _Ge.Point3d(0, 0, 0));
                createCircle(btr, 1, new _Ge.Point3d(0, 0, 0));

                _Db.BlockReference newBlockReference = new _Db.BlockReference(center, btrId);
                newBlockReference.TransformBy(_Ge.Matrix3d.Scaling(40, center));

                _c.modelSpace.AppendEntity(newBlockReference);
                _c.trans.AddNewlyCreatedDBObject(newBlockReference, true);
            }
            else
            {
                using (_Db.BlockReference newBlockReference = new _Db.BlockReference(center, _c.blockTable[blockName]))
                {
                    newBlockReference.TransformBy(_Ge.Matrix3d.Scaling(40, center));
                    _c.modelSpace.AppendEntity(newBlockReference);
                    _c.trans.AddNewlyCreatedDBObject(newBlockReference, true);
                }
            }
        }
Exemple #3
0
        private void CalcVolume(_AcDb.BlockReference blockRef)
        {
            var attHeight = GetBlockAttribute(HeightAttName, blockRef);
            var attArea   = GetBlockAttribute(AreaAttName, blockRef);
            var attVol    = GetBlockAttribute(VolAttName, blockRef);

            double height;

            if (!GetHeightFromString(attHeight.TextString, out height))
            {
                return;
            }

            double area;

            if (!GetAreaFromString(attArea.TextString, out area))
            {
                return;
            }

            double vol = height * area;

            attVol.UpgradeOpen();
            attVol.TextString = string.Format(CultureInfo.CurrentCulture, "Vol={0:F2}m3", vol);
        }
Exemple #4
0
        internal void CalcVolume(string raumBlockName, string areaAttName, string heightAttName, string volAttName)
        {
            RaumBlockName = raumBlockName;
            AreaAttName   = areaAttName;
            HeightAttName = heightAttName;
            VolAttName    = volAttName;

            if (!(CalcVolArgsOk))
            {
                return;
            }

            List <_AcDb.ObjectId> allRaumBlocks = SelectRaumBlocks();

            if (allRaumBlocks.Count == 0)
            {
                return;
            }

            using (_AcDb.Transaction myT = _TransMan.StartTransaction())
            {
                foreach (var oid in allRaumBlocks)
                {
                    _AcDb.BlockReference blockRef = _TransMan.GetObject(oid, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference;
                    if (blockRef == null)
                    {
                        continue;
                    }

                    CalcVolume(blockRef);
                }

                myT.Commit();
            }
        }
Exemple #5
0
        public void renameBlockFields(string find, string replace)
        {
            foreach (_Db.ObjectId btrId in _c.blockTable)
            {
                _Db.BlockTableRecord btr = _c.trans.GetObject(btrId, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;

                _Db.ObjectIdCollection blockRefIds = btr.GetBlockReferenceIds(true, true);

                foreach (_Db.ObjectId btRfId in blockRefIds)
                {
                    _Db.BlockReference br = _c.trans.GetObject(btRfId, _Db.OpenMode.ForWrite) as _Db.BlockReference;

                    if (br != null)
                    {
                        foreach (_Db.ObjectId arId in br.AttributeCollection)
                        {
                            _Db.DBObject           obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite);
                            _Db.AttributeReference ar  = obj as _Db.AttributeReference;

                            if (ar != null)
                            {
                                ar.TextString = ar.TextString.Replace(find, replace);
                            }
                        }
                    }
                }
            }
        }
        static public void DynamicBlockProps()
        {
            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database db  = doc.Database;
            _AcEd.Editor   ed  = doc.Editor;

            _AcEd.PromptStringOptions pso = new _AcEd.PromptStringOptions("\nEnter dynamic block name or enter to select: ");
            pso.AllowSpaces = true;
            _AcEd.PromptResult pr = ed.GetString(pso);

            if (pr.Status != _AcEd.PromptStatus.OK)
            {
                return;
            }

            _AcDb.Transaction tr = db.TransactionManager.StartTransaction();
            using (tr)
            {
                _AcDb.BlockReference br = null;
                // If a null string was entered allow entity selection
                if (pr.StringResult == "")
                {
                    // Select a block reference
                    _AcEd.PromptEntityOptions peo = new _AcEd.PromptEntityOptions("\nSelect dynamic block reference: ");
                    peo.SetRejectMessage("\nEntity is not a block.");
                    peo.AddAllowedClass(typeof(_AcDb.BlockReference), false);

                    _AcEd.PromptEntityResult per = ed.GetEntity(peo);
                    if (per.Status != _AcEd.PromptStatus.OK)
                    {
                        return;
                    }

                    // Access the selected block reference
                    br = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference;
                }

                else
                {
                    // Otherwise we look up the block by name
                    _AcDb.BlockTable bt = tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead) as _AcDb.BlockTable;
                    if (!bt.Has(pr.StringResult))
                    {
                        ed.WriteMessage("\nBlock \"" + pr.StringResult + "\" does not exist.");
                        return;
                    }

                    // Create a new block reference referring to the block
                    br = new _AcDb.BlockReference(new _AcGe.Point3d(), bt[pr.StringResult]);
                }

                _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(br.DynamicBlockTableRecord, _AcDb.OpenMode.ForRead);

                // Call our function to display the block properties
                DisplayDynBlockProperties(ed, br, btr.Name);

                // Committing is cheaper than aborting
                tr.Commit();
            }
        }
Exemple #7
0
        private void alfa(_Db.ObjectId id, ref List <_Db.Dimension> dims, ref List <_Db.BlockReference> blocks, ref List <_Db.MText> txts)
        {
            _Db.DBObject currentEntity = _c.trans.GetObject(id, _Db.OpenMode.ForWrite, false) as _Db.DBObject;

            if (currentEntity == null)
            {
                return;
            }

            else if (currentEntity is _Db.BlockReference)
            {
                _Db.BlockReference blockRef = currentEntity as _Db.BlockReference;

                _Db.BlockTableRecord block = null;
                if (blockRef.IsDynamicBlock)
                {
                    block = _c.trans.GetObject(blockRef.DynamicBlockTableRecord, _Db.OpenMode.ForRead) as _Db.BlockTableRecord;
                }
                else
                {
                    block = _c.trans.GetObject(blockRef.BlockTableRecord, _Db.OpenMode.ForRead) as _Db.BlockTableRecord;
                }

                if (block != null)
                {
                    blocks.Add(blockRef);
                }
            }
            else if (currentEntity is _Db.Dimension)
            {
                _Db.Dimension dim = currentEntity as _Db.Dimension;
                dims.Add(dim);
            }
            else if (currentEntity is _Db.MText)
            {
                _Db.MText br = currentEntity as _Db.MText;
                txts.Add(br);
            }
            else if (currentEntity is _Db.DBText)
            {
                _Db.DBText br = currentEntity as _Db.DBText;

                _Db.MText myMtext = new _Db.MText();
                myMtext.Contents   = br.TextString;
                myMtext.Location   = br.Position;
                myMtext.TextHeight = br.Height;
                txts.Add(myMtext);
            }
            else if (currentEntity is _Db.MLeader)
            {
                _Db.MLeader br = currentEntity as _Db.MLeader;

                if (br.ContentType == _Db.ContentType.MTextContent)
                {
                    _Db.MText leaderText = br.MText;
                    txts.Add(leaderText);
                }
            }
        }
Exemple #8
0
        private void outputTable(_Area_v2 a, List <_Mark> rows)
        {
            _Db.DBObject currentEntity = _c.trans.GetObject(a.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject;

            if (currentEntity is _Db.BlockReference)
            {
                _Db.BlockReference blockRef = currentEntity as _Db.BlockReference;

                double scale = blockRef.ScaleFactors.X;
                string name  = blockRef.Name;


                _Ge.Point3d currentPoint = a.Start;

                if (name == newBoxNames[0])
                {
                    currentPoint = new _Ge.Point3d(a.Start.X + (366 * scale), a.Start.Y + (141.8 * scale), a.Start.Z);
                }
                else if (name == newBoxNames[1])
                {
                    currentPoint = new _Ge.Point3d(a.Start.X + (366 * scale), a.Start.Y + (263.5 * scale), a.Start.Z);
                }

                int counter = 0;
                foreach (_Mark r in rows)
                {
                    if (r.Position != "emptyrow")
                    {
                        double txtHeight = 1.5 * scale;

                        _Ge.Point3d position_IP = new _Ge.Point3d(currentPoint.X + (1 * scale), currentPoint.Y + (1.125 * scale), currentPoint.Z);
                        _Ge.Point3d diameter_IP = new _Ge.Point3d(currentPoint.X + (0.75 * scale) + (6.1 * scale), currentPoint.Y + (1.125 * scale), currentPoint.Z);
                        _Ge.Point3d number_IP   = new _Ge.Point3d(currentPoint.X + (1.5 * scale) + (9.75 * scale), currentPoint.Y + (1.125 * scale), currentPoint.Z);

                        insertText(r.Position, position_IP, _Mark.markLayerName, txtHeight);
                        insertText(r.Diameter.ToString(), diameter_IP, _Mark.markLayerName, txtHeight);
                        insertText(r.Number.ToString(), number_IP, _Mark.markLayerName, txtHeight);
                    }

                    if (counter == 19)
                    {
                        if (name == newBoxNames[0])
                        {
                            currentPoint = new _Ge.Point3d(a.Start.X + (336 * scale), a.Start.Y + (141.8 * scale), a.Start.Z);
                        }
                        else if (name == newBoxNames[1])
                        {
                            currentPoint = new _Ge.Point3d(a.Start.X + (336 * scale), a.Start.Y + (263.5 * scale), a.Start.Z);
                        }
                    }
                    else
                    {
                        currentPoint = new _Ge.Point3d(currentPoint.X, currentPoint.Y - (4 * scale), currentPoint.Z);
                    }

                    counter++;
                }
            }
        }
        public static void ReplaceAttributeBlock(AcDb.ObjectId idBlock,
                                                 string tag,
                                                 string newValue,
                                                 Boolean visible)
        {
            try
            {
                //using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                //{
                //    DBObject dbObj = tr.GetObject(idBlock, AcDb.OpenMode.ForRead) as DBObject;
                //    AcDb.BlockReference blockReference = dbObj as BlockReference;
                //    ReplaceAttributeBlock(blockReference, tag, newValue, visible);
                //}


                using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    AcDb.BlockTable acBlockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                    if (acBlockTable == null)
                    {
                        return;
                    }

                    AcDb.BlockTableRecord acBlockTableRecord = (AcDb.BlockTableRecord)
                                                               tr.GetObject(acBlockTable[AcDb.BlockTableRecord.ModelSpace], AcDb.OpenMode.ForRead);
                    if (acBlockTableRecord == null)
                    {
                        return;
                    }

                    //foreach (var blkId in acBlockTableRecord)
                    //{
                    AcDb.BlockReference acBlock = (AcDb.BlockReference)tr.GetObject(idBlock, AcDb.OpenMode.ForRead);
                    //if (acBlock == null) continue;
                    //if (!acBlock.Name.Equals(blockName, StringComparison.CurrentCultureIgnoreCase)) continue;
                    foreach (AcDb.ObjectId attId in acBlock.AttributeCollection)
                    {
                        AcDb.AttributeReference acAtt = (AcDb.AttributeReference)tr.GetObject(attId, AcDb.OpenMode.ForRead);
                        if (acAtt == null)
                        {
                            continue;
                        }

                        if (!acAtt.Tag.Equals(tag, StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }

                        acAtt.UpgradeOpen();
                        acAtt.TextString = newValue;
                    }
                    //}
                    tr.Commit();
                }
            }
            catch //(System.Exception exc)
            {
            }
        }
        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();
            }
        }
Exemple #11
0
        private string getAreaName(_Area_v2 area)
        {
            string ritn_nr = "x";

            _Db.DBObject currentEntity = _c.trans.GetObject(area.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject;

            if (currentEntity is _Db.BlockReference)
            {
                _Db.BlockReference blockRef = currentEntity as _Db.BlockReference;

                foreach (_Db.ObjectId arId in blockRef.AttributeCollection)
                {
                    _Db.DBObject           obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite);
                    _Db.AttributeReference ar  = obj as _Db.AttributeReference;
                    if (ar != null)
                    {
                        if (ar.Tag == "RITN_NR")
                        {
                            ritn_nr = ar.TextString;
                        }

                        if (blockRef.Name == "KN-V23")
                        {
                            if (ar.Tag == "RITN_23_NR")
                            {
                                ritn_nr = ar.TextString;
                            }
                        }
                        else if (blockRef.Name == "KN-V27")
                        {
                            if (ar.Tag == "RITN_27_NR")
                            {
                                ritn_nr = ar.TextString;
                            }
                        }
                    }
                }

                if (blockRef.Name == "KN-V23")
                {
                    if (!ritn_nr.Contains("23"))
                    {
                        ritn_nr = "V23-" + ritn_nr;
                    }
                }
                else if (blockRef.Name == "KN-V27")
                {
                    if (!ritn_nr.Contains("73"))
                    {
                        ritn_nr = "V27-" + ritn_nr;
                    }
                }
            }

            return(ritn_nr);
        }
Exemple #12
0
        static public void Plan2CenterBlockSelBlock()
        {
            try
            {
                if (!OpenPalette())
                {
                    return;
                }

                var            opts = Globs.TheOptions;
                _AcAp.Document doc  = _AcAp.Application.DocumentManager.MdiActiveDocument;

                using (_AcAp.DocumentLock m_doclock = doc.LockDocument())
                {
                    _AcAp.DocumentCollection dm = _AcAp.Application.DocumentManager;
                    if (doc == null)
                    {
                        return;
                    }
                    _AcEd.Editor ed = doc.Editor;
#if NEWSETFOCUS
                    doc.Window.Focus();
#else
                    Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); // previous 2014 AutoCAD - Versions
#endif

                    _AcEd.PromptNestedEntityResult per = ed.GetNestedEntity("\nBlock wählen: ");

                    if (per.Status == _AcEd.PromptStatus.OK)
                    {
                        using (var tr = doc.TransactionManager.StartTransaction())
                        {
                            _AcDb.DBObject       obj = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead);
                            _AcDb.BlockReference br  = obj as _AcDb.BlockReference;
                            if (br == null)
                            {
                                br = Plan2Ext.Globs.GetBlockFromItsSubentity(tr, per);
                                if (br == null)
                                {
                                    return;
                                }
                            }

                            opts.SetBlockname(br.Name);

                            tr.Commit();
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2CenterBlockSelBlock aufgetreten! {0}", ex.Message));
            }
        }
Exemple #13
0
 public LandBlockJig(AcDb.BlockReference br)
     : base(br)
 {
     _br  = br;
     _pos = _br.Position;
     AcEd.Editor             ed     = CurrentCAD.Editor;
     AcGe.CoordinateSystem3d ucs    = ed.CurrentUserCoordinateSystem.CoordinateSystem3d;
     AcGe.Matrix3d           ocsMat = AcGe.Matrix3d.WorldToPlane(new AcGe.Plane(AcGe.Point3d.Origin, ucs.Zaxis));
     _ucsRot = AcGe.Vector3d.XAxis.GetAngleTo(ucs.Xaxis.TransformBy(ocsMat), ucs.Zaxis);
     _rot    = _br.Rotation - _ucsRot;
 }
Exemple #14
0
        private static bool HasWohnungblockInvalidKomma(_AcDb.BlockReference blockRef)
        {
            var attDict  = Globs.GetAttributesUcKey(blockRef);
            var nutzwert = Globs.GetValOrEmpty("NUTZWERT", attDict);

            if (nutzwert.IndexOf(".", StringComparison.Ordinal) >= 0)
            {
                return(true);
            }
            return(false);
        }
        public static void EditeAttributeBlock(string blockName, string tag, string newValue)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTable acBlockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                if (acBlockTable == null)
                {
                    return;
                }

                AcDb.BlockTableRecord acBlockTableRecord = (AcDb.BlockTableRecord)tr.GetObject(acBlockTable[AcDb.BlockTableRecord.ModelSpace], AcDb.OpenMode.ForRead);
                if (acBlockTableRecord == null)
                {
                    return;
                }

                foreach (var blkId in acBlockTableRecord)
                {
                    try
                    {
                        AcDb.BlockReference acBlock = (AcDb.BlockReference)tr.GetObject(blkId, AcDb.OpenMode.ForRead);
                        if (acBlock == null)
                        {
                            continue;
                        }
                        if (!acBlock.Name.Equals(blockName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }
                        foreach (AcDb.ObjectId attId in acBlock.AttributeCollection)
                        {
                            var acAtt = tr.GetObject(attId, AcDb.OpenMode.ForRead) as AcDb.AttributeReference;
                            if (acAtt == null)
                            {
                                continue;
                            }

                            if (!acAtt.Tag.Equals(tag, StringComparison.CurrentCultureIgnoreCase))
                            {
                                continue;
                            }

                            acAtt.UpgradeOpen();
                            acAtt.TextString = newValue;
                        }
                    }
                    catch
                    {
                    }
                }

                tr.Commit();
            }
        }
 public BlockPlacementJig(AcDb.BlockReference br, Dictionary <string, string> tags)
     : base(br)
 {
     blockReference = br;
     position       = blockReference.Position;
     AcEd.Editor             ed     = CurrentCAD.Editor;
     AcGe.CoordinateSystem3d ucs    = ed.CurrentUserCoordinateSystem.CoordinateSystem3d;
     AcGe.Matrix3d           ocsMat = AcGe.Matrix3d.WorldToPlane(new AcGe.Plane(AcGe.Point3d.Origin, ucs.Zaxis));
     ucsRotation = AcGe.Vector3d.XAxis.GetAngleTo(ucs.Xaxis.TransformBy(ocsMat), ucs.Zaxis);
     rotation    = blockReference.Rotation - ucsRotation;
     this.tags   = tags;
     layerId     = blockReference.LayerId;
 }
Exemple #17
0
        private string getAttributeValue(_Db.BlockReference block, string attribute)
        {
            _Db.DynamicBlockReferencePropertyCollection aa = block.DynamicBlockReferencePropertyCollection;
            foreach (_Db.DynamicBlockReferenceProperty a in aa)
            {
                if (a.PropertyName == attribute)
                {
                    return(a.Value.ToString());
                }
            }

            return(null);
        }
Exemple #18
0
        public static List <_AcDb.AttributeReference> GetAttributEntities(_AcDb.BlockReference blockRef, _AcDb.Transaction tr)
        {
            var atts = new List <_AcDb.AttributeReference>();

            foreach (_AcDb.ObjectId attId in blockRef.AttributeCollection)
            {
                var anyAttRef = tr.GetObject(attId, _AcDb.OpenMode.ForRead) as _AcDb.AttributeReference;
                if (anyAttRef != null)
                {
                    atts.Add(anyAttRef);
                }
            }
            return(atts);
        }
Exemple #19
0
        private double getAreaScale(_Area_v2 area)
        {
            double scale = 1;

            _Db.DBObject currentEntity = _c.trans.GetObject(area.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject;

            if (currentEntity is _Db.BlockReference)
            {
                _Db.BlockReference blockRef = currentEntity as _Db.BlockReference;
                scale = blockRef.ScaleFactors.X;
            }

            return(scale);
        }
Exemple #20
0
        public static Dictionary <string, _AcDb.AttributeReference> GetAttributes(_AcDb.BlockReference blockRef, _AcDb.Transaction trans)
        {
            var valuePerTag = new Dictionary <string, _AcDb.AttributeReference>();

            foreach (_AcDb.ObjectId attId in blockRef.AttributeCollection)
            {
                var anyAttRef = trans.GetObject(attId, _AcDb.OpenMode.ForRead) as _AcDb.AttributeReference;
                if (anyAttRef != null)
                {
                    valuePerTag[anyAttRef.Tag.ToUpperInvariant()] = anyAttRef;
                }
            }
            return(valuePerTag);
        }
Exemple #21
0
        private void get27Data(List <element> elements)
        {
            foreach (element el in elements)
            {
                _Area_v2 area = el._27;

                string date         = "xyz";
                string rev          = "xyz";
                string net_weight   = "xyz";
                string reinf_weight = "xyz";

                _Db.DBObject currentEntity = _c.trans.GetObject(area.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject;

                if (currentEntity is _Db.BlockReference)
                {
                    _Db.BlockReference blockRef = currentEntity as _Db.BlockReference;

                    foreach (_Db.ObjectId arId in blockRef.AttributeCollection)
                    {
                        _Db.DBObject           obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite);
                        _Db.AttributeReference ar  = obj as _Db.AttributeReference;
                        if (ar != null)
                        {
                            if (ar.Tag == "DATUM")
                            {
                                date = ar.TextString;
                            }
                            if (ar.Tag == "REVISION")
                            {
                                rev = ar.TextString;
                            }
                            if (ar.Tag == "SUMMA_NATARMERING")
                            {
                                net_weight = ar.TextString;
                            }
                            if (ar.Tag == "SUMMA_OVRIG_ARMERING")
                            {
                                reinf_weight = ar.TextString;
                            }
                        }
                    }
                }

                el._date27    = date;
                el._rev27     = rev;
                el._sum_net   = net_weight;
                el._sum_reinf = reinf_weight;
            }
        }
Exemple #22
0
        private List <_Db.BlockReference> getSelectedBlockReference(string[] blockNames)
        {
            List <_Db.BlockReference> refs = new List <_Db.BlockReference>();

            _Ed.PromptSelectionOptions opts = new _Ed.PromptSelectionOptions();
            opts.MessageForAdding = "\nSelect BLOCK " + blockNames[0] + " / " + blockNames[1];

            _Ed.PromptSelectionResult selection = _c.ed.GetSelection(opts);

            if (selection.Status == _Ed.PromptStatus.OK)
            {
                _Db.ObjectId[] selectionIds = selection.Value.GetObjectIds();

                foreach (_Db.ObjectId id in selectionIds)
                {
                    _Db.DBObject currentEntity = _c.trans.GetObject(id, _Db.OpenMode.ForWrite, false) as _Db.DBObject;

                    if (currentEntity == null)
                    {
                        continue;
                    }

                    else if (currentEntity is _Db.BlockReference)
                    {
                        _Db.BlockReference blockRef = currentEntity as _Db.BlockReference;

                        _Db.BlockTableRecord block = null;
                        if (blockRef.IsDynamicBlock)
                        {
                            block = _c.trans.GetObject(blockRef.DynamicBlockTableRecord, _Db.OpenMode.ForRead) as _Db.BlockTableRecord;
                        }
                        else
                        {
                            block = _c.trans.GetObject(blockRef.BlockTableRecord, _Db.OpenMode.ForRead) as _Db.BlockTableRecord;
                        }

                        if (block != null)
                        {
                            if (blockNames.Contains(block.Name))
                            {
                                refs.Add(blockRef);
                            }
                        }
                    }
                }
            }

            return(refs);
        }
Exemple #23
0
 private _AcDb.AttributeReference GetBlockAttribute(string name, _AcDb.BlockReference blockEnt, _AcDb.Transaction trans)
 {
     foreach (_AcDb.ObjectId attId in blockEnt.AttributeCollection)
     {
         var anyAttRef = trans.GetObject(attId, _AcDb.OpenMode.ForRead) as _AcDb.AttributeReference;
         if (anyAttRef != null)
         {
             if (string.Compare(anyAttRef.Tag, name, StringComparison.OrdinalIgnoreCase) == 0)
             {
                 return(anyAttRef);
             }
         }
     }
     return(null);
 }
Exemple #24
0
        private static bool SetAttValues(_AcDb.Database db)
        {
            bool ok = true;

            try
            {
                using (_AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    _AcDb.BlockTable bt = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);
                    foreach (var id in bt)
                    {
                        _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(id, _AcDb.OpenMode.ForRead);
                        if (btr.IsLayout)
                        {
                            foreach (var oid in btr)
                            {
                                var ent = tr.GetObject(oid, _AcDb.OpenMode.ForRead);
                                _AcDb.BlockReference bref = ent as _AcDb.BlockReference;
                                if (bref != null)
                                {
                                    bool sameName = false;
                                    try
                                    {
                                        sameName = (bref.Name == _BlockName);
                                    }
                                    catch (Exception)
                                    {
                                        log.WarnFormat("Invalid block with handle {0}!", bref.Handle);
                                    }
                                    if (sameName)
                                    {
                                        SetAttValues(bref, tr);
                                    }
                                }
                            }
                        }
                    }

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                log.Error(string.Format(CultureInfo.CurrentCulture, "Fehler beim Ändern der Attribute: {0}", ex.Message), ex);
                ok = false;
            }
            return(ok);
        }
        public static void ReplaceAttributeBlock(AcDb.BlockReference blockReference,
                                                 Dictionary <string, string> tags,
                                                 Boolean visible)
        {
            using (AcDb.Transaction trAdding = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTable       btTable  = (AcDb.BlockTable)trAdding.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                AcDb.BlockTableRecord btrTable =
                    (AcDb.BlockTableRecord)btTable[blockReference.Name].GetObject(AcDb.OpenMode.ForRead);

                if (btrTable.HasAttributeDefinitions)
                {
                    var attDefs = btrTable.Cast <AcDb.ObjectId>()
                                  .Where(n => n.ObjectClass.Name == "AcDbAttributeDefinition")
                                  .Select(n => (AcDb.AttributeDefinition)n.GetObject(AcDb.OpenMode.ForRead));

                    foreach (AcDb.AttributeDefinition attDef in attDefs)
                    {
                        AcDb.AttributeReference attRef = new AcDb.AttributeReference();
                        attRef.SetAttributeFromBlock(attDef, blockReference.BlockTransform);

                        foreach (var tag in tags)
                        {
                            attRef.UpgradeOpen();
                            if (tag.Key.ToUpper() == attRef.Tag)
                            {
                                attRef.TextString = tag.Value;
                            }
                            else
                            {
                                attRef.TextString = "NoneValue";
                            }
                            attRef.Visible  = visible;
                            attRef.Rotation = 0;
                        }

                        blockReference.AttributeCollection.AppendAttribute(attRef);
                        trAdding.AddNewlyCreatedDBObject(attRef, false);
                    }
                }
                else
                {
                    ed.WriteMessage("\n < ERROR > ");
                }

                trAdding.Commit();
            }
        }
Exemple #26
0
        private void ExplodeBlocks(_AcDb.Database db, List <_AcDb.ObjectId> allXrefsInMs, List <_AcDb.ObjectId> newlyCreatedObjects, bool deleteRef, bool deleteBtr)
        {
            log.Debug("ExplodeXRefs");
            using (_AcDb.Transaction tr = _TransMan.StartTransaction())
            {
                _AcDb.BlockTable bt = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);

                _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(_AcDb.SymbolUtilityServices.GetBlockModelSpaceId(db), _AcDb.OpenMode.ForWrite);


                foreach (var oid in allXrefsInMs)
                {
                    _AcDb.DBObjectCollection objs  = new _AcDb.DBObjectCollection();
                    _AcDb.BlockReference     block = (_AcDb.BlockReference)tr.GetObject(oid, _AcDb.OpenMode.ForRead);
                    log.DebugFormat(CultureInfo.CurrentCulture, "Explode von Block '{0}'.", block.Name);
                    block.Explode(objs);
                    log.DebugFormat(CultureInfo.CurrentCulture, "Block enthält {0} Entities.", objs.Count);
                    _AcDb.ObjectId blockRefTableId = block.BlockTableRecord;


                    foreach (_AcDb.DBObject obj in objs)
                    {
                        _AcDb.Entity ent = (_AcDb.Entity)obj;
                        btr.AppendEntity(ent);
                        tr.AddNewlyCreatedDBObject(ent, true);

                        newlyCreatedObjects.Add(ent.ObjectId);
                    }

                    if (deleteRef)
                    {
                        log.DebugFormat(CultureInfo.CurrentCulture, "Lösche Block '{0}'.", block.Name);
                        block.UpgradeOpen();
                        block.Erase();
                    }

                    if (deleteBtr)
                    {
                        log.DebugFormat("DeleteBtr");
                        // funkt nicht -> xref würde gelöscht
                        var bd = (_AcDb.BlockTableRecord)tr.GetObject(blockRefTableId, _AcDb.OpenMode.ForWrite);
                        bd.Erase();
                        log.DebugFormat("Endof DeleteBtr");
                    }
                }
                tr.Commit();
            }
        }
Exemple #27
0
 private static bool IsXref(_AcDb.BlockReference bref, _AcDb.Transaction tr)
 {
     try
     {
         var bd = (_AcDb.BlockTableRecord)tr.GetObject(bref.BlockTableRecord, _AcDb.OpenMode.ForRead);
         if (bd.IsFromExternalReference)
         {
             return(true);
         }
     }
     catch (Exception)
     {
         log.WarnFormat("Invalid block with handle {0}!", bref.Handle);
     }
     return(false);
 }
Exemple #28
0
        private void insertReinforcementSingle(R.Raud _ALFA_, bool arrayReinf)
        {
            string layerName = "Armatuur";
            string blockName = getReinforcementBlockName(_ALFA_, arrayReinf);

            _Ge.Point3d insertPointBlock = new _Ge.Point3d(_ALFA_.StartPoint.X, _ALFA_.StartPoint.Y, 0);
            using (_Db.BlockReference newBlockReference = new _Db.BlockReference(insertPointBlock, _c.blockTable[blockName]))
            {
                newBlockReference.Rotation = _ALFA_.Rotation;
                newBlockReference.Layer    = layerName;
                _c.modelSpace.AppendEntity(newBlockReference);
                _c.trans.AddNewlyCreatedDBObject(newBlockReference, true);

                setReinforcementBlockParameters(newBlockReference, _ALFA_);
            }
        }
        private void AddRbToRetCol(List <_AcDb.ObjectId> Ret, _AcDb.TransactionManager tm, _AcDb.ObjectId elFG)
        {
            _AcDb.Extents3d ext    = GetExtents(tm, elFG);
            _AcGe.Point3d   minExt = new _AcGe.Point3d(ext.MinPoint.X - ABSTANDTEXT, ext.MinPoint.Y - ABSTANDTEXT, ext.MinPoint.Z);
            _AcGe.Point3d   maxExt = new _AcGe.Point3d(ext.MaxPoint.X + ABSTANDTEXT, ext.MaxPoint.Y + ABSTANDTEXT, ext.MaxPoint.Z);

            _AcEd.Editor          ed     = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
            _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] {
                new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "INSERT"),
                new _AcDb.TypedValue((int)_AcDb.DxfCode.BlockName, _RaumblockName)
            });
            _AcEd.PromptSelectionResult res = null;
            res = ed.SelectCrossingWindow(minExt, maxExt, filter);
            if (res.Status != _AcEd.PromptStatus.OK)
            {
                // todo: logging: lot4net?
                return;
            }

#if BRX_APP
            _AcEd.SelectionSet ss = res.Value;
#else
            using (_AcEd.SelectionSet ss = res.Value)
#endif
            {
                _AcDb.ObjectId[] idArray = ss.GetObjectIds();
                for (int i = 0; i < idArray.Length; i++)
                {
                    _AcDb.ObjectId oid = idArray[i];
                    using (_AcDb.DBObject pEntity = tm.GetObject(oid, _AcDb.OpenMode.ForRead, false))
                    {
                        using (_AcDb.Entity entElFG = tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false) as _AcDb.Entity)
                        {
                            if (pEntity is _AcDb.BlockReference)
                            {
                                _AcDb.BlockReference br = pEntity as _AcDb.BlockReference;
                                if (AreaEngine.InPoly(br.Position, entElFG))
                                {
                                    Ret.Add(oid);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #30
0
        private _Ge.Point3d getAreaCenter(_Area_v2 area)
        {
            _Ge.Point3d center = new _Ge.Point3d(0, 0, 0);

            _Db.DBObject currentEntity = _c.trans.GetObject(area.ID, _Db.OpenMode.ForWrite, false) as _Db.DBObject;

            if (currentEntity is _Db.BlockReference)
            {
                _Db.BlockReference blockRef = currentEntity as _Db.BlockReference;
                _Ge.Point3d        max      = blockRef.GeometricExtents.MaxPoint;
                _Ge.Point3d        min      = blockRef.GeometricExtents.MinPoint;

                center = new _Ge.Point3d(min.X + ((max.X - min.X) / 2), min.Y + ((max.Y - min.Y) / 2), 0);
            }

            return(center);
        }