/// <summary> /// Saves a snapshot of the current SprApplication main view to the MDB database. /// </summary> /// <param name="snapShot">The snapshot format the image will be created with.</param> /// <param name="zoomToTag">Determines if the main view zooms to the tag in the main SmartPlant screen.</param> public void TakeSnapshot(bool zoomToTag, SprSnapShot snapShot = null) { if (!Row.Table.Columns.Contains("tag_image")) { Application.Tags.AddDataField("tag_image", "OLEOBJECT"); var oldVals = Row.ItemArray; Refresh(); Row.ItemArray = oldVals; } if (zoomToTag) { Goto(); } var snap = snapShot ?? Application.DefaultSnapshot; var tempName = string.Format("dbImage_tag_{0}", Id); var ms = new MemoryStream(); _image = Application.TakeSnapshot(tempName, SprSnapShot.TempDirectory, snap); _image.Save(ms, _image.RawFormat); Row["tag_image"] = ms.ToArray(); ms.Dispose(); Update(); }
/// <summary> /// Captures the active SmartPlant Reviews session main view and /// writes it an image of the given filename and format. /// </summary> /// <param name="snapShot">SprSnapshot containing the snapshot settings.</param> /// <param name="imageName">Name of the final output image.</param> /// <param name="outputDir">Directory to save the snapshot to.</param> /// <returns></returns> public Image TakeSnapshot(string imageName, string outputDir, SprSnapShot snapShot = null) { if (!IsConnected) throw SprExceptions.SprNotConnected; // Get the default snapshot if none was supplied var snap = snapShot ?? DefaultSnapshot; // Turn off Fly-To behaviors (if supported) var vers = int.Parse(Version.Substring(0, 2)); if (vers >= 9) { SprStatus = DrApi.NameValueSet("Motion-Fly-To", false); if (SprStatus != 0) throw SprException; } // Get the current backface/endcap settings var orgBackfaces = GlobalOptionsGet(SprConstants.SprGlobalBackfacesDisplay); var orgEndcaps = GlobalOptionsGet(SprConstants.SprGlobalEndcapsDisplay); // Turn on view backfaces/endcaps as needed if (orgBackfaces == 0) GlobalOptionsSet(SprConstants.SprGlobalBackfacesDisplay, 1); if (orgEndcaps == 0) GlobalOptionsSet(SprConstants.SprGlobalEndcapsDisplay, 1); // (.BMP is forced before conversions) var imgPath = Path.Combine(outputDir, string.Format("{0}.bmp", imageName)); if (File.Exists(imgPath)) File.Delete(imgPath); // Take the snapshot SprStatus = DrApi.SnapShot(imgPath, snap.Flags, snap.DrSnapShot, 0); if (SprStatus != 0) throw SprException; // Wait until finished while (IsBusy) Thread.Sleep(100); // Reset the original settings if applicable if (orgBackfaces == 0) GlobalOptionsSet(SprConstants.SprGlobalBackfacesDisplay, 1); if (orgEndcaps == 0) GlobalOptionsSet(SprConstants.SprGlobalEndcapsDisplay, 1); // Return false if the snapshot doesn't exist if (!File.Exists(imgPath)) return null; // Format the snapshot if required if (snap.OutputFormat != SprSnapshotFormat.Bmp) return SprSnapShot.FormatSnapshot(imgPath, snap.OutputFormat); return Image.FromFile(imgPath); }
/// <summary> /// Connects to a running instance of SmartPlant Review. /// </summary> /// <returns>Boolean indicating success or failure of the operation.</returns> public bool Connect() { DrApi = Activator.CreateInstance(SprImportedTypes.DrApi); if (DrApi == null) return false; try { // Set the startup fields _version = GetVersion(); _mdbPath = GetMdbPath(); _mdbDatabase = GetMdbDatabase(); _sessionName = GetSessionName(); //_nextTag = GetNextTag(); _nextAnnotation = GetNextAnnotation(); _processId = GetProcessId(); _designFiles = GetDesignFiles(); // Windows Windows = new SprApplicationWindows(this); // DbObjects _annotations = new SprAnnotationCollection(this); _tags = new SprTagCollection(this); // Create the default snapshot format DefaultSnapshot = new SprSnapShot { AntiAlias = 3, OutputFormat = SprSnapshotFormat.Jpg, AspectOn = true, Scale = 1 }; // Set the default snapshot directories SprSnapShot.TempDirectory = Environment.GetEnvironmentVariable("TEMP"); SprSnapShot.DefaultDirectory = Environment.SpecialFolder.MyPictures.ToString(); SprStatus = 0; } catch { return false; } return IsConnected; }
/// <summary> /// Saves a snapshot of the current SprApplication main view to the MDB database. /// </summary> /// <param name="snapShot">The snapshot format the image will be created with.</param> /// <param name="zoomToTag">Determines if the main view zooms to the tag in the main SmartPlant screen.</param> public void TakeSnapshot(bool zoomToTag, SprSnapShot snapShot = null) { if (!Row.Table.Columns.Contains("tag_image")) { Application.Tags.AddDataField("tag_image", "OLEOBJECT"); var oldVals = Row.ItemArray; Refresh(); Row.ItemArray = oldVals; } if (zoomToTag) Goto(); var snap = snapShot ?? Application.DefaultSnapshot; var tempName = string.Format("dbImage_tag_{0}", Id); var ms = new MemoryStream(); _image = Application.TakeSnapshot(tempName, SprSnapShot.TempDirectory, snap); _image.Save(ms, _image.RawFormat); Row["tag_image"] = ms.ToArray(); ms.Dispose(); Update(); }