/// <summary> /// Generate a Markup /// </summary> /// <param name="issue"></param> /// <param name="g"></param> /// <returns></returns> private XDocument generateMarkup(IssueBCF issue, string g) { DateTime m_now = DateTime.Now; XDocument m_markup = new XDocument( new XElement("Markup", new XElement("Header", new XElement("File", new XAttribute("IfcProject", ""), new XElement("Filename", System.IO.Path.GetFileName(Autodesk.Navisworks.Api.Application.ActiveDocument.FileName)), new XElement("Date", m_now.ToString("o")))), new XElement("Topic", new XAttribute("Guid", g), new XElement("ReferenceLink"), new XElement("Title", issue.viewpoint.DisplayName)))); foreach (var comm in issue.viewpoint.Comments) { m_markup.Element("Markup").Add(new XElement("Comment", new XAttribute("Guid", Guid.NewGuid().ToString()), new XElement("VerbalStatus", comm.Status.ToString()), new XElement("Status", "Unknown"), new XElement("Date", comm.CreationDate.ToLocalTime().ToString("o")), new XElement("Author", comm.Author), new XElement("Comment", comm.Body), new XElement("Topic", new XAttribute("Guid", g)))); } return(m_markup); }
/// <summary> /// forther iteration on the three of saved viewpoints /// </summary> private void RecurseItems(SavedItem oSI) { try { Autodesk.Navisworks.Api.GroupItem group = oSI as Autodesk.Navisworks.Api.GroupItem; if (null != group)//is a group { foreach (SavedItem oSII in group.Children) { RecurseItems(oSII); } } else { IssueBCF ib = new IssueBCF(); ib.viewpoint = oSI as SavedViewpoint; jira.IssuesBCFCollection.Add(ib); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <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 }
/// <summary> /// Generate a Markup /// </summary> /// <param name="issue"></param> /// <param name="g"></param> /// <returns></returns> private XDocument generateMarkup(IssueBCF issue, string g) { DateTime m_now = DateTime.Now; XDocument m_markup = new XDocument( new XElement("Markup", new XElement("Header", new XElement("File", new XAttribute("IfcProject", ""), new XElement("Filename", System.IO.Path.GetFileName(Autodesk.Navisworks.Api.Application.ActiveDocument.FileName)), new XElement("Date", m_now.ToString("o")))), new XElement("Topic", new XAttribute("Guid", g), new XElement("ReferenceLink"), new XElement("Title", issue.viewpoint.DisplayName)))); foreach (var comm in issue.viewpoint.Comments) { m_markup.Element("Markup").Add(new XElement("Comment", new XAttribute("Guid", Guid.NewGuid().ToString()), new XElement("VerbalStatus", comm.Status.ToString()), new XElement("Status", "Unknown"), new XElement("Date", comm.CreationDate.ToLocalTime().ToString("o")), new XElement("Author", comm.Author), new XElement("Comment", comm.Body), new XElement("Topic", new XAttribute("Guid", g)))); } return m_markup; }