public void generateSnapshot(string folderIssue) { try { string snapshot = Path.Combine(folderIssue, "snapshot.png"); // get the state of COM ComApi.InwOpState10 oState = ComBridge.State; // get the IO plugin for image ComApi.InwOaPropertyVec options = oState.GetIOPluginOptions("lcodpimage"); //export the viewpoint to the image oState.DriveIOPlugin("lcodpimage", snapshot, options); System.Drawing.Bitmap oBitmap = new System.Drawing.Bitmap(snapshot); System.IO.MemoryStream ImageStream = new System.IO.MemoryStream(); oBitmap.Save(ImageStream, System.Drawing.Imaging.ImageFormat.Jpeg); oBitmap.Dispose(); //IM.postAttach(issueKey, File.ReadAllBytes(snapshot), IM.ConvertToBytes(v), g); // postAttach2(issueKey, ConvertToBytes(v), "viewpoint.bcfv"); } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } }
public void GetNavisSnapshot() { try { string tempImg = Path.Combine(Path.GetTempPath(), "BCFier", Path.GetTempFileName() + ".png"); // get the state of COM ComApi.InwOpState10 oState = ComBridge.State; // get the IO plugin for image ComApi.InwOaPropertyVec options = oState.GetIOPluginOptions("lcodpimage"); //export the viewpoint to the image oState.DriveIOPlugin("lcodpimage", tempImg, options); Bitmap bitmap = new Bitmap(tempImg); var imageStream = new MemoryStream(); bitmap.Save(imageStream, ImageFormat.Jpeg); bitmap.Dispose(); AddViewControl.AddViewpoint(tempImg); File.Delete(tempImg); } catch (Exception ex1) { MessageBox.Show("exception: " + ex1, "Error!", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Background Worker /// </summary> void worker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = (BackgroundWorker)sender; //create a temporary directory _tempFolder = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "CASE.Navis2BCF", System.IO.Path.GetRandomFileName()); if (!Directory.Exists(_tempFolder)) { Directory.CreateDirectory(_tempFolder); } //if set to attach selected elements, do it only once if (_elemCheck == 1) { elementList = oDoc.CurrentSelection.SelectedItems.Where(o => o.InstanceGuid != Guid.Empty).ToList <ModelItem>(); } for (int i = 0; i < jira.IssuesBCFCollection.Count(); i++) { try { IssueBCF issue = jira.IssuesBCFCollection[i]; //for each issue create a subdirectory named as the guid string g = Guid.NewGuid().ToString(); string issueFolder = System.IO.Path.Combine(_tempFolder, g); DirectoryInfo di = Directory.CreateDirectory(issueFolder); // get the state of COM ComApi.InwOpState10 oState = ComBridge.State; // get the IO plugin for image ComApi.InwOaPropertyVec options = oState.GetIOPluginOptions("lcodpimage"); // configure the option "export.image.format" to export png and image size foreach (ComApi.InwOaProperty opt in options.Properties()) { if (opt.name == "export.image.format") { opt.value = "lcodpexpng"; } if (opt.name == "export.image.width") { opt.value = 1600; } if (opt.name == "export.image.height") { opt.value = 900; } } string snapshot = System.IO.Path.Combine(issueFolder, "snapshot.png"); XDocument v = new XDocument(); //need to use a dispatcher to access resource on a different process Dispatcher.BeginInvoke(new Action(() => { oDoc.SavedViewpoints.CurrentSavedViewpoint = issue.viewpoint; v = generateViewpoint(issue.viewpoint.Viewpoint); })); XDocument m = new XDocument(); m = generateMarkup(issue, g); //set the view to the saved one //export the viewpoint to the image oState.DriveIOPlugin("lcodpimage", snapshot, options); System.Drawing.Bitmap oBitmap = new System.Drawing.Bitmap(snapshot); System.IO.MemoryStream ImageStream = new System.IO.MemoryStream(); oBitmap.Save(ImageStream, System.Drawing.Imaging.ImageFormat.Jpeg); oBitmap.Dispose(); v.Save(issueFolder + @"\viewpoint.bcfv"); m.Save(issueFolder + @"\markup.bcf"); } // END TRY catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } worker.ReportProgress((100 * (i + 1)) / jira.IssuesBCFCollection.Count());// HAS TO BE OUT OF THE DISPATCHER! }// END LOOP }