public static void StatisticsModel123_Steel4(BeamData beam, AcadDB.BlockReference blk_ref)
        {
            AcadDB.Database db = AcadApp.DocumentManager.MdiActiveDocument.Database;
            using (AcadDB.Transaction trans = db.TransactionManager.StartTransaction())
            {
                AcadDB.AttributeCollection atts = blk_ref.AttributeCollection;
                foreach (AcadDB.ObjectId att in atts)
                {
                    AcadDB.AttributeReference att_ref = trans.GetObject(att, AcadDB.OpenMode.ForWrite) as AcadDB.AttributeReference;
                    if (null == att_ref)
                    {
                        continue;
                    }

                    if (ATT_SH == att_ref.Tag)
                    {
                        att_ref.TextString = "4";
                    }
                    if (ATT_DK == att_ref.Tag)
                    {
                        att_ref.TextString = beam.dau_goi_data.first_layer_diameter.ToString();
                    }
                    if (ATT_DAI == att_ref.Tag)
                    {
                        att_ref.TextString = (beam.Length - 2 * Beam.cover).ToString();
                    }
                    if (ATT_L2 == att_ref.Tag)
                    {
                        att_ref.TextString = "2000";
                    }
                    if (ATT_L1 == att_ref.Tag)
                    {
                        att_ref.TextString = (beam.Height - 2 * Beam.cover).ToString();
                    }
                    if (ATT_SL1 == att_ref.Tag)
                    {
                        att_ref.TextString = (beam.dau_goi_data.number_steel_first_layer).ToString();
                    }
                    if (ATT_SLA == att_ref.Tag)
                    {
                        att_ref.TextString = (beam.dau_goi_data.number_steel_first_layer).ToString();
                    }
                    if (ATT_DT == att_ref.Tag)
                    {
                        double total_len = beam.dau_goi_data.number_steel_first_layer * (beam.Length - 2 * Beam.cover);
                        total_len         /= 1000.0;
                        att_ref.TextString = (total_len).ToString();
                    }
                    if (ATT_TL == att_ref.Tag)
                    {
                        att_ref.TextString = "...";
                    }
                }

                trans.Commit();
            }
        }
Exemple #2
0
        private void btnSelBlk_Click(object sender, EventArgs e)
        {
            Editor editor            = AcAp.DocumentManager.MdiActiveDocument.Editor;
            PromptEntityOptions pEnt = new PromptEntityOptions("\nSelect Block: ");

            pEnt.AllowNone = true;
            pEnt.SetRejectMessage("Selected Object is not a Block!.");
            pEnt.AddAllowedClass(typeof(BlockReference), true);
            PromptEntityResult pEntRes = editor.GetEntity(pEnt);

            if (pEntRes.Status != PromptStatus.OK)
            {
                return;
            }
            BlockReference bRef = pEntRes.ObjectId.GetObject <BlockReference>();
            Dictionary <string, string> dicTag = new Dictionary <string, string>();

            for (int i = 0; i < bRef.AttributeCollection.Count; i++)
            {
                string strTag        = bRef.AttributeCollection[i].GetObject <AttributeReference>(OpenMode.ForRead).Tag;
                string strTextString = bRef.AttributeCollection[i].GetObject <AttributeReference>(OpenMode.ForRead).TextString;
                dicTag.Add(strTag, strTextString);
                switch (i)
                {
                case 0:
                {
                    lblTag1.Text     = strTag;
                    textString1.Text = strTextString;
                }
                break;

                case 1:
                {
                    lblTag2.Text     = strTag;
                    textString2.Text = strTextString;
                }
                break;

                case 2:
                {
                    lblTag3.Text     = strTag;
                    textString3.Text = strTextString;
                }
                break;

                case 3:
                {
                    lblTag4.Text     = strTag;
                    textString4.Text = strTextString;
                }
                break;

                default:
                    break;
                }
            }
            if (objRot.Checked)
            {
                this.BlockRotation = bRef.Rotation;
                txtBlkRot.Text     = Converter.AngleToString(bRef.Rotation);
            }
            else
            {
                this.BlockRotation = Converter.StringToAngle(txtRot.Text);
            }
            txtRot.Text = Converter.AngleToString(bRef.Rotation);
            Autodesk.AutoCAD.DatabaseServices.AttributeCollection attRefColl = bRef.AttributeCollection;
            if (attRefColl == null || attRefColl.Count == 0)
            {
                AcAp.ShowAlertDialog("Selected Block do not have Attributes.");
                return;
            }
            this.cbxBlock.SelectedItem = (bRef.IsDynamicBlock ? bRef.DynamicBlockTableRecord.GetObject <BlockTableRecord>() : bRef.BlockTableRecord.GetObject <BlockTableRecord>());
        }
