Exemplo n.º 1
0
        getDrawing(string pathDwg)
        {
            Document     acadDoc;
            bool         fileExists = FileSystem.FileExists(pathDwg);
            DialogResult pr;

            var names = BaseObjs._acadDocsList;

            if (fileExists)
            {
                if (names.Contains(Path.GetFileName(pathDwg)))
                {
                    foreach (Document doc in BaseObjs._acadDocs)
                    {
                        if (doc.Name == Path.GetFileName(pathDwg))
                        {
                            BaseObjs._acadDocs.MdiActiveDocument = doc;
                            break;
                        }
                    }
                }
                else
                {
                    pr = MessageBox.Show(string.Format("{0} {1} .dwg exists - Open Y/N?: ", JN, TOP), "", MessageBoxButtons.YesNo);
                    if (pr == DialogResult.Yes)
                    {
                        acadDoc = DocumentCollectionExtension.Open(BaseObjs._acadDocs, pathDwg, false);
                    }
                    else
                    {
                        return;
                    }
                }
            }
            else
            {
                acadDoc = DocumentCollectionExtension.Add(BaseObjs._acadDocs, TemplateTOP);
                acadDoc.saveAsDoc(pathDwg);
                Application.DocumentManager.MdiActiveDocument = acadDoc;
            }

            myUtility.CreateSurveyProject(JN);

            bool exists;

            using (BaseObjs._acadDoc.LockDocument())
            {
                ObjectId idDictPPF2 = Dict.getNamedDictionary("PPF2", out exists);

                if (exists)
                {
                    Dict.deleteXRec(idDictPPF2, "strTOP");
                }

                TypedValue[] tvs = new TypedValue[4];
                tvs.SetValue(new TypedValue(1000, JN), 0);
                tvs.SetValue(new TypedValue(1000, TOP), 1);
                tvs.SetValue(new TypedValue(1000, TXTFILE), 2);
                tvs.SetValue(new TypedValue(1000, string.Format("{0}{1}{2}_mod.txt", Path.GetDirectoryName(TXTFILE), @"\", Path.GetFileNameWithoutExtension(TXTFILE))), 3);
                ResultBuffer rb = new ResultBuffer(tvs);

                Dict.addXRec(idDictPPF2, "strTOP", rb);
            }
        }
Exemplo n.º 2
0
        transferObjects(List <ObjectId> idPolys3d, string dwgTemplate, string type, string namePntFile = null)
        {
            List <polyInfo> pInfo  = new List <polyInfo>();
            List <string>   layers = new List <string>();

            foreach (ObjectId idPoly3d in idPolys3d)
            {
                string   nameLayer = idPoly3d.getLayer();
                polyInfo p         = new polyInfo(p.pnts3d = idPoly3d.getCoordinates3d(), p.layer = nameLayer);
                layers.Add(nameLayer);
                if (!layers.Contains(nameLayer))
                {
                    Layer.manageLayers(nameLayer);
                }
            }

            Document acadDocX = BaseObjs._acadDoc;
            Document acadDocT = null;

            string pathX = Path.GetDirectoryName(acadDocX.Database.Filename);
            string nameX = Path.GetFileName(acadDocX.Database.Filename);

            string nameT = string.Format("{0}{1}{2}{3}.dwg", pathX, @"\", nameX.Substring(0, 4), type);

            if (File.Exists(nameT))
            {
                List <string> names = new List <string>();           //check to see if user has it open

                foreach (Document doc in BaseObjs._acadDocs)
                {
                    names.Add(Path.GetFileName(doc.Name));
                }

                if (names.Contains(Path.GetFileName(nameT)))
                {
                    foreach (Document doc in BaseObjs._acadDocs)
                    {
                        if (doc.Name == Path.GetFileName(nameT))
                        {
                            acadDocT = doc;
                            BaseObjs._acadDocs.MdiActiveDocument = acadDocT;
                            break;
                        }
                    }
                }
                else
                {
                    string nameDWL = string.Format("{0}{1}{2}.dwl", pathX, @"\", Path.GetFileNameWithoutExtension(nameX));
                    if (File.Exists(nameDWL))
                    {
                        StreamReader sr   = new StreamReader(nameDWL);
                        string       user = sr.ReadLine();
                        sr.Close();
                        string message = string.Format("{0} has {1}open. Select OK to Proceed when the file is available", user, nameT);
                        var    result  = MessageBox.Show(message, string.Format("{0} is open.", nameT), MessageBoxButtons.YesNo);
                        if (result == DialogResult.Yes)
                        {
                            acadDocT = DocumentCollectionExtension.Open(BaseObjs._acadDocs, nameT, false);
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        acadDocT = DocumentCollectionExtension.Open(BaseObjs._acadDocs, nameT, false);
                    }
                }
            }
            else
            {
                acadDocT = DocumentCollectionExtension.Add(BaseObjs._acadDocs, dwgTemplate);
                acadDocT.save();

                //BaseObjs.sendCommand(System.Convert.ToString(27));
                //BaseObjs.sendCommand("filedia\r0\r");
                //BaseObjs.sendCommand(string.Format("saveas\r2013\r{0}\r", nameT));
                //BaseObjs.sendCommand("filedia\r1\r");
            }

            if (type == "TOPO")
            {
                if (idPolys3d.Count > 0)
                {
                    foreach (polyInfo p in pInfo)
                    {
                        p.pnts3d.addPoly3d(p.layer);
                    }
                }

                if (namePntFile != null)
                {
                    transferPoints("Import", namePntFile, BaseObjsCom.aeccSurvDoc);
                }
            }
            else if (type == "CONT")
            {
                if (idPolys3d.Count > 0)
                {
                    foreach (polyInfo p in pInfo)
                    {
                        p.pnts3d.addPoly3d(p.layer);
                    }
                }

                if (namePntFile != null)
                {
                    transferPoints("Import", namePntFile, BaseObjsCom.aeccSurvDoc);
                }
            }
        }
Exemplo n.º 3
0
        private void cmdSetup_Click(object sender, RoutedEventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            fbd.Description = "Browse to Project Folder";
            fbd.ShowDialog();

            string strPath = fbd.SelectedPath;

            int intPosX = 1, intPos = 0;

            if (strPath == "")
            {
                System.Windows.MessageBox.Show("No Folder Selected");
                return;
            }
            else
            {
                while (intPosX != 0)
                {
                    intPos  = intPosX + 1;
                    intPosX = (short)(strPath.IndexOf("\\", intPos - 1) + 1);
                }
            }

            string strJN = strPath.Substring(intPos - 1);

            strPath = string.Format("{0}\\{1}EW.dwg", strPath, strJN);

            if (FileSystem.FileExists(strPath))
            {
                MessageBoxResult varResponse = System.Windows.MessageBox.Show(string.Format("File {0} exists! Make Backup??", strPath), "File Exists!", MessageBoxButton.YesNoCancel);

                if (varResponse == MessageBoxResult.Yes)
                {
                    FileInfo fileInfo;

                    fileInfo = FileSystem.GetFileInfo(strPath);

                    string strDateCreated = (fileInfo.LastAccessTime).ToString();
                    intPos         = (short)(strDateCreated.IndexOf(" ") + 1);
                    strDateCreated = strDateCreated.Substring(0, intPos - 1);
                    strDateCreated = strDateCreated.Replace("/", "_");
                    intPos         = strPath.IndexOf(".");

                    FileSystem.CopyFile(strPath, string.Format("{0}_{1}.dwg", strPath.Substring(0, intPos - 1), strDateCreated));
                    FileSystem.DeleteFile(strPath);
                }
                else if (varResponse == MessageBoxResult.No)
                {
                    FileSystem.DeleteFile(strPath);
                }
                else if (varResponse == MessageBoxResult.Cancel)
                {
                    return;
                }
            }

            using (BaseObjs._acadDoc.LockDocument()) {
                Document objDwgEW = DocumentCollectionExtension.Add(BaseObjs._acadDocs, @"R:\TSET\Template\CIVIL3D2015\EW.dwt");
                BaseObjs._acadDoc.Database.SaveAs(strPath, true, DwgVersion.Current, BaseObjs._acadDoc.Database.SecurityParameters);
            }

            using (BaseObjs._acadDoc.LockDocument()) {
                xRef.doMXR();
            }
            Point3d pnt3dUR = BaseObjs._acadDoc.Database.Extmax;

            SelectionSet objSSet = EW_Utility1.buildSSetTable();

            ObjectId[] ids = objSSet.GetObjectIds();
            if (ids == null || ids.Length == 0)
            {
                return;
            }

            Table tbl = null;

            using (BaseObjs._acadDoc.LockDocument()) {
                ObjectId id = ids[0];
                try {
                    using (Transaction tr = BaseObjs.startTransactionDb()) {
                        tbl = (Table)tr.GetObject(id, OpenMode.ForWrite);
                        Extents3d ext3d = (Extents3d)tbl.Bounds;
                        tbl.TransformBy(Matrix3d.Displacement(new Vector3d(pnt3dUR.X, pnt3dUR.Y, 0)));

                        objSSet = Base_Tools45.Select.buildSSet(typeof(Polyline), ext3d.MinPoint, ext3d.MaxPoint);
                        ids     = objSSet.GetObjectIds();
                        ObjectIdCollection idsm = new ObjectIdCollection();
                        foreach (ObjectId idm in ids)
                        {
                            idsm.Add(idm);
                        }
                        idsm.moveObjs(Point3d.Origin, pnt3dUR);

                        tr.Commit();
                    }
                }
                catch (System.Exception ex) {
                    BaseObjs.writeDebug(string.Format("{0} frmEarthwork.cs: line: 137", ex.Message));
                }

                Layer.manageLayers("0");

                string strDwgName = BaseObjs.docName;
                intPos     = strDwgName.IndexOf(".") + 1;
                strDwgName = strDwgName.Substring(0, intPos - 1);
                BlockReference blkRef;

                blkRef = xRef.getXRefBlockReference("CNTL");
                if (blkRef != null)
                {
                    string strBlkName = blkRef.Name;

                    BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rF\r{0}*\r\r", strBlkName), true, false, false);

                    BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|CURB\r\r", strBlkName), true, false, false);
                    BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|GB\r\r", strBlkName), true, false, false);
                    BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|BLDG\r\r", strBlkName), true, false, false);
                    BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|FL\r\r", strBlkName), true, false, false);
                    BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|FS\r\r", strBlkName), true, false, false);
                    BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|GUTTER\r\r", strBlkName), true, false, false);
                    BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|WALL\r\r", strBlkName), true, false, false);
                }

                blkRef = xRef.getXRefBlockReference("BNDRY");
                if (blkRef != null)
                {
                    string strBlkName = blkRef.Name;

                    BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rF\r{0}*\r\r", strBlkName), true, false, false);
                    BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|PL\r\r", strBlkName), true, false, false);
                }

                View.ZoomExtents();
            }
            System.Windows.Forms.MessageBox.Show("User needs to create data shortcut for Surfaces: CPNT-ON and EXIST");
        }