Example #1
0
        convertDictionaryLinksToXData()
        {
            try
            {
                BaseObjs.sendCommand("VBAUNLOAD\rC:\\TSET\\VBA2015\\CIVIL3D2015.DVB\r");
                //BaseObjs.sendCommand("(unloadCivil3d2015)\r");
            }
            catch (System.Exception ex)
            {
                Application.ShowAlertDialog(string.Format("{0} Convert_App.cs: line: 31", ex.Message));
                BaseObjs.writeDebug(string.Format("{0} Convert_App.cs: line: 31", ex.Message));
            }
            int k = 0;

            bool exists = false;

            ObjectId idBlock   = ObjectId.Null;
            ObjectId idLeader  = ObjectId.Null;
            ObjectId idText    = ObjectId.Null;
            ObjectId idPnt1    = ObjectId.Null;
            ObjectId idPnt2    = ObjectId.Null;
            ObjectId idAlign   = ObjectId.Null;
            ObjectId idSurface = ObjectId.Null;
            ObjectId idPoly    = ObjectId.Null;
            ObjectId idBubble  = ObjectId.Null;
            ObjectId idCwpRef  = ObjectId.Null;

            string topNum  = string.Empty;
            string topTxt  = string.Empty;
            string botNum  = string.Empty;
            string botTxt  = string.Empty;
            string nameCmd = string.Empty;
            string nameApp = string.Empty;
            string top     = string.Empty;
            string bot     = string.Empty;

            List <string> dicts = new List <string> {
                "GradeTagDict",
                "PtTagDict",
                "FlTagDict",
                "SEDTagDict",
                "MHTagDict",
                "XrGradeTagDict",
                "XrFlTagDict",
                "VBTagDict"
            };

            List <ObjectId> idsCgPnts = null;

            ResultBuffer rb = null;

            TypedValue[] tvs = null;

            List <Object> errorCallouts = new List <object>();

            foreach (string dict in dicts)
            {
                ObjectId idDict = Dict.getNamedDictionary(dict, out exists);
                List <DBDictionaryEntry> entries = idDict.getEntries();

                foreach (DBDictionaryEntry entry in entries)
                {
                    string shPnt1 = entry.Key;
                    Handle hPnt1  = new Handle(Int64.Parse(shPnt1, NumberStyles.AllowHexSpecifier));
                    idPnt1 = hPnt1.getObjectId();

                    rb = Dict.getXRec(idDict, hPnt1.ToString());
                    if (rb == null)
                    {
                        continue;
                    }
                    tvs     = rb.AsArray();
                    idBlock = tvs[0].Value.ToString().stringToHandle().getObjectId();
                    checkGroup(idBlock);

                    idLeader = tvs[1].Value.ToString().stringToHandle().getObjectId();

                    //if (idBlock.IsEffectivelyErased || idBlock.IsErased)
                    //{
                    if (idLeader.IsErased || idLeader.IsEffectivelyErased)
                    {
                        Dict.deleteXRec(idDict, hPnt1.ToString());
                        errorCallouts.Add(idPnt1.getCogoPntNumber());
                        continue;
                    }
                    //}

                    idsCgPnts = new List <ObjectId> {
                        idPnt1
                    };

                    Leader ldr = null;
                    using (Transaction tr = BaseObjs.startTransactionDb())
                    {
                        ldr            = (Leader)tr.GetObject(idLeader, OpenMode.ForWrite);
                        ldr.Annotative = AnnotativeStates.True;
                        tr.Commit();
                    }

                    idLeader.moveToTop();

                    topNum = Blocks.getBlockRefAttributeValue(idBlock, "TOPNUM");
                    topTxt = Blocks.getBlockRefAttributeValue(idBlock, "TOPTXT");
                    botNum = Blocks.getBlockRefAttributeValue(idBlock, "BOTNUM");
                    botTxt = Blocks.getBlockRefAttributeValue(idBlock, "BOTTXT");

                    switch (dict)
                    {
                    case "GradeTagDict":
                        nameCmd = "cmdG";
                        nameApp = "lnkC0";
                        break;

                    case "PtTagDict":
                        nameCmd = "cmdPT";
                        nameApp = "lnkC0";
                        break;

                    case "FlTagDict":
                        nameCmd = "cmdFL";
                        nameApp = "lnkC0";
                        break;

                    case "SEDTagDict":
                        nameCmd = "cmdSDE";
                        nameApp = "lnkC0";
                        idAlign = tvs[2].Value.ToString().stringToHandle().getObjectId();
                        break;

                    case "MHTagDict":
                        nameCmd   = "cmdMH";
                        nameApp   = "lnkC0";
                        idAlign   = tvs[2].Value.ToString().stringToHandle().getObjectId();
                        idSurface = tvs[3].Value.ToString().stringToHandle().getObjectId();
                        break;

                    case "XrGradeTagDict":
                        nameCmd   = "cmdSDE";
                        nameApp   = "lnkC0";
                        idAlign   = tvs[2].Value.ToString().stringToHandle().getObjectId();
                        idSurface = tvs[3].Value.ToString().stringToHandle().getObjectId();
                        break;

                    case "XrFlTagDict":
                        nameCmd   = "cmdSDE";
                        nameApp   = "lnkC0";
                        idAlign   = tvs[2].Value.ToString().stringToHandle().getObjectId();
                        idSurface = tvs[3].Value.ToString().stringToHandle().getObjectId();
                        break;

                    case "VBTagDict":
                        nameCmd   = "cmdVB";
                        nameApp   = "lnkC0";
                        idPoly    = tvs[1].Value.ToString().stringToHandle().getObjectId();
                        idSurface = tvs[2].Value.ToString().stringToHandle().getObjectId();
                        idBubble  = tvs[3].Value.ToString().stringToHandle().getObjectId();
                        idCwpRef  = tvs[4].Value.ToString().stringToHandle().getObjectId();
                        break;
                    }

                    top = string.Format("{0}{1}", topNum, topTxt);
                    bot = string.Format("{0}{1}", botNum, botTxt);
                    idBlock.delete();
                    Dict.deleteXRec(idDict, hPnt1.ToString());
                    if (topNum.Contains("(") && topNum.Contains(")"))
                    {
                        nameCmd = string.Format("{0}X", nameCmd);
                    }
                    double dZ = 0.0;
                    if (botNum != "")
                    {
                        if (botNum == "0\"")
                        {
                            nameCmd = "cmdCF0";
                            dZ      = 0;
                        }
                        else
                        {
                            dZ = double.Parse(topNum.ToString()) - double.Parse(botNum.ToString());
                        }
                    }

                    Txt.addLdrText(nameCmd, nameApp, ldr.ObjectId, idsCgPnts, top, bot, "", dZ, useBackgroundFill: true);
                    ++k;
                }
            }

            ObjectId idDictGS = Dict.getNamedDictionary("GSDict", out exists);
            List <DBDictionaryEntry> entriesGS = idDictGS.getEntries();
            ResultBuffer             rbGS      = null;

            TypedValue[] tvsGS = null;

            foreach (DBDictionaryEntry entryGS in entriesGS)
            {
                ObjectId idEntryGS = ObjectId.Null;
                string   shText    = entryGS.Key;
                Handle   hText     = new Handle(Int64.Parse(shText, NumberStyles.AllowHexSpecifier));
                idText = hText.getObjectId();
                rbGS   = Dict.getXRec(idDictGS, hText.ToString());
                if (rbGS == null)
                {
                    continue;
                }
                tvsGS    = rbGS.AsArray();
                idLeader = tvsGS[0].getObjectId();
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    DBText text = (DBText)tr.GetObject(idText, OpenMode.ForRead);
                    top = text.TextString;
                    bot = string.Empty;
                    Leader ldr = (Leader)tr.GetObject(idLeader, OpenMode.ForWrite);
                    ldr.Annotative = AnnotativeStates.True;
                    tr.Commit();
                }
                switch (top.Substring(0, 1))
                {
                case "(":
                    nameCmd = "cmdGSX";
                    break;

                case "R":
                    nameCmd = "cmdGS";
                    break;

                case "S":
                    nameCmd = "cmdSS";
                    break;

                default:
                    if (top.Contains("."))
                    {
                        nameCmd = "cmdGSS";
                    }
                    else
                    {
                        nameCmd = "cmdGS0";
                    }
                    break;
                }

                idsCgPnts = new List <ObjectId> {
                    tvsGS[1].getObjectId(),
                    tvsGS[2].getObjectId()
                };
                nameApp = apps.lnkGS;
                Dict.deleteXRec(idDictGS, hText.ToString());
                idText.delete();

                Txt.addLdrText(nameCmd, nameApp, idLeader, idsCgPnts, top, bot, useBackgroundFill: true);
                ++k;
                Debug.Print(string.Format("k:{0}", k));
            }

            tvs = new TypedValue[11];
            tvs.SetValue(new TypedValue((int)DxfCode.Start, "INSERT"), 0);
            tvs.SetValue(new TypedValue((int)DxfCode.Operator, "<OR"), 1);
            tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "GradeTag"), 2);
            tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "XrGradeTag"), 3);
            tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "FlTag"), 4);
            tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "XrFlTag"), 5);
            tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "PlxTag"), 6);
            tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "TcTag"), 7);
            tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "PtTag"), 8);
            tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "LabelTag"), 9);
            tvs.SetValue(new TypedValue((int)DxfCode.Operator, "OR>"), 10);

            SelectionSet ss = Select.buildSSet(tvs);

            if (ss != null && ss.Count > 0)
            {
                ObjectId[] ids = ss.GetObjectIds();
                Point3d    pnt3dIns;

                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    foreach (ObjectId id in ids)
                    {
                        BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                        pnt3dIns = br.Position;
                        List <ObjectId> idLdrs = Select.getEntityatPoint(pnt3dIns, typeof(Leader), "ARROW", 1.0);
                        if (idLdrs == null || idLdrs.Count == 0)
                        {
                            Debug.Print(string.Format("No Leader: {0},{1}", pnt3dIns.X, pnt3dIns.Y));
                            continue;
                        }
                        Point3d pnt3dLdrBeg = idLdrs[0].getBegPnt();

                        List <ObjectId> idCgPnts = Select.getEntityatPoint(pnt3dLdrBeg, typeof(CogoPoint), "CPNT-ON");
                        if (idCgPnts == null || idCgPnts.Count == 0)
                        {
                            Debug.Print(string.Format("No CogoPnt: {0},{1}", pnt3dLdrBeg.X, pnt3dLdrBeg.Y));
                        }

                        idLeader = idLdrs[0];
                        Leader ldr = (Leader)tr.GetObject(idLeader, OpenMode.ForWrite);
                        ldr.Annotative = AnnotativeStates.True;

                        idLeader.moveToTop();

                        string nameBlock = br.Name.ToUpper();

                        switch (nameBlock)
                        {
                        case "GRADETAG":
                        case "XRGRADETAG":
                            topNum  = Blocks.getBlockRefAttributeValue(id, "TOPNUM");
                            topTxt  = Blocks.getBlockRefAttributeValue(id, "TOPTXT");
                            botNum  = Blocks.getBlockRefAttributeValue(id, "BOTNUM");
                            botTxt  = Blocks.getBlockRefAttributeValue(id, "BOTTXT");
                            top     = string.Format("{0}{1}", topNum, topTxt);
                            bot     = string.Format("{0}{1}", botNum, botTxt);
                            nameCmd = "cmdG";
                            break;

                        case "FLTAG":
                        case "XRFLTAG":
                        case "PLXTAG":
                            top     = Blocks.getBlockRefAttributeValue(id, "TOPNUM");
                            bot     = Blocks.getBlockRefAttributeValue(id, "BOTTXT");
                            nameCmd = "cmdFL";
                            break;

                        case "TCTAG":
                        case "PTTAG":
                        case "LABELTAG":
                            top = Blocks.getBlockRefAttributeValue(id, "TOPLABEL");
                            bot = Blocks.getBlockRefAttributeValue(id, "BOTLABEL");
                            if (top == "DEEPEN")
                            {
                                nameCmd = "cmdDEP";
                            }
                            if (bot == "RISERS")
                            {
                                nameCmd = "cmdRISER";
                            }
                            break;
                        }

                        id.delete();

                        nameApp = apps.lnkCO;

                        if (top.Contains("(") && top.Contains(")"))
                        {
                            nameCmd = string.Format("{0}X", nameCmd);
                        }
                        double dZ = 0.0;
                        if (botNum != "")
                        {
                            if (botNum == "0\"")
                            {
                                nameCmd = "cmdCF0";
                                dZ      = 0;
                            }
                            else
                            {
                                dZ = double.Parse(topNum.ToString()) - double.Parse(botNum.ToString());
                            }
                        }

                        Txt.addLdrText(nameCmd, nameApp, idLeader, idsCgPnts, top, bot, "", dZ, useBackgroundFill: true);
                        ++k;
                    }
                    tr.Commit();
                }
            }

            Application.ShowAlertDialog(string.Format("{0} Callouts converted.  {1} Points with broken links", k.ToString(), errorCallouts.Count.ToString()));
            foreach (object pntNum in errorCallouts)
            {
                Debug.Print(pntNum.ToString());
            }

            BaseObjs.sendCommand("-VBALOAD\rC:\\TSET\\VBA2015\\CIVIL3D2015.DVB\r");
        }
