public bool DeleteService() { try { base.StopReactors(); base.StopReactors(); } catch { } Database database = base.ParentDataset.ParentDocument.Database; Document parentDocument = base.ParentDataset.ParentDocument; Editor editor = base.ParentDataset.ParentDocument.Editor; bool result; try { using (base.ParentDataset.ParentDocument.LockDocument((DocumentLockMode)20, null, null, false)) { using (Transaction transaction = parentDocument.TransactionManager.StartTransaction()) { RasterImage rasterImage = (RasterImage)transaction.GetObject(base.RasterObjectId, (OpenMode)1); rasterImage.DisableUndoRecording(true); ObjectId imageDefId = rasterImage.ImageDefId; RasterImageDef rasterImageDef = (RasterImageDef)transaction.GetObject(imageDefId, (OpenMode)1); rasterImageDef.DisableUndoRecording(true); if (rasterImageDef.IsLoaded) { rasterImageDef.Unload(true); } try { File.Delete(rasterImageDef.SourceFileName); if (App.TempFiles.Contains(rasterImageDef.SourceFileName)) { App.TempFiles.Remove(rasterImageDef.SourceFileName); } } catch { } if (!rasterImageDef.IsErased) { rasterImageDef.Erase(); } ObjectId imageDictionary = RasterImageDef.GetImageDictionary(database); DBDictionary dBDictionary = (DBDictionary)transaction.GetObject(imageDictionary, (OpenMode)1); dBDictionary.Remove(imageDefId); dBDictionary.Contains(imageDefId); if (!rasterImage.IsErased) { rasterImage.Erase(false); } this.RemoveDictionary(database, transaction); parentDocument.TransactionManager.QueueForGraphicsFlush(); parentDocument.TransactionManager.FlushGraphics(); parentDocument.Editor.UpdateScreen(); transaction.Commit(); base.ParentDataset.ImageServices.Remove(base.Name); editor.Regen(); MSCDataset.SetDefaultActiveRasterServices(); result = true; } } } catch { MessageBox.Show("DEBUG: Catch in MSCMapService.DeleteService"); result = false; } return(result); }
private bool UpdateRasterImage(Document doc, ObjectId rasterId, string url, Point3d basePoint, Vector3d v1, Vector3d v2) { bool result; try { if (doc == null) { result = false; } else { if (doc.IsDisposed) { result = false; } else { if (rasterId.IsEffectivelyErased) { result = false; } else { if (rasterId == ObjectId.Null) { result = false; } else { Database arg_4D_0 = doc.Database; try { Editor arg_54_0 = doc.Editor; ; using (doc.LockDocument(DocumentLockMode.Write, null, null, false)) { doc.TransactionManager.EnableGraphicsFlush(true); Autodesk.AutoCAD.ApplicationServices.TransactionManager transactionManager = doc.TransactionManager; using (Transaction transaction = transactionManager.StartTransaction()) { RasterImage rasterImage = (RasterImage)transaction.GetObject(rasterId, OpenMode.ForWrite); rasterImage.DisableUndoRecording(true); ObjectId imageDefId = rasterImage.ImageDefId; RasterImageDef rasterImageDef = (RasterImageDef)transaction.GetObject(imageDefId, OpenMode.ForWrite); rasterImageDef.DisableUndoRecording(true); string sourceFileName = rasterImageDef.SourceFileName; try { rasterImageDef.Unload(true); rasterImageDef.SourceFileName = url; rasterImageDef.Load(); if (rasterImageDef.IsLoaded) { try { if (!string.IsNullOrEmpty(sourceFileName)) { System.IO.File.Delete(sourceFileName); } } catch { } } //rasterImage.Orientation = new CoordinateSystem3d(basePoint, v1, v2); rasterImage.Draw(); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); } try { rasterImageDef.UpdateEntities(); doc.TransactionManager.QueueForGraphicsFlush(); doc.TransactionManager.FlushGraphics(); doc.Editor.UpdateScreen(); } catch { } transaction.Commit(); } } result = true; } catch (System.Exception) { result = false; } } } } } } catch { result = false; } return(result); }
public void UpdateAerial() { Document doc = Application.DocumentManager.MdiActiveDocument; if (doc == null) { return; } Editor ed = doc.Editor; // Select an aerial entity to update PromptEntityResult entityResult = ed.GetEntity("Pick an aerial to update : "); if (entityResult.Status == PromptStatus.OK) { // Create a new transaction to contain the update Transaction tx = doc.TransactionManager.StartTransaction(); try { // Get the aerial entity object and try to read its extension dictionary RasterImage aerialEnt = tx.GetObject(entityResult.ObjectId, OpenMode.ForRead) as RasterImage; if (aerialEnt.ExtensionDictionary.IsNull) { throw new Exception(ErrorStatus.InvalidInput, "Unrecognized aerial image."); } // Get the extension dictionary object DBDictionary extDict = tx.GetObject(aerialEnt.ExtensionDictionary, OpenMode.ForRead) as DBDictionary; if (!extDict.Contains("ImageData")) { throw new Exception(ErrorStatus.InvalidInput, "Unrecognized aerial image."); } // Get the associated image data ObjectId boundsEntryId = extDict.GetAt("ImageData"); Xrecord boundsRecord = tx.GetObject(boundsEntryId, OpenMode.ForRead) as Xrecord; TypedValue[] resBuff = boundsRecord.Data.AsArray(); GeoPoint center = new GeoPoint((resBuff[0].Value as double?).Value, (resBuff[1].Value as double?).Value); GeoPoint neCorner = new GeoPoint((resBuff[2].Value as double?).Value, (resBuff[3].Value as double?).Value); GeoPoint swCorner = new GeoPoint((resBuff[4].Value as double?).Value, (resBuff[5].Value as double?).Value); int zoom = (resBuff[6].Value as int?).Value; int mapTypeInt = (resBuff[7].Value as int?).Value; int mapSourceInt = (resBuff[8].Value as int?).Value; MapType mapType = (MapType)mapTypeInt; AerialRepository repository; if (mapSourceInt == 0) { repository = new BingAerialRepository(); } else { repository = new GoogleMapsAerialRepository(); } // Get the current filename using the aerial's RasterImageDef ObjectId aerialImgDefId = aerialEnt.ImageDefId; RasterImageDef aerialImgDef = tx.GetObject(aerialImgDefId, OpenMode.ForRead) as RasterImageDef; string filename = aerialImgDef.SourceFileName; // Get the image width and height int width = (int)aerialImgDef.Size.X; int height = (int)aerialImgDef.Size.Y; // Get the request details for the image downlaod AerialImageData imageData = new AerialImageData(center, neCorner, swCorner, width, height, zoom, mapType, filename); string requestUrl = repository.BuildImageRequestUrl(imageData, update: true); // Delete the current entity aerialImgDef.UpgradeOpen(); aerialImgDef.Unload(true); // Download the new aerial photo to replace the old AerialRepository.DownloadImage(requestUrl, filename); // Reload the image entity aerialImgDef.Load(); // Commit the transaction tx.Commit(); } catch (Exception ex) { ed.WriteMessage("Error updating aerial: " + ex.Message + '\n'); ed.WriteMessage("Please try again.\n"); } finally { tx.Dispose(); } } }