public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null || value.ToString() == "") { return(null); } RestClient client = new RestClient(); var request = new RestRequest(value.ToString(), Method.GET); try {//workaround because I use a class for this XD string exeConfigPath = this.GetType().Assembly.Location; string dir = Path.GetDirectoryName(exeConfigPath); string[] files = System.IO.Directory.GetFiles(dir, "*.config"); string mainassembly = ""; foreach (var f in files) { if (!f.Contains(this.GetType().Assembly.FullName) && !f.Contains("vshost")) { mainassembly = f.Substring(0, f.Length - 7); break; } } string username = MySettings.Get("username"); string password = DataProtector.DecryptData(MySettings.Get("password")); if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password)) { return(null); } HttpBasicAuthenticator user = new HttpBasicAuthenticator(username, password); client.Authenticator = user; } catch (Exception ex1) { MessageBox.Show("exception: " + ex1); } // var response = client.Execute(request); return(LoadImage(response.RawBytes)); }
private void EditSnapshot_Click(object sender, RoutedEventArgs e) { try { string editSnap = "mspaint"; if (File.Exists(snapshot)) { string customeditor = MySettings.Get("editSnap"); if (!string.IsNullOrEmpty(customeditor) && File.Exists(customeditor)) { editSnap = customeditor; } Process paint = new Process(); // paint.Start(editSnap, "\"" + snapshot + "\""); ProcessStartInfo paintInfo = new ProcessStartInfo(editSnap, "\"" + snapshot + "\""); paintInfo.UseShellExecute = false; //navisworksStartInfo.RedirectStandardOutput = true; paint.StartInfo = paintInfo; paint.Start(); paint.WaitForExit(); Refresh_Click(null, null); } else { MessageBox.Show("Snapshot is not a valit image, please try again.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (System.Exception ex1) { TaskDialog.Show("Error!", "exception: " + ex1); } }
/// <summary> /// Add Issue /// </summary> /// <param name="path"></param> /// <param name="isBcf"></param> /// <returns></returns> private Tuple <Markup, Issue> AddIssue(string path, bool isBcf) { try { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; if (!(uidoc.ActiveView is View3D || uidoc.ActiveView is ViewSheet || uidoc.ActiveView is ViewPlan || uidoc.ActiveView is ViewSection || uidoc.ActiveView is ViewDrafting)) { MessageBox.Show("I'm sorry,\nonly 3D and 2D views are supported.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } Markup issue = new Markup(DateTime.Now); string folderIssue = Path.Combine(path, issue.Topic.Guid); if (!Directory.Exists(folderIssue)) { Directory.CreateDirectory(folderIssue); } var types = new ObservableCollection <Issuetype>(); var assignees = new List <User>(); var components = new ObservableCollection <IssueTracker.Classes.Component>(); var priorities = new ObservableCollection <Priority>(); var noCom = true; var noPrior = true; var noAssign = true; if (!isBcf) { types = mainPan.jira.TypesCollection; assignees = mainPan.getAssigneesIssue(); components = mainPan.jira.ComponentsCollection; priorities = mainPan.jira.PrioritiesCollection; noCom = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.components == null; noPrior = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.priority == null; noAssign = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.assignee == null; } AddIssueRevit air = new AddIssueRevit(uidoc, folderIssue, types, assignees, components, priorities, noCom, noPrior, noAssign); air.Title = "Add Jira Issue"; if (!isBcf) { air.JiraFieldsBox.Visibility = System.Windows.Visibility.Visible; air.VerbalStatus.Visibility = System.Windows.Visibility.Collapsed; air.BcfFieldsBox.Visibility = System.Windows.Visibility.Collapsed; } else { air.JiraFieldsBox.Visibility = System.Windows.Visibility.Collapsed; air.BcfFieldsBox.Visibility = System.Windows.Visibility.Visible; } air.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; air.ShowDialog(); if (air.DialogResult.HasValue && air.DialogResult.Value) { ViewPoint vp = new ViewPoint(true); vp.SnapshotPath = Path.Combine(folderIssue, "snapshot.png"); int elemCheck = 2; if (air.all.IsChecked.Value) { elemCheck = 0; } else if (air.selected.IsChecked.Value) { elemCheck = 1; } vp.VisInfo = generateViewpoint(elemCheck); //Add annotations for description with snapshot/viewpoint StringBuilder descriptionText = new StringBuilder(); if (!string.IsNullOrWhiteSpace(air.CommentBox.Text)) { descriptionText.AppendLine(air.CommentBox.Text); } if (!isBcf) { if (vp.VisInfo != null) { descriptionText.AppendLine(string.Format("<Viewpoint>[^{0}]</Viewpoint>", "viewpoint.bcfv")); } if (!string.IsNullOrWhiteSpace(vp.SnapshotPath)) { descriptionText.AppendLine(string.Format("<Snapshot>[^{0}]</Snapshot>", "snapshot.png")); descriptionText.AppendLine(string.Format("!{0}|width=200!", "snapshot.png")); } } Issue issueJira = new Issue(); if (!isBcf) { issueJira.fields = new Fields(); issueJira.fields.description = descriptionText.ToString().Trim(); issueJira.fields.issuetype = (Issuetype)air.issueTypeCombo.SelectedItem; issueJira.fields.priority = (Priority)air.priorityCombo.SelectedItem; if (!string.IsNullOrEmpty(air.ChangeAssign.Content.ToString()) && air.ChangeAssign.Content.ToString() != "none") { issueJira.fields.assignee = new User(); issueJira.fields.assignee.name = air.ChangeAssign.Content.ToString(); } if (air.SelectedComponents != null && air.SelectedComponents.Any()) { issueJira.fields.components = air.SelectedComponents; } } issue.Viewpoints.Add(vp); issue.Topic.Title = air.TitleBox.Text; issue.Topic.Description = descriptionText.ToString().Trim(); issue.Topic.AssignedTo = air.BcfAssignee.Text; issue.Topic.CreationAuthor = MySettings.Get("username"); issue.Topic.Priority = air.BcfPriority.Text; issue.Topic.TopicStatus = air.VerbalStatus.Text; issue.Topic.TopicType = air.BcfIssueType.Text; issue.Header[0].IfcProject = ExporterIFCUtils.CreateProjectLevelGUID(doc, Autodesk.Revit.DB.IFC.IFCProjectLevelGUIDType.Project); string projFilename = (doc.PathName != null && doc.PathName != "") ? System.IO.Path.GetFileName(doc.PathName) : ""; issue.Header[0].Filename = projFilename; issue.Header[0].Date = DateTime.Now; return(new Tuple <Markup, Issue>(issue, issueJira)); } else { mainPan.DeleteDirectory(folderIssue); } } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } return(null); }
/// <summary> /// Add Issue /// </summary> private void AddIssue(string path, bool isBcf, Action <Tuple <Markup, Issue> > callback) { sendIpcRequest(IpcOperationType.AddIssueRequest, null, (o) => { try { AddIssueResponse ipcResponse = o as AddIssueResponse; if (!ipcResponse.isValidRequest) { MessageBox.Show("Please switch to model space as paper space is not supported.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return; } Markup issue = new Markup(DateTime.Now); string folderIssue = Path.Combine(path, issue.Topic.Guid); if (!Directory.Exists(folderIssue)) { Directory.CreateDirectory(folderIssue); } // copy snapshot from temp file and delete temp file string snapshotPath = Path.Combine(folderIssue, "snapshot.png"); File.Copy(ipcResponse.tempSnapshotPath, snapshotPath); File.Delete(ipcResponse.tempSnapshotPath); var types = new ObservableCollection <Issuetype>(); var assignees = new List <User>(); var components = new ObservableCollection <IssueTracker.Classes.Component>(); var priorities = new ObservableCollection <Priority>(); var noCom = true; var noPrior = true; var noAssign = true; if (!isBcf) { types = mainPan.jira.TypesCollection; assignees = mainPan.getAssigneesIssue(); components = mainPan.jira.ComponentsCollection; priorities = mainPan.jira.PrioritiesCollection; noCom = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.components == null; noPrior = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.priority == null; noAssign = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.assignee == null; } AddIssueDialog aid = new AddIssueDialog(folderIssue, types, assignees, components, priorities, noCom, noPrior, noAssign); aid.Title = "Add Jira Issue"; if (!isBcf) { aid.JiraFieldsBox.Visibility = System.Windows.Visibility.Visible; aid.VerbalStatus.Visibility = System.Windows.Visibility.Collapsed; aid.BcfFieldsBox.Visibility = System.Windows.Visibility.Collapsed; } else { aid.JiraFieldsBox.Visibility = System.Windows.Visibility.Collapsed; aid.BcfFieldsBox.Visibility = System.Windows.Visibility.Visible; } aid.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; aid.ShowDialog(); if (aid.DialogResult.HasValue && aid.DialogResult.Value) { ViewPoint vp = new ViewPoint(true); vp.SnapshotPath = snapshotPath; //int elemCheck = 2; //if (aic.all.IsChecked.Value) // elemCheck = 0; //else if (aic.selected.IsChecked.Value) // elemCheck = 1; vp.VisInfo = ipcResponse.visualizationInfo; //Add annotations for description with snapshot/viewpoint StringBuilder descriptionText = new StringBuilder(); if (!string.IsNullOrWhiteSpace(aid.CommentBox.Text)) { descriptionText.AppendLine(aid.CommentBox.Text); } if (!isBcf) { if (vp.VisInfo != null) { descriptionText.AppendLine(string.Format("{{anchor:<Viewpoint>[^{0}]</Viewpoint>}}", "viewpoint.bcfv")); } if (!string.IsNullOrWhiteSpace(vp.SnapshotPath)) { descriptionText.AppendLine(string.Format("!{0}|thumbnail!", "snapshot.png")); descriptionText.AppendLine(string.Format("{{anchor:<Snapshot>[^{0}]</Snapshot>}}", "snapshot.png")); } } Issue issueJira = new Issue(); if (!isBcf) { issueJira.fields = new Fields(); issueJira.fields.description = descriptionText.ToString().Trim(); issueJira.fields.issuetype = (Issuetype)aid.issueTypeCombo.SelectedItem; issueJira.fields.priority = (Priority)aid.priorityCombo.SelectedItem; if (!string.IsNullOrEmpty(aid.ChangeAssign.Content.ToString()) && aid.ChangeAssign.Content.ToString() != "none") { issueJira.fields.assignee = new User(); issueJira.fields.assignee.name = aid.ChangeAssign.Tag.ToString(); } if (aid.SelectedComponents != null && aid.SelectedComponents.Any()) { issueJira.fields.components = aid.SelectedComponents; } if (!string.IsNullOrWhiteSpace(aid.JiraLabels.Text)) { var labels = aid.JiraLabels.Text.Split(',').ToList(); labels.ForEach(s => s.Trim()); issueJira.fields.labels = labels; } } issue.Viewpoints.Add(vp); issue.Topic.Title = aid.TitleBox.Text; issue.Topic.Description = descriptionText.ToString().Trim(); issue.Topic.AssignedTo = aid.BcfAssignee.Text; issue.Topic.CreationAuthor = string.IsNullOrWhiteSpace(MySettings.Get("username")) ? MySettings.Get("BCFusername") : MySettings.Get("username"); issue.Topic.Priority = aid.BcfPriority.Text; issue.Topic.TopicStatus = aid.VerbalStatus.Text; issue.Topic.TopicType = aid.BcfIssueType.Text; if (!string.IsNullOrWhiteSpace(aid.BcfLabels.Text)) { var labels = aid.BcfLabels.Text.Split(',').ToList(); labels.ForEach(s => s.Trim()); issue.Topic.Labels = labels.ToArray(); } issue.Header[0].IfcProject = ipcResponse.documentGuid; issue.Header[0].Filename = ipcResponse.documentName; issue.Header[0].Date = DateTime.Now; callback(new Tuple <Markup, Issue>(issue, issueJira)); } else { mainPan.DeleteDirectory(folderIssue); } } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } }); }
/// <summary> /// Add Issue /// </summary> /// <param name="path"></param> /// <param name="isBcf"></param> /// <returns></returns> private Tuple <IssueBCF, Issue> AddIssue(string path, bool isBcf) { try { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; if (!(uidoc.ActiveView is View3D || uidoc.ActiveView is ViewSheet || uidoc.ActiveView is ViewPlan || uidoc.ActiveView is ViewSection || uidoc.ActiveView is ViewDrafting)) { MessageBox.Show("I'm sorry,\nonly 3D and 2D views are supported.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } IssueBCF issue = new IssueBCF(); string folderIssue = Path.Combine(path, issue.guid.ToString()); if (!Directory.Exists(folderIssue)) { Directory.CreateDirectory(folderIssue); } var types = new ObservableCollection <Issuetype>(); var assignees = new List <User>(); var components = new ObservableCollection <IssueTracker.Classes.Component>(); var priorities = new ObservableCollection <Priority>(); var noCom = true; var noPrior = true; var noAssign = true; if (!isBcf) { types = mainPan.jira.TypesCollection; assignees = mainPan.getAssigneesIssue(); components = mainPan.jira.ComponentsCollection; priorities = mainPan.jira.PrioritiesCollection; noCom = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.components == null; noPrior = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.priority == null; noAssign = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.assignee == null; } AddIssueRevit air = new AddIssueRevit(uidoc, folderIssue, types, assignees, components, priorities, noCom, noPrior, noAssign); air.Title = "Add Jira Issue"; if (!isBcf) { air.VerbalStatus.Visibility = System.Windows.Visibility.Collapsed; } else { air.JiraFieldsBox.Visibility = System.Windows.Visibility.Collapsed; } air.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; air.ShowDialog(); if (air.DialogResult.HasValue && air.DialogResult.Value) { issue.snapshot = Path.Combine(folderIssue, "snapshot.png"); int elemCheck = 2; if (air.all.IsChecked.Value) { elemCheck = 0; } else if (air.selected.IsChecked.Value) { elemCheck = 1; } Issue issueJira = new Issue(); if (!isBcf) { issueJira.fields = new Fields(); issueJira.fields.issuetype = (Issuetype)air.issueTypeCombo.SelectedItem; issueJira.fields.priority = (Priority)air.priorityCombo.SelectedItem; if (!string.IsNullOrEmpty(air.ChangeAssign.Content.ToString()) && air.ChangeAssign.Content.ToString() != "none") { issueJira.fields.assignee = new User(); issueJira.fields.assignee.name = air.ChangeAssign.Content.ToString(); } if (air.SelectedComponents != null && air.SelectedComponents.Any()) { issueJira.fields.components = air.SelectedComponents; } } issue.viewpoint = generateViewpoint(elemCheck); issue.markup.Topic.Title = air.TitleBox.Text; issue.markup.Header[0].IfcProject = ExporterIFCUtils.CreateProjectLevelGUID(doc, Autodesk.Revit.DB.IFC.IFCProjectLevelGUIDType.Project); string projFilename = (doc.PathName != null && doc.PathName != "") ? System.IO.Path.GetFileName(doc.PathName) : ""; issue.markup.Header[0].Filename = projFilename; issue.markup.Header[0].Date = DateTime.Now; //comment if (!string.IsNullOrWhiteSpace(air.CommentBox.Text)) { CommentBCF c = new CommentBCF(); c.Comment1 = air.CommentBox.Text; c.Topic = new CommentTopic(); c.Topic.Guid = issue.guid.ToString(); ; c.Date = DateTime.Now; c.VerbalStatus = air.VerbalStatus.Text; // if (air.comboStatuses.SelectedIndex != -1) // c.Status = mainPan.getStatus(air.comboStatuses.SelectedValue.ToString()); c.Status = CommentStatus.Unknown; c.Author = (string.IsNullOrWhiteSpace(mainPan.jira.Self.displayName)) ? MySettings.Get("BCFusername") : mainPan.jira.Self.displayName; issue.markup.Comment.Add(c); } return(new Tuple <IssueBCF, Issue>(issue, issueJira)); } else { mainPan.DeleteDirectory(folderIssue); } } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } return(null); }
/// <summary> /// Add Issue /// </summary> /// <param name="path"></param> /// <param name="isBcf"></param> /// <returns></returns> private Tuple <Markup, Issue> AddIssue(string path, bool isBcf) { try { if (doc.Editor.GetCurrentView().IsPaperspaceView) { MessageBox.Show("Please switch to model space as paper space is not supported.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } Markup issue = new Markup(DateTime.Now); string folderIssue = Path.Combine(path, issue.Topic.Guid); if (!Directory.Exists(folderIssue)) { Directory.CreateDirectory(folderIssue); } var types = new ObservableCollection <Issuetype>(); var assignees = new List <User>(); var components = new ObservableCollection <IssueTracker.Classes.Component>(); var priorities = new ObservableCollection <Priority>(); var noCom = true; var noPrior = true; var noAssign = true; if (!isBcf) { types = mainPan.jira.TypesCollection; assignees = mainPan.getAssigneesIssue(); components = mainPan.jira.ComponentsCollection; priorities = mainPan.jira.PrioritiesCollection; noCom = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.components == null; noPrior = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.priority == null; noAssign = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.assignee == null; } // get snapshot by AITSNAPSHOT command string snapshotPath = Path.Combine(folderIssue, "snapshot.png"); AcadApplication acadApp = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication; acadApp.ActiveDocument.SendCommand(string.Format("_.AITSNAPSHOT {0}\n", snapshotPath)); AddIssueCivil3D aic = new AddIssueCivil3D(doc, folderIssue, types, assignees, components, priorities, noCom, noPrior, noAssign); aic.Title = "Add Jira Issue"; if (!isBcf) { aic.JiraFieldsBox.Visibility = System.Windows.Visibility.Visible; aic.VerbalStatus.Visibility = System.Windows.Visibility.Collapsed; aic.BcfFieldsBox.Visibility = System.Windows.Visibility.Collapsed; } else { aic.JiraFieldsBox.Visibility = System.Windows.Visibility.Collapsed; aic.BcfFieldsBox.Visibility = System.Windows.Visibility.Visible; } aic.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; aic.ShowDialog(); if (aic.DialogResult.HasValue && aic.DialogResult.Value) { ViewPoint vp = new ViewPoint(true); vp.SnapshotPath = snapshotPath; int elemCheck = 2; //if (aic.all.IsChecked.Value) // elemCheck = 0; //else if (aic.selected.IsChecked.Value) // elemCheck = 1; vp.VisInfo = generateViewpoint(elemCheck); //Add annotations for description with snapshot/viewpoint StringBuilder descriptionText = new StringBuilder(); if (!string.IsNullOrWhiteSpace(aic.CommentBox.Text)) { descriptionText.AppendLine(aic.CommentBox.Text); } if (!isBcf) { if (vp.VisInfo != null) { descriptionText.AppendLine(string.Format("{{anchor:<Viewpoint>[^{0}]</Viewpoint>}}", "viewpoint.bcfv")); } if (!string.IsNullOrWhiteSpace(vp.SnapshotPath)) { descriptionText.AppendLine(string.Format("!{0}|thumbnail!", "snapshot.png")); descriptionText.AppendLine(string.Format("{{anchor:<Snapshot>[^{0}]</Snapshot>}}", "snapshot.png")); } } Issue issueJira = new Issue(); if (!isBcf) { issueJira.fields = new Fields(); issueJira.fields.description = descriptionText.ToString().Trim(); issueJira.fields.issuetype = (Issuetype)aic.issueTypeCombo.SelectedItem; issueJira.fields.priority = (Priority)aic.priorityCombo.SelectedItem; if (!string.IsNullOrEmpty(aic.ChangeAssign.Content.ToString()) && aic.ChangeAssign.Content.ToString() != "none") { issueJira.fields.assignee = new User(); issueJira.fields.assignee.name = aic.ChangeAssign.Tag.ToString(); } if (aic.SelectedComponents != null && aic.SelectedComponents.Any()) { issueJira.fields.components = aic.SelectedComponents; } if (!string.IsNullOrWhiteSpace(aic.JiraLabels.Text)) { var labels = aic.JiraLabels.Text.Split(',').ToList(); labels.ForEach(s => s.Trim()); issueJira.fields.labels = labels; } } issue.Viewpoints.Add(vp); issue.Topic.Title = aic.TitleBox.Text; issue.Topic.Description = descriptionText.ToString().Trim(); issue.Topic.AssignedTo = aic.BcfAssignee.Text; issue.Topic.CreationAuthor = string.IsNullOrWhiteSpace(MySettings.Get("username")) ? MySettings.Get("BCFusername") : MySettings.Get("username"); issue.Topic.Priority = aic.BcfPriority.Text; issue.Topic.TopicStatus = aic.VerbalStatus.Text; issue.Topic.TopicType = aic.BcfIssueType.Text; if (!string.IsNullOrWhiteSpace(aic.BcfLabels.Text)) { var labels = aic.BcfLabels.Text.Split(',').ToList(); labels.ForEach(s => s.Trim()); issue.Topic.Labels = labels.ToArray(); } issue.Header[0].IfcProject = doc.Database.FingerprintGuid; issue.Header[0].Filename = doc.Database.OriginalFileName; issue.Header[0].Date = DateTime.Now; return(new Tuple <Markup, Issue>(issue, issueJira)); } else { mainPan.DeleteDirectory(folderIssue); } } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } return(null); }
/// <summary> /// External Event Implementation /// </summary> /// <param name="app"></param> public void Execute(UIApplication app) { try { UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; SelElementSet m_elementsToHide = SelElementSet.Create(); List <ElementId> elementids = new List <ElementId>(); // IS ORTHOGONAL if (v.OrthogonalCamera != null) { if (v.OrthogonalCamera.ViewToWorldScale == null || v.OrthogonalCamera.CameraViewPoint == null || v.OrthogonalCamera.CameraUpVector == null || v.OrthogonalCamera.CameraDirection == null) { return; } //type = "OrthogonalCamera"; var zoom = UnitUtils.ConvertToInternalUnits(v.OrthogonalCamera.ViewToWorldScale, DisplayUnitType.DUT_METERS); var CameraDirection = Utils.GetXYZ(v.OrthogonalCamera.CameraDirection.X, v.OrthogonalCamera.CameraDirection.Y, v.OrthogonalCamera.CameraDirection.Z); var CameraUpVector = Utils.GetXYZ(v.OrthogonalCamera.CameraUpVector.X, v.OrthogonalCamera.CameraUpVector.Y, v.OrthogonalCamera.CameraUpVector.Z); var CameraViewPoint = Utils.GetXYZ(v.OrthogonalCamera.CameraViewPoint.X, v.OrthogonalCamera.CameraViewPoint.Y, v.OrthogonalCamera.CameraViewPoint.Z); var orient3d = Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true); View3D orthoView = null; //if active view is 3d ortho use it if (doc.ActiveView.ViewType == ViewType.ThreeD) { View3D ActiveView3D = doc.ActiveView as View3D; if (!ActiveView3D.IsPerspective) { orthoView = ActiveView3D; } } if (orthoView == null) { IEnumerable <View3D> viewcollector3D = get3DViews(doc); //try to use default 3D view if (viewcollector3D.Any() && viewcollector3D.Where(o => o.Name == "{3D}" || o.Name == "BCFortho").Any()) { orthoView = viewcollector3D.Where(o => o.Name == "{3D}" || o.Name == "BCFortho").First(); } } using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Open orthogonal view") == TransactionStatus.Started) { //create a new 3d ortho view if (orthoView == null) { orthoView = View3D.CreateIsometric(doc, getFamilyViews(doc).First().Id); orthoView.Name = "BCFortho"; } orthoView.SetOrientation(orient3d); trans.Commit(); } } uidoc.ActiveView = orthoView; //adjust view rectangle // **** CUSTOM VALUE FOR TEKLA **** // // double x = touple.Item2 // **** CUSTOM VALUE FOR TEKLA **** // double customZoomValue = (MyProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5; double x = zoom / customZoomValue; XYZ m_xyzTl = uidoc.ActiveView.Origin.Add(uidoc.ActiveView.UpDirection.Multiply(x)).Subtract(uidoc.ActiveView.RightDirection.Multiply(x)); XYZ m_xyzBr = uidoc.ActiveView.Origin.Subtract(uidoc.ActiveView.UpDirection.Multiply(x)).Add(uidoc.ActiveView.RightDirection.Multiply(x)); uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr); } else if (v.PerspectiveCamera != null) { if (v.PerspectiveCamera.FieldOfView == null || v.PerspectiveCamera.CameraViewPoint == null || v.PerspectiveCamera.CameraUpVector == null || v.PerspectiveCamera.CameraDirection == null) { return; } var zoom = v.PerspectiveCamera.FieldOfView; double z1 = 18 / Math.Tan(zoom / 2 * Math.PI / 180); //focale 1 double z = 18 / Math.Tan(25 / 2 * Math.PI / 180); //focale, da controllare il 18, vedi PDF double factor = z1 - z; var CameraDirection = Utils.GetXYZ(v.PerspectiveCamera.CameraDirection.X, v.PerspectiveCamera.CameraDirection.Y, v.PerspectiveCamera.CameraDirection.Z); var CameraUpVector = Utils.GetXYZ(v.PerspectiveCamera.CameraUpVector.X, v.PerspectiveCamera.CameraUpVector.Y, v.PerspectiveCamera.CameraUpVector.Z); XYZ oldO = Utils.GetXYZ(v.PerspectiveCamera.CameraViewPoint.X, v.PerspectiveCamera.CameraViewPoint.Y, v.PerspectiveCamera.CameraViewPoint.Z); var CameraViewPoint = (oldO.Subtract(CameraDirection.Divide(factor))); var orient3d = Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true); View3D perspView = null; IEnumerable <View3D> viewcollector3D = get3DViews(doc); if (viewcollector3D.Any() && viewcollector3D.Where(o => o.Name == "BCFpersp").Any()) { perspView = viewcollector3D.Where(o => o.Name == "BCFpersp").First(); } using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Open perspective view") == TransactionStatus.Started) { if (null == perspView) { perspView = View3D.CreatePerspective(doc, getFamilyViews(doc).First().Id); perspView.Name = "BCFpersp"; } perspView.SetOrientation(orient3d); // turn off the far clip plane with standard parameter API if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue) { Parameter m_farClip = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR); m_farClip.Set(0); } perspView.CropBoxActive = true; perspView.CropBoxVisible = true; trans.Commit(); } } uidoc.ActiveView = perspView; } else if (v.SheetCamera != null)//sheet { //using (Transaction trans = new Transaction(uidoc.Document)) //{ // if (trans.Start("Open sheet view") == TransactionStatus.Started) // { IEnumerable <View> viewcollectorSheet = getSheets(doc, v.SheetCamera.SheetID); if (!viewcollectorSheet.Any()) { MessageBox.Show("No Sheet with Id=" + v.SheetCamera.SheetID + " found."); return; } uidoc.ActiveView = viewcollectorSheet.First(); uidoc.RefreshActiveView(); // trans.Commit(); // } //} XYZ m_xyzTl = new XYZ(v.SheetCamera.TopLeft.X, v.SheetCamera.TopLeft.Y, v.SheetCamera.TopLeft.Z); XYZ m_xyzBr = new XYZ(v.SheetCamera.BottomRight.X, v.SheetCamera.BottomRight.Y, v.SheetCamera.BottomRight.Z); uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr); } else { return; } //select/hide elements if (v.Components != null && v.Components.Any()) { FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType(); System.Collections.Generic.ICollection <ElementId> collection = collector.ToElementIds(); foreach (var e in v.Components) { var bcfguid = IfcGuid.FromIfcGUID(e.IfcGuid); var ids = collection.Where(o => bcfguid == ExportUtils.GetExportId(doc, o)); if (ids.Any()) { m_elementsToHide.Add(doc.GetElement(ids.First())); elementids.Add(ids.First()); } } if (null != m_elementsToHide && !m_elementsToHide.IsEmpty) { //do transaction only if there is something to hide/select using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Apply visibility/selection") == TransactionStatus.Started) { if (MySettings.Get("selattachedelems") == "0") { uidoc.ActiveView.IsolateElementsTemporary(elementids); } else { uidoc.Selection.Elements = m_elementsToHide; } } trans.Commit(); } } } uidoc.RefreshActiveView(); } catch (Exception ex) { TaskDialog.Show("Error!", "exception: " + ex); } }
private void Open3DView(VisualizationInfo v) { try { // { // Tuple <Point3D, Vector3D, Vector3D, ViewpointProjection, double> tuple = GetViewCoordinates(v); if (tuple == null) { MessageBox.Show("Viewpoint not formatted correctly.", "Viewpoint Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument; // get current viewpoint // Viewpoint oCurVP = oDoc.vi.CurrentViewpoint.ToViewpoint; // get copy viewpoint Viewpoint oCopyVP = new Viewpoint(); oCopyVP.AlignDirection(tuple.Item3); oCopyVP.AlignUp(tuple.Item2); oCopyVP.Projection = tuple.Item4; // **** CUSTOM VALUE FOR TEKLA **** // // otherwise = 1 // **** CUSTOM VALUE FOR TEKLA **** // const double TEKLA = 1.25; double x = tuple.Item5 / TEKLA; if (oCopyVP.Projection == ViewpointProjection.Orthographic) { oCopyVP.Position = tuple.Item1; oCopyVP.FocalDistance = 1; //top center point of view Point3D xyzTL = oCopyVP.Position.Add(tuple.Item2.Multiply(x)); oCopyVP.SetExtentsAtFocalDistance(1, xyzTL.DistanceTo(oCopyVP.Position)); } else { //double angle = tuple.Item5 * Math.PI / 180; // MessageBox.Show(tuple.Item5.ToString() + " " +(Math.Tan(angle / 2)*2).ToString()); oCopyVP.FocalDistance = tuple.Item5; //oCopyVP.SetExtentsAtFocalDistance(Math.Tan(angle / 2) * 2, Math.Tan(angle / 2) * 2 / oCopyVP.AspectRatio); oCopyVP.Position = tuple.Item1; } oDoc.CurrentViewpoint.CopyFrom(oCopyVP); if (v.Components != null && v.Components.Any()) { // ModelItemCollection selected = new ModelItemCollection(); List <ModelItem> attachedElems = new List <ModelItem>(); List <ModelItem> elems = oDoc.Models.First.RootItem.DescendantsAndSelf.ToList <ModelItem>(); foreach (var item in elems.Where(o => o.InstanceGuid != Guid.Empty)) { string ifcguid = IfcGuid.ToIfcGuid(item.InstanceGuid).ToString(); if (v.Components.Any(o => o.IfcGuid == ifcguid)) { attachedElems.Add(item); } } if (attachedElems.Any())//avoid to hide everything if no elements matches { if (MySettings.Get("selattachedelems") == "0") { List <ModelItem> elemsVisible = new List <ModelItem>(); foreach (var item in attachedElems) { elemsVisible.AddRange(item.AncestorsAndSelf); } foreach (var item in elemsVisible) { elems.Remove(item); } oDoc.Models.ResetAllHidden(); oDoc.Models.SetHidden(elems, true); } else { oDoc.CurrentSelection.Clear(); oDoc.CurrentSelection.AddRange(attachedElems); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } //setVisibility(v); }
private Tuple <List <IssueBCF>, List <Issue> > AddIssue(string path, bool isBcf) { try { // set image export settings ComApi.InwOaPropertyVec options = ComBridge.State.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; } } _savedViewpoints = new List <SavedViewpoint>(); foreach (SavedItem oSI in _oDoc.SavedViewpoints.ToSavedItemCollection()) { RecurseItems(oSI); } var types = new ObservableCollection <Issuetype>(); var assignees = new List <User>(); var components = new ObservableCollection <Component>(); var priorities = new ObservableCollection <Priority>(); var noCom = true; var noPrior = true; var noAssign = true; if (!isBcf) { types = mainPan.jira.TypesCollection; assignees = mainPan.getAssigneesProj(); components = mainPan.jira.ComponentsCollection; priorities = mainPan.jira.PrioritiesCollection; noCom = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.components == null; noPrior = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.priority == null; noAssign = mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.assignee == null; } AddIssueNavis ain = new AddIssueNavis(_savedViewpoints, types, assignees, components, priorities, noCom, noPrior, noAssign); if (isBcf) { ain.JiraFieldsBox.Visibility = System.Windows.Visibility.Collapsed; } ain.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; ain.ShowDialog(); if (ain.DialogResult.HasValue && ain.DialogResult.Value) { int elemCheck = 2; if (ain.all.IsChecked.Value) { elemCheck = 0; } else if (ain.selected.IsChecked.Value) { elemCheck = 1; } List <SavedViewpoint> savedViewpointsImport = new List <SavedViewpoint>(); for (int i = 0; i < ain.issueList.SelectedItems.Count; i++) { int index = ain.issueList.Items.IndexOf(ain.issueList.SelectedItems[i]); savedViewpointsImport.Add(_savedViewpoints[index]); } if (!savedViewpointsImport.Any()) { return(null); } //get selection only once! if (elemCheck == 1) { _elementList = _oDoc.CurrentSelection.SelectedItems.Where(o => o.InstanceGuid != Guid.Empty).ToList <ModelItem>(); } List <IssueBCF> issues = new List <IssueBCF>(); List <Issue> issuesJira = new List <Issue>(); foreach (var sv in savedViewpointsImport) { Issue issueJira = new Issue(); if (!isBcf) { issueJira.fields = new Fields(); issueJira.fields.issuetype = (Issuetype)ain.issueTypeCombo.SelectedItem; issueJira.fields.priority = (Priority)ain.priorityCombo.SelectedItem; if (!string.IsNullOrEmpty(ain.ChangeAssign.Content.ToString()) && ain.ChangeAssign.Content.ToString() != "none") { issueJira.fields.assignee = new User(); issueJira.fields.assignee.name = ain.ChangeAssign.Content.ToString(); } if (ain.SelectedComponents != null && ain.SelectedComponents.Any()) { issueJira.fields.components = ain.SelectedComponents; } } IssueBCF issue = new IssueBCF(); string folderIssue = Path.Combine(path, issue.guid.ToString()); if (!Directory.Exists(folderIssue)) { Directory.CreateDirectory(folderIssue); } issue.snapshot = Path.Combine(folderIssue, "snapshot.png"); // set the currtent saved viewpoint and then generate sna and BCF viewpoint _oDoc.SavedViewpoints.CurrentSavedViewpoint = sv; issue.viewpoint = generateViewpoint(sv.Viewpoint, elemCheck); generateSnapshot(folderIssue); issue.markup.Topic.Title = sv.DisplayName; issue.markup.Header[0].IfcProject = ""; string projFilename = !string.IsNullOrEmpty(_oDoc.FileName) ? System.IO.Path.GetFileName(_oDoc.FileName) : ""; issue.markup.Header[0].Filename = projFilename; issue.markup.Header[0].Date = DateTime.Now; //comment if (sv.Comments.Any()) { foreach (var comm in sv.Comments) { var c = new CommentBCF { Comment1 = comm.Body, Topic = new CommentTopic { Guid = issue.guid.ToString() } }; ; c.Date = DateTime.Now; c.VerbalStatus = comm.Status.ToString(); c.Author = (string.IsNullOrWhiteSpace(mainPan.jira.Self.displayName)) ? MySettings.Get("BCFusername") : mainPan.jira.Self.displayName; issue.markup.Comment.Add(c); } } issues.Add(issue); issuesJira.Add(issueJira); } // end foreach return(new Tuple <List <IssueBCF>, List <Issue> >(issues, issuesJira)); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return(null); }