Example #2
0
        public static void makeSurfaceSG()
        {
            //Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.Command("_ucs", "w", "");
            BaseObjs.sendCommand("_ucs\rw\r");
            TinSurface objSurfaceCPNT = Surf.getTinSurface("CPNT-ON", out exists);

            SelectionSet objSSet = null;

            if (pub.boolDebug)
            {
                objSSet = EW_Utility1.buildSSet1();                 //SelectOnScreen _XX-*
            }
            else
            {
                objSSet = EW_Utility1.buildSSet0();                 //get _XX-*
            }
            if (objSSet == null || objSSet.Count == 0)
            {
                return;
            }

            ObjectId[] ids = objSSet.GetObjectIds();

            timeBeg = DateTime.Now;

            ObjectId idPolyT = ObjectId.Null;

            for (int i = 0; i < ids.Length; i++)
            {
                Polyline objLWPline = (Polyline)ids[i].getEnt();

                ObjectId idLWPlineT = objLWPline.copy();
                if (idLWPlineT.IsNull)
                {
                    MessageBox.Show("Null Id @ line 131 EW_Main");
                    continue;
                }

                idLWPlineT.changeProp(LineWeight.LineWeight050, clr.yel);

                if (objLWPline.HasBulges)
                {
                    idPolyT = Conv.processBndry(idLWPlineT);                        //boundary with arcs converted to line segments
                    idLWPlineT.delete();
                }
                else
                {
                    Entity ent = idLWPlineT.getEnt();
                    idPolyT = ent.ObjectId;
                }

                //Entity entx = idPolyT.getEnt();
                //MessageBox.Show(entx.GetType().ToString());

                switch (objLWPline.Layer)
                {
                case "_XX-FLOOR SLAB_A":
                case "_XX-FLOOR SLAB_B":
                case "_XX-FLOOR SLAB_C":
                case "_XX-DOCK APRON":
                    color = clr.yel;
                    break;

                default:
                    color = clr.grn;
                    break;
                }

                ObjectId idLWPlineX = ObjectId.Null;
                if (!objLWPline.Layer.Contains("_XX-FLOOR"))
                {
                    idLWPlineX = idPolyT.offset(-0.05);
                    idPolyT.delete();
                }
                else
                {
                    idLWPlineX = idPolyT;
                }

                if (idLWPlineX.IsNull)
                {
                    MessageBox.Show("Null Id @ line 162 EW_Main" + idPolyT.getHandle().ToString());
                    continue;
                }

                idLWPlineX.changeProp(LineWeight.LineWeight060, color);


                if (!offsetSegments("CPNT-ON", "SG", idLWPlineX, objLWPline.Layer))
                {
                    return;
                }
            }

            viewResults("SG", true);
        }