Exemple #3
0
        addBlockRef(string strName, Point3d pnt3dIns, double dblRotation, List <string> attValues)
        {
            Database db = BaseObjs._db;
            Editor   ed = BaseObjs._editor;

            BlockTableRecord btrx = null;
            BlockReference   br   = null;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead);
                    if (!bt.Has(strName))
                    {
                        btrx = addBtr(strName);
                    }
                    else
                    {
                        btrx = (BlockTableRecord)bt[strName].GetObject(OpenMode.ForRead);
                    }

                    //---> debug only
                    foreach (ObjectId idObj in btrx)
                    {
                        Entity ent             = (Entity)idObj.GetObject(OpenMode.ForRead);
                        AttributeDefinition ad = ent as AttributeDefinition;

                        if (ad != null)
                        {
                            ed.WriteMessage(string.Format("\n{0}", ad.Tag));
                        }
                    }//<--- debug only

                    //BlockTableRecord Btr = (BlockTableRecord)DB.CurrentSpaceId.GetObject(OpenMode.ForWrite);

                    btrx.UpgradeOpen();

                    using (btrx)
                    {
                        br = new BlockReference(pnt3dIns, btrx.ObjectId);
                        using (br)
                        {
                            Matrix3d           ucsMatrix = ed.CurrentUserCoordinateSystem;
                            CoordinateSystem3d ucs       = ucsMatrix.CoordinateSystem3d;

                            Matrix3d mat3d = new Matrix3d();
                            mat3d = Matrix3d.Rotation(dblRotation, ucs.Zaxis, pnt3dIns);

                            br.TransformBy(mat3d);
                            br.ScaleFactors = new Scale3d(1, 1, 1);
                            btrx.AppendEntity(br);
                            tr.AddNewlyCreatedDBObject(br, true);

                            BlockTableRecord btratt = (BlockTableRecord)br.BlockTableRecord.GetObject(OpenMode.ForRead);
                            using (btratt)
                            {
                                Autodesk.AutoCAD.DatabaseServices.AttributeCollection ATTcol = br.AttributeCollection;

                                foreach (ObjectId subid in btratt)
                                {
                                    Entity ent             = (Entity)subid.GetObject(OpenMode.ForRead);
                                    AttributeDefinition ad = ent as AttributeDefinition;

                                    if (ad != null)
                                    {
                                        AttributeReference ar = new AttributeReference();
                                        ar.SetPropertiesFrom(ad);
                                        ar.SetAttributeFromBlock(ad, br.BlockTransform);
                                        ar.Visible = ad.Visible;

                                        ar.HorizontalMode = ad.HorizontalMode;
                                        ar.VerticalMode   = ad.VerticalMode;
                                        ar.Rotation       = ad.Rotation;
                                        ar.TextStyleId    = ad.TextStyleId;
                                        ar.Position       = ad.Position + pnt3dIns.GetAsVector();
                                        ar.Tag            = ad.Tag;
                                        ar.FieldLength    = ad.FieldLength;
                                        ar.AdjustAlignment(db);

                                        //if (ar.Tag == "TOPTXT")
                                        //    ar.TextString = strTop;

                                        //if (ar.Tag == "MIDTXT")
                                        //    ar.TextString = strMid;

                                        //if (ar.Tag == "BOTTXT")
                                        //    ar.TextString = strBot;

                                        ar.Position = ad.Position.TransformBy(br.BlockTransform);

                                        ATTcol.AppendAttribute(ar);
                                        tr.AddNewlyCreatedDBObject(ar, true);
                                    }
                                }
                            }
                            br.DowngradeOpen();
                        }

                        btrx.DowngradeOpen();
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Blocks.cs: line: 194");
            }
            return(br);
        }
Exemple #4
0
        addBlockRef(string strName, string strTopNum, string strTopTxt, string strBotNum, string strBotTxt, Point3d pnt3dIns, double dblRotation)
        {
            Database DB = BaseObjs._db;
            Editor   ED = BaseObjs._editor;

            ObjectId         blkID = ObjectId.Null;
            BlockTableRecord Btrx  = null;

            using (Transaction tr = BaseObjs.startTransactionDb())
            {
                BlockTable BT = (BlockTable)DB.BlockTableId.GetObject(OpenMode.ForRead);
                if (!BT.Has(strName))
                {
                    blkID = insBlockRef(@"R:\Tset\Block\", "GradeTag.dwg");
                    Btrx  = (BlockTableRecord)blkID.GetObject(OpenMode.ForRead);
                    Btrx.UpgradeOpen();
                    Btrx.Name = "GradeTag";
                    Btrx.DowngradeOpen();
                }
                else
                {
                    Btrx = (BlockTableRecord)BT[strName].GetObject(OpenMode.ForRead);
                }

                //---> debug only
                foreach (ObjectId objID in Btrx)
                {
                    Entity ENT             = (Entity)objID.GetObject(OpenMode.ForRead);
                    AttributeDefinition AD = ENT as AttributeDefinition;

                    if (AD != null)
                    {
                        ED.WriteMessage(string.Format("\n{0}", AD.Tag));
                    }
                }//<--- debug only

                BlockTableRecord Btr = (BlockTableRecord)DB.CurrentSpaceId.GetObject(OpenMode.ForWrite);

                using (Btr)
                {
                    BlockReference BR = new BlockReference(pnt3dIns, Btrx.ObjectId);
                    using (BR)
                    {
                        Matrix3d           UCSMatrix = ED.CurrentUserCoordinateSystem;
                        CoordinateSystem3d UCS       = UCSMatrix.CoordinateSystem3d;

                        Matrix3d MAT3d = new Matrix3d();
                        MAT3d = Matrix3d.Rotation(dblRotation, UCS.Zaxis, pnt3dIns);

                        BR.TransformBy(MAT3d);
                        BR.ScaleFactors = new Scale3d(1, 1, 1);
                        Btr.AppendEntity(BR);
                        tr.AddNewlyCreatedDBObject(BR, true);

                        BlockTableRecord Btratt = (BlockTableRecord)BR.BlockTableRecord.GetObject(OpenMode.ForRead);
                        using (Btratt)
                        {
                            Autodesk.AutoCAD.DatabaseServices.AttributeCollection ATTcol = BR.AttributeCollection;

                            foreach (ObjectId subID in Btratt)
                            {
                                Entity ENT             = (Entity)subID.GetObject(OpenMode.ForRead);
                                AttributeDefinition AD = ENT as AttributeDefinition;

                                if (AD != null)
                                {
                                    AttributeReference AR = new AttributeReference();
                                    AR.SetPropertiesFrom(AD);
                                    AR.SetAttributeFromBlock(AD, BR.BlockTransform);
                                    AR.Visible = AD.Visible;

                                    AR.HorizontalMode = AD.HorizontalMode;
                                    AR.VerticalMode   = AD.VerticalMode;
                                    AR.Rotation       = AD.Rotation;
                                    AR.TextStyleId    = AD.TextStyleId;
                                    AR.Position       = AD.Position + pnt3dIns.GetAsVector();
                                    AR.Tag            = AD.Tag;
                                    AR.FieldLength    = AD.FieldLength;
                                    AR.AdjustAlignment(DB);

                                    if (AR.Tag == "TOPNUM")
                                    {
                                        AR.TextString = strTopNum;
                                    }

                                    if (AR.Tag == "TOPTXT")
                                    {
                                        AR.TextString = strTopTxt;
                                    }

                                    if (AR.Tag == "BOTNUM")
                                    {
                                        AR.TextString = strBotNum;
                                    }

                                    if (AR.Tag == "BOTTXT")
                                    {
                                        AR.TextString = strBotTxt;
                                    }

                                    AR.Position = AD.Position.TransformBy(BR.BlockTransform);

                                    ATTcol.AppendAttribute(AR);
                                    tr.AddNewlyCreatedDBObject(AR, true);
                                } // end if
                            }     //end foreach
                        }
                        BR.DowngradeOpen();
                    }

                    Btr.DowngradeOpen();
                }

                // BT.DowngradeOpen ();
                tr.Commit();
            }
            return(true);
        }
Exemple #5
0
        public override String Process()
        {
            try
            {
                BeforeProcessing();
            }
            catch (System.Exception se)
            {
                return("Keyfile Generation processing exception: " + se.Message);
            }
            //if (!CheckDirPath()) { return "Invalid path: " + _Path; }

            //try
            //{
            //    _Logger = new Logger(String.Concat(_Path, "\\KeyfileErrors.txt"));
            //}
            //catch (System.Exception se)
            //{
            //    // FATAL ERROR
            //    return "Could not create log file in: " + _Path + " because: " + se.Message;
            //}

            //StartTimer();

            // Get all DWG files
            try
            {
                GetDwgList(SearchOption.TopDirectoryOnly, delegate(String inFile) { return((System.IO.Path.GetFileNameWithoutExtension(inFile).Length < 15)); });
            }
            catch (SystemException se)
            {
                _Logger.Log(" DWG files could not be enumerated because: " + se.Message);
                _Logger.Dispose();
                return(" DWG files could not be enumerated because: " + se.Message);
            }

            if (NumDwgs == 0)
            {
                return("No DWGs found in: " + _Path);
            }

            foreach (String currentDWG in DwgList)
            {
                DwgCounter++;

                try { _Bw.ReportProgress(Utilities.GetPercentage(DwgCounter, NumDwgs)); }
                catch { }

                if (_Bw.CancellationPending)
                {
                    _Logger.Log("Keyfile generation cancelled by user at dwg " + DwgCounter.ToString() + " out of " + DwgList.Count);
                    break;
                }

                String dwgNameNoExt = System.IO.Path.GetFileNameWithoutExtension(currentDWG);
                String dwgNameExt   = System.IO.Path.GetFileName(currentDWG);
                String ms           = String.Empty;

                using (Database db = new Database(false, true))
                {
                    try
                    {
                        db.ReadDwgFile(currentDWG, FileOpenMode.OpenForReadAndWriteNoShare, true, String.Empty);
                        db.Regenmode = true;
                        db.CloseInput(true);
                    }
                    catch (Autodesk.AutoCAD.Runtime.Exception e)
                    {
                        _Logger.Log(String.Concat("Could not read DWG: ", dwgNameNoExt, " because: ", e.Message, "...Continuing to next DWG"));
                        continue;
                    }

                    using (Transaction acTrans = db.TransactionManager.StartTransaction())
                    {
                        // Unlock and thaw all layers
                        ToEach.toEachLayer(db, acTrans, delegate(LayerTableRecord ltr)
                        {
                            if (ltr.IsLocked)
                            {
                                ltr.IsLocked = false;
                            }
                            if (ltr.IsFrozen)
                            {
                                ltr.IsFrozen = false;
                            }
                            return(false);
                        });

                        XmlWriterSettings settings = new XmlWriterSettings();
                        settings.Encoding = Encoding.ASCII;
                        settings.Indent   = true;
                        XmlWriter xmlW = XmlWriter.Create(_Path + "\\" + dwgNameNoExt + "_key.xml", settings);

                        if (xmlW == null)
                        {
                            _Logger.Log("XML writer could not be initialized.");
                            _Logger.Dispose();
                            return("XML file could not be initialized.");
                        }

                        try
                        {
                            xmlW.WriteStartDocument();
                            xmlW.WriteStartElement("rpstl_keyfile");
                            xmlW.WriteAttributeString("version", "2.0");
                            xmlW.WriteStartElement("filename");
                            xmlW.WriteAttributeString("text", dwgNameExt);
                            xmlW.WriteEndElement();

                            // Write dwg extents
                            xmlW.WriteStartElement("extents");
                            xmlW.WriteAttributeString("x1", db.Extmin.X.truncstring(3));
                            xmlW.WriteAttributeString("y1", db.Extmin.Y.truncstring(3));
                            xmlW.WriteAttributeString("x2", db.Extmax.X.truncstring(3));
                            xmlW.WriteAttributeString("y2", db.Extmax.Y.truncstring(3));

                            double height = db.Extmax.Y - db.Extmin.Y;
                            double width  = db.Extmax.X - db.Extmin.X;

                            // Write document height and width
                            xmlW.WriteAttributeString("height", height.truncstring(3));
                            xmlW.WriteAttributeString("width", width.truncstring(3));

                            xmlW.WriteEndElement();

                            // Unlock all layers
                            ToEach.toEachLayer(db, acTrans, delegate(LayerTableRecord ltr)
                            {
                                if (ltr.IsLocked)
                                {
                                    ltr.IsLocked = false;
                                }
                                return(false);
                            }
                                               );

                            db.Regenmode = true;

                            ObjectIdCollection oidc = new ObjectIdCollection();
                            ToEach.toEachEntity(db, acTrans, delegate(Entity ent) { oidc.Add(ent.Id); return(false); });
                            db.Purge(oidc);

                            //Make Dictionary to map layerIds to layer names
                            // Note neccessary because the DBText .Layer property isn't working
                            Dictionary <ObjectId, String> LayerIdToLayerName = new Dictionary <ObjectId, string>();

                            using (LayerTable lt = acTrans.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable)
                            {
                                foreach (ObjectId layerOid in lt)
                                {
                                    using (LayerTableRecord ltr = acTrans.GetObject(layerOid, OpenMode.ForRead) as LayerTableRecord)
                                    {
                                        LayerIdToLayerName.Add(ltr.Id, ltr.Name);
                                    }
                                }
                            }

                            using (LayerTable lt = acTrans.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable)
                            {
                                foreach (ObjectId oid in lt)
                                {
                                    List <DBText>         msNos       = new List <DBText>();
                                    List <DBText>         callouts    = new List <DBText>();
                                    List <DBText>         viewLetters = new List <DBText>();
                                    List <DBText>         miscTexts   = new List <DBText>();
                                    List <BlockReference> cards       = new List <BlockReference>();
                                    //IEnumerable<DBText> msnos = new List<DBText>();
                                    StringBuilder prefixString = new StringBuilder();

                                    using (LayerTableRecord ltr = acTrans.GetObject(oid, OpenMode.ForRead) as LayerTableRecord)
                                    {
                                        List <DBText> linesBelowDesignations = new List <DBText>();

                                        using (BlockTable bt = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable)
                                        {
                                            using (BlockTableRecord btr = acTrans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord)
                                            {
                                                foreach (ObjectId oidbtr in btr)
                                                {
                                                    Entity ent = acTrans.GetObject(oidbtr, OpenMode.ForRead) as Entity;

                                                    if (ent.LayerId == ltr.Id)
                                                    {
                                                        if (ent.GetType() == typeof(DBText))
                                                        {
                                                            DBText dbt = ent as DBText;

                                                            String layerName = LayerIdToLayerName[dbt.LayerId];
                                                            // Skip everything on "FILENAME" and "SCALE" layers
                                                            if (String.Equals(layerName, "FILENAME") || String.Equals(layerName, "SCALE"))
                                                            {
                                                                continue;
                                                            }

                                                            if (dbt.TextString.Trim().ToUpper().EndsWith("(REF)"))
                                                            {
                                                                // Skip old refdess
                                                                continue;
                                                            }

                                                            // P/0 instead of P/O
                                                            if (String.Equals(dbt.TextString.Trim(), "P/0"))
                                                            {
                                                                _Logger.Log("P/0 found instead of P/O on layer: " + dbt.Layer + " in DWG: " + dwgNameNoExt);
                                                            }

                                                            if (calloutRegex.IsMatch(dbt.TextString) && !dbt.TextString.Contains("-") && layerName.StartsWith("m"))
                                                            {
                                                                callouts.Add(dbt);
                                                                continue;
                                                            }

                                                            // Skip view letters that are on layers that aren't m layers
                                                            if (viewLetterRegex.IsMatch(dbt.TextString.Trim()) && layerName.StartsWith("m"))
                                                            {
                                                                viewLetters.Add(dbt);
                                                                continue;
                                                            }

                                                            // Skip msnos that are on layers that aren't m layers
                                                            if ((msRegex.IsMatch(dbt.TextString.ToUpper()) || letterRegex.IsMatch(dbt.TextString.ToUpper())) && layerName.StartsWith("m"))
                                                            {
                                                                msNos.Add(dbt);
                                                                continue;
                                                            }

                                                            if (refDesRegex.IsMatch(dbt.TextString.ToUpper().Trim())) //&&
                                                            {
                                                                // Do nothing
                                                                // Look for refdess on a per-callout basis because refdes
                                                                // must be within a certain range of each callout
                                                                continue;
                                                            }

                                                            // Check if text refdes
                                                            if (dbt.TextString.Contains("DESIGNATIONS"))
                                                            {
                                                                // Get prefix from line with Designations
                                                                prefixString.Append(dbt.TextString.Substring(dbt.TextString.IndexOf("WITH") + 5).Trim());

                                                                // Get each line below Designations line and add it to list
                                                                linesBelowDesignations = ToEach.toEachDBText(db,
                                                                                                             acTrans,
                                                                                                             delegate(DBText dbtUnderDes)
                                                                {
                                                                    double yDiff = dbt.Position.Y - dbtUnderDes.Position.Y;
                                                                    double xDiff = Math.Abs(dbt.Position.X - dbtUnderDes.Position.X);

                                                                    return((dbt.Id != dbtUnderDes.Id) &&
                                                                           (dbt.LayerId == dbtUnderDes.LayerId) &&
                                                                           (dbt.Position.Y > dbtUnderDes.Position.Y) &&
                                                                           (yDiff < .5) &&
                                                                           (xDiff < .02));
                                                                });

                                                                // Append each line to String and format it with spaces and commas
                                                                foreach (DBText lineBelowDes in linesBelowDesignations)
                                                                {
                                                                    if (prefixString[prefixString.Length - 1] != ',')
                                                                    {
                                                                        prefixString.Append(String.Concat(", ", lineBelowDes.TextString.Trim()));
                                                                        continue;
                                                                    }
                                                                    if (prefixString[prefixString.Length - 1] == ',')
                                                                    {
                                                                        prefixString.Append(String.Concat(" ", lineBelowDes.TextString.Trim()));
                                                                        continue;
                                                                    }
                                                                }

                                                                // Delete trailing comma if it exists
                                                                if (prefixString[prefixString.Length - 1] == ',')
                                                                {
                                                                    prefixString.Length--;
                                                                }
                                                                // TODO ?
                                                                continue;
                                                            }

                                                            miscTexts.Add(dbt);
                                                        }

                                                        if (ent.GetType() == typeof(BlockReference))
                                                        {
                                                            BlockReference br = acTrans.GetObject(oidbtr, OpenMode.ForRead) as BlockReference;

                                                            if (br.Name.Contains("PRENOTE"))
                                                            {
                                                                _Logger.Log("DWG: " + dwgNameExt + ": layer: " + LayerIdToLayerName[br.LayerId] + ": " + "block reference prefix note found");
                                                            }
                                                            if (br.Name.Contains("HCRDTBL"))
                                                            {
                                                                cards.Add(br);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        xmlW.WriteStartElement("layer");
                                        xmlW.WriteAttributeString("text", ltr.Name);

                                        if (prefixString.Length > 0)
                                        {
                                            xmlW.WriteAttributeString("refdes_prefix", prefixString.ToString());
                                        }

                                        foreach (BlockReference br in cards)
                                        {
                                            Autodesk.AutoCAD.DatabaseServices.AttributeCollection attCol = br.AttributeCollection;

                                            AttributeReference attRefRefDes = acTrans.GetObject(br.AttributeCollection[0], OpenMode.ForRead) as AttributeReference;
                                            AttributeReference attRefItem   = acTrans.GetObject(br.AttributeCollection[1], OpenMode.ForRead) as AttributeReference;

                                            xmlW.WriteStartElement("callout");
                                            xmlW.WriteAttributeString("text", (String.IsNullOrWhiteSpace(attRefItem.TextString)) ? "no_itemno_for_card_slot" : attRefItem.TextString);
                                            xmlW.writeOutAttRefMinMax(attRefItem);

                                            xmlW.WriteStartElement("refdes");
                                            xmlW.WriteAttributeString("text", attRefRefDes.TextString);
                                            xmlW.writeOutAttRefMinMax(attRefRefDes);
                                            xmlW.WriteEndElement();

                                            xmlW.WriteEndElement();
                                        }
                                        foreach (DBText viewLetter in viewLetters)
                                        {
                                            TextEntity tent = new TextEntity(viewLetter);
                                            xmlW.WriteStartElement("view_letter");
                                            xmlW.WriteAttributeString("text", tent.text);
                                            xmlW.writeOutMinMax(tent, _Logger);
                                            xmlW.WriteEndElement();
                                        }

                                        foreach (DBText msNo in msNos)
                                        {
                                            TextEntity tent = new TextEntity(msNo);
                                            xmlW.WriteStartElement("msno");
                                            xmlW.WriteAttributeString("text", tent.text);
                                            xmlW.writeOutMinMax(tent, _Logger);
                                            xmlW.WriteEndElement();
                                        }

                                        foreach (DBText callout in callouts)
                                        {
                                            TextEntity tent = new TextEntity(callout);
                                            xmlW.WriteStartElement("callout");
                                            xmlW.writeOutMinMax(tent, _Logger);
                                            List <DBText> refDess = new List <DBText>();
                                            refDess = ToEach.toEachDBText(db,
                                                                          acTrans,
                                                                          delegate(DBText possibleRefDes)
                                            {
                                                const System.Double yRange = .15;
                                                const System.Double xRange = .15;

                                                return(possibleRefDes.Id != callout.Id &&
                                                       possibleRefDes.LayerId == callout.LayerId &&
                                                       refDesRegex.IsMatch(possibleRefDes.TextString.ToUpper().Trim()) &&
                                                       //!possibleRefDes.TextString.Contains(",") &&
                                                       //!possibleRefDes.TextString.Contains("-") &&
                                                       (possibleRefDes.IsAbove(callout, .1135 /*.5*/) ||
                                                        possibleRefDes.IsInRect(callout.AlignmentPoint.X - xRange,
                                                                                callout.AlignmentPoint.Y,
                                                                                callout.AlignmentPoint.X,
                                                                                callout.AlignmentPoint.Y + yRange) ||
                                                        possibleRefDes.IsInRect(callout.AlignmentPoint.X,
                                                                                callout.AlignmentPoint.Y,
                                                                                callout.AlignmentPoint.X + xRange,
                                                                                callout.AlignmentPoint.Y + yRange)) &&
                                                       !callout.IsRefDesBetween(possibleRefDes, acTrans, db)
                                                       );
                                            });
                                            if (refDess.Count > 1)
                                            {
                                                if (callout.Justify != AttachmentPoint.MiddleCenter)
                                                {
                                                    _Logger.Log("DWG: " +
                                                                dwgNameExt +
                                                                " layer: " +
                                                                LayerIdToLayerName[tent.dbText.LayerId] +
                                                                " callout: " +
                                                                tent.text +
                                                                " has an alignment point that isn't middle center" +
                                                                " (" +
                                                                tent.dbText.Position.X.truncstring(3) +
                                                                ", " +
                                                                tent.dbText.Position.Y.truncstring(3) +
                                                                ") ");
                                                }
                                                else
                                                {
                                                    _Logger.Log("DWG: " +
                                                                dwgNameExt +
                                                                " layer: " +
                                                                LayerIdToLayerName[tent.dbText.LayerId] +
                                                                " has more than one refdes for callout: " +
                                                                tent.text +
                                                                " (" +
                                                                tent.dbText.Position.X.truncstring(3) +
                                                                ", " +
                                                                tent.dbText.Position.Y.truncstring(3) +
                                                                ") "); //tent.dbText.Layer);
                                                }
                                            }

                                            xmlW.WriteAttributeString("text", tent.text);

                                            foreach (DBText refdes in refDess)
                                            {
                                                TextEntity tentRefDes = new TextEntity(refdes);
                                                xmlW.WriteStartElement("refdes");
                                                xmlW.WriteAttributeString("text", tentRefDes.text);
                                                xmlW.writeOutMinMax(tentRefDes, _Logger);
                                                xmlW.WriteEndElement();
                                            }
                                            xmlW.WriteEndElement();
                                        }
                                        foreach (DBText otherText in miscTexts)
                                        {
                                            if (!linesBelowDesignations.Contains(otherText))
                                            {
                                                TextEntity tent = new TextEntity(otherText);
                                                xmlW.WriteStartElement("other_text");
                                                xmlW.WriteAttributeString("text", tent.text);
                                                xmlW.writeOutMinMax(tent, _Logger);
                                                xmlW.WriteEndElement();
                                            }
                                        }
                                        xmlW.WriteEndElement();
                                    }
                                }
                            }
                        }
                        catch (System.Exception se)
                        {
                            _Logger.Log("DWG: " + dwgNameExt + ": processing error of type: " + se.GetType().ToString() + " : " + se.Message);
                        }
                        finally
                        {
                            xmlW.WriteEndElement();
                            xmlW.WriteRaw(Environment.NewLine);
                            xmlW.WriteEndDocument();
                            xmlW.Flush();
                            xmlW.Close();
                        }
                        acTrans.Commit();
                    }
                }
            }

            AfterProcessing();

            return(String.Concat(DwgCounter.ToString(),
                                 " out of ",
                                 NumDwgs,
                                 " DWGs processed in ",
                                 TimePassed,
                                 ". ",
                                 (_Logger.ErrorCount > 0) ? ("Error Log: " + _Logger.Path) : ("No errors found.")));
        }
Exemple #6
0
        public static List <string> GetBlockRefSelected(string brefName)
        {
            List <string> newList = new List <string>();
            Document      doc     = AcAp.DocumentManager.MdiActiveDocument;
            Database      db      = doc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
                foreach (ObjectId objId in bt)
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[brefName], OpenMode.ForRead);
                    if (btr.IsAnonymous)
                    {
                        continue;
                    }
                    if (btr.GetBlockReferenceIds(true, false).Count > 0)
                    {
                        if (btr.HasAttributeDefinitions)
                        {
                            ObjectIdCollection objIds = btr.GetBlockReferenceIds(true, false);
                            foreach (ObjectId brefId in objIds)
                            {
                                BlockReference bRef = (BlockReference)tr.GetObject(brefId, OpenMode.ForRead);
                                Autodesk.AutoCAD.DatabaseServices.AttributeCollection atRefColl = bRef.AttributeCollection;
                                foreach (ObjectId atId in atRefColl)
                                {
                                    AttributeReference atdef = (AttributeReference)tr.GetObject(atId, OpenMode.ForRead);
                                    newList.Add(atdef.Tag);
                                }
                            }
                        }
                    }
                }
            }
            return(newList);
        }