Example #3
0
        doCadOUT(string cmdName)
        {
            Object pickf = null;

            try
            {
                Document doc = BaseObjs._acadDoc;
                doc.save();
                pickf = Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("PICKFIRST");

                Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("PICKFIRST", 1);
                Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("FILEDIA", 0);

                BaseObjs.sendCommand("plan w\r");

                DateTime dt = DateTime.Now;

                string path0   = BaseObjs.docFullName;
                string nameDwg = Path.GetFileName(path0);

                if (nameDwg.Substring(0, 1) == "$")
                {
                    DialogResult dr = MessageBox.Show("Temporary file is active.  Proceed?", "CADOUT", MessageBoxButtons.YesNo);
                    if (dr == DialogResult.No)
                    {
                        return;
                    }
                }
                string nameDir = Path.GetDirectoryName(path0);

                int numJob = int.Parse(BaseObjs.jobNumber(nameDwg));

                string path1 = "", path2 = "", path3 = "";

                if (nameDir.Substring(0, 1) == "N")
                {
                    if (numJob > 2599 && numJob < 2700)
                    {
                        path1 = string.Format("{0}\\EMAILOUT", path0.Substring(0, 17));
                        path2 = string.Format("{0}\\EMAIL-OUT", path1.Substring(0, 17));
                        path3 = string.Format("{0}\\EMAIL OUT", path1.Substring(0, 17));
                    }
                    else
                    {
                        path1 = string.Format("{0}\\EMAILOUT", path0.Substring(0, 7));
                        path2 = string.Format("{0}\\EMAIL-OUT", path1.Substring(0, 7));
                        path3 = string.Format("{0}\\EMAIL OUT", path1.Substring(0, 7));
                    }
                }
                else if (path0.Substring(0, 1) == "O")
                {
                    path1 = string.Format("{0}\\EMAILOUT", path0.Substring(0, 17));
                    path2 = string.Format("{0}\\EMAIL-OUT", path1.Substring(0, 17));
                    path3 = string.Format("{0}\\EMAIL OUT", path1.Substring(0, 17));
                }
                else
                {
                    path1 = string.Format("{0}\\EMAILOUT", path0.Substring(0, 7));
                    path2 = string.Format("{0}\\EMAIL-OUT", path1.Substring(0, 7));
                    path3 = string.Format("{0}\\EMAIL OUT", path1.Substring(0, 7));
                }

                bool fldr1 = Directory.Exists(path1);
                bool fldr2 = Directory.Exists(path2);
                bool fldr3 = Directory.Exists(path3);

                string nameTmp = "";
                string nameOut = "";
                string date    = string.Format("{0}-{1:00}-{2:00}", dt.Year, dt.Month, dt.Day);

                if (fldr1)
                {
                    if (!Directory.Exists(path1 + "\\" + date))
                    {
                        Directory.CreateDirectory(path1 + "\\" + date);
                    }

                    nameTmp = path1 + "\\" + date + "\\$" + nameDwg;
                    nameOut = path1 + "\\" + date + "\\" + nameDwg.Substring(0, nameDwg.Length - 4) + "_out.dwg";
                }
                else if (fldr2)
                {
                    if (!Directory.Exists(path2 + "\\" + date))
                    {
                        Directory.CreateDirectory(path2 + "\\" + date);
                    }
                    nameTmp = path2 + "\\" + date + "\\$" + nameDwg;
                    nameOut = path2 + "\\" + date + "\\" + nameDwg.Substring(0, nameDwg.Length - 4) + "_out.dwg";
                }
                else if (fldr3)
                {
                    if (!Directory.Exists(path3 + "\\" + date))
                    {
                        Directory.CreateDirectory(path3 + "\\" + date);
                    }
                    nameTmp = path3 + "\\" + date + "\\$" + nameDwg;
                    nameOut = path3 + "\\" + date + "\\" + nameDwg.Substring(0, nameDwg.Length - 4) + "_out.dwg";
                }
                else
                {
                    Directory.CreateDirectory(path1 + "\\" + date);
                    nameTmp = path1 + "\\" + date + "\\$" + nameDwg;
                    nameOut = path1 + "\\" + date + "\\" + nameDwg.Substring(0, nameDwg.Length - 4) + "_out.dwg";
                }

                bool fileExists = File.Exists(nameTmp);

                if (fileExists)                 //file exists - so delete and saveas
                {
                    File.Delete(nameTmp);
                    doc.saveas(nameTmp);
                }
                else                 //folder exists; file doesn't exist
                {
                    doc.saveas(nameTmp);
                }

                //-------------------------------------------------------------------------------------------

                Dict.deleteDictionary("SearchDict");
                Dict.deleteDictionary("ObjectDict");

                if (cmdName == "cmdCOUT")
                {
                    doCleanup1();
                }
                if (cmdName == "cmdCOUTX")
                {
                    doCleanup2();
                }

                fileExists = File.Exists(nameOut);

                if (fileExists)                 //file exists - so delete and saveas
                {
                    File.Delete(nameOut);
                    doc.saveas(nameOut);
                }
                else                 //folder exists; file doesn't exist
                {
                    doc.saveas(nameOut);
                }

                File.Delete(nameTmp);

                MessageBox.Show(string.Format("File created at: {0}", nameOut), "FILE CREATED", MessageBoxButtons.OK);
            }
            catch (System.Exception ex)     {
                BaseObjs.writeDebug(string.Format("{0} CadOUT.cs: line: 180", ex.Message));
            }
            finally {
                Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("PICKFIRST", pickf);
                Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("FILEDIA", 1);
            }
        }