/// <summary> /// Returns navisworks selection set matching GUID string /// </summary> /// <param name="guid"></param> /// <returns></returns> private SelectionSet GetSetsByGUID(string guid) { Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument; DocumentSelectionSets selections = doc.SelectionSets; SelectionSet outputSelectionSet = selections.ResolveGuid(System.Guid.Parse(guid)) as SelectionSet ?? new SelectionSet(); return(outputSelectionSet); }
public override int Execute(params string[] parameters) { Document oDoc = Application.ActiveDocument; DocumentSelectionSets selectionSets = oDoc.SelectionSets; FolderItem rootFolderItem = selectionSets.RootItem; string output = WriteSelectionSetContent( rootFolderItem, oDoc.Title, ""); Win.MessageBox.Show(output); return(0); }
public override int Execute(params string[] parameters) { try { Document doc = Application.ActiveDocument; DocumentSelectionSets selectionSets = doc.SelectionSets; FolderItem rootFolderItem = selectionSets.RootItem; List <FolderItem> folders = new List <FolderItem>(); foreach (SavedItem item in rootFolderItem.Children) { if (item is FolderItem) { folders.Add(item as FolderItem); } } if (folders.Count == 0) { WinForms.MessageBox.Show("Для работы этой команды необходимо наличие папок с сохраненными наборами выбора", "Отменено", WinForms.MessageBoxButtons.OK); return(0); } string initialPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string initialFileName = "Проект"; string docFileName = doc.FileName; if (!String.IsNullOrEmpty(docFileName)) { initialPath = Path.GetDirectoryName(docFileName); initialFileName = Path.GetFileNameWithoutExtension(docFileName); } //Вывести окно для выбора корневой папки для формирования структуры SelectRootFolderWindow selectRootFolderWindow = new SelectRootFolderWindow(folders, true, initialPath); bool?result = selectRootFolderWindow.ShowDialog(); if (result != null && result.Value) { FolderItem rootFolder = selectRootFolderWindow.RootFolder; //Запросить имя и путь создаваемого файла структуры WinForms.SaveFileDialog saveFileDialog = new WinForms.SaveFileDialog(); saveFileDialog.InitialDirectory = initialPath; saveFileDialog.Filter = "st.xml files (*.st.xml)|*.st.xml"; saveFileDialog.FilterIndex = 1; saveFileDialog.RestoreDirectory = true; if (!String.IsNullOrWhiteSpace(initialFileName)) { saveFileDialog.FileName = initialFileName; } saveFileDialog.Title = "Укажите файл для создания структуры"; if (saveFileDialog.ShowDialog() == WinForms.DialogResult.OK) { string stFilename = saveFileDialog.FileName; string name = Path.GetFileName(stFilename); string clFilename = Path.Combine(Path.GetDirectoryName(stFilename), name.Substring(0, name.Length - 6) + "cl.xml"); Classifier classifier = null; if (selectRootFolderWindow.ViewModel.ClassifierSamplePathVM.FileNameIsValid) { //Если был указан образец структуры, то десериализовать его //и использовать как основу для для создаваемого классификатора using (StreamReader sr = new StreamReader( selectRootFolderWindow.ViewModel.ClassifierSamplePathVM.FileName)) { string serializedData = Common.Utils.RemoveInvalidXmlSubstrs(sr.ReadToEnd()); XmlSerializer xmlSerializer = new XmlSerializer(typeof(Classifier)); StringReader stringReader = new StringReader(serializedData); classifier = (Classifier)xmlSerializer.Deserialize(stringReader); classifier.ClassName = classifier.Name; classifier.DefaultClasses[0] = classifier.Name + "_DefaultFolder"; classifier.DefaultClasses[1] = classifier.Name + "_DefaultGeometry"; } } else { //пустой классификатор classifier = new Classifier() { Name = rootFolder.DisplayName, ClassName = rootFolder.DisplayName, IsPrimary = true, DetailLevels = new List <string>() { "Folder", "Geometry" } }; classifier.DefaultClasses[0] = rootFolder.DisplayName + "_DefaultFolder"; classifier.DefaultClasses[1] = rootFolder.DisplayName + "_DefaultGeometry"; } //Создать пустую структуру Structure structure = new Structure() { Name = rootFolder.DisplayName, Classifier = classifier.Name, IsPrimary = true, }; //Создать StructureDataStorage StructureDataStorage dataStorage = new StructureDataStorage( doc, stFilename, clFilename, structure, classifier, true, selectRootFolderWindow.SelectedCategories); //Сформировать XML по структуре папок //Каждая папка - объект без свойств StructureFilling(null, rootFolder, dataStorage, doc); dataStorage.SerializeStruture(); WinForms.MessageBox.Show("Данные сохранены", "Готово", WinForms.MessageBoxButtons.OK); } } } catch (Exception ex) { CommonException(ex, "Ошибка при создании файлов структуры из наборов выбора"); } return(0); }
public override int Execute(params string[] parameters) { Win.MessageBoxResult result = Win.MessageBox.Show("Перед экспортом FBX, нужно настроить параметры экспорта в " + "FBX на экспорт ЛИБО В ФОРМАТЕ ASCII, ЛИБО В ДВОИЧНОМ ФОРМАТЕ ВЕРСИИ НЕ НОВЕЕ 2018. " + "Рекомендуется так же отключить экспорт источников света и камер. " + "\n\nНачать выгрузку FBX?", "Выгрузка FBX", Win.MessageBoxButton.YesNo); if (result == Win.MessageBoxResult.Yes) { try { Document doc = Application.ActiveDocument; DocumentSelectionSets selectionSets = doc.SelectionSets; FolderItem rootFolderItem = selectionSets.RootItem; List <FolderItem> folders = new List <FolderItem>(); foreach (SavedItem item in rootFolderItem.Children) { if (item is FolderItem) { folders.Add(item as FolderItem); } } if (folders.Count == 0) { WinForms.MessageBox.Show("Для работы этой команды необходимо наличие папок с сохраненными наборами выбора", "Отменено", WinForms.MessageBoxButtons.OK); return(0); } //Вывести окно для выбора корневой папки для формирования структуры SelectRootFolderWindow selectRootFolderWindow = new SelectRootFolderWindow(folders, false, null); bool?resultRootSelect = selectRootFolderWindow.ShowDialog(); if (resultRootSelect != null && resultRootSelect.Value) { string initialPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string docPath = doc.FileName; if (!String.IsNullOrEmpty(docPath)) { initialPath = Path.GetDirectoryName(docPath); } WinForms.FolderBrowserDialog fbd = new WinForms.FolderBrowserDialog(); fbd.Description = "Выберите расположение файлов FBX"; fbd.ShowNewFolderButton = true; fbd.SelectedPath = initialPath; WinForms.DialogResult fbdResult = fbd.ShowDialog(); if (fbdResult == WinForms.DialogResult.OK) { FolderItem rootFolder = selectRootFolderWindow.RootFolder; FBXExport.ManualUse = false; FBXExport.FBXSavePath = fbd.SelectedPath; ExportBySelSets(rootFolder, doc); Win.MessageBox.Show("Готово", "Готово", Win.MessageBoxButton.OK, Win.MessageBoxImage.Information); } } } catch (Exception ex) { CommonException(ex, "Ошибка при экспорте объектов по отдельным наборам выбора"); } finally { FBXExport.ManualUse = true; FBXExport.FBXSavePath = null; FBXExport.FBXFileName = null; } } return(0); }
public override int Execute(params string[] parameters) { string documentspath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string fileoutpath = documentspath + "\\" + "CoordinationModel.nwd"; Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument; double scalefactor = UnitConversion.ScaleFactor(Units.Meters, doc.Units); DocumentSelectionSets myselectionsets = doc.SelectionSets; ModelItemCollection clipbox = new ModelItemCollection(); foreach (SavedItem childItem in ((GroupItem)myselectionsets.RootItem).Children) { if (childItem.DisplayName == "hidden") { SelectionSet oSet = childItem as SelectionSet; doc.Models.SetHidden(oSet.ExplicitModelItems, false); myselectionsets.Remove((GroupItem)myselectionsets.RootItem, oSet); } else if (childItem.DisplayName == "clipbox") { SelectionSet oSet = childItem as SelectionSet; clipbox.AddRange(oSet.ExplicitModelItems); } } Point3D selbbmin, selbbmax; if (parameters.Length == 0) { ModelItemCollection mysel = doc.CurrentSelection.SelectedItems; selbbmin = mysel.BoundingBox().Min; selbbmax = mysel.BoundingBox().Max; } else { fileoutpath = @parameters[0]; selbbmin = new Point3D(Convert.ToDouble(parameters[1].Replace("neg", "-")) * scalefactor, Convert.ToDouble(parameters[2].Replace("neg", "-")) * scalefactor, Convert.ToDouble(parameters[3].Replace("neg", "-")) * scalefactor); selbbmax = new Point3D(Convert.ToDouble(parameters[4].Replace("neg", "-")) * scalefactor, Convert.ToDouble(parameters[5].Replace("neg", "-")) * scalefactor, Convert.ToDouble(parameters[6].Replace("neg", "-")) * scalefactor); } if (selbbmin.IsOrigin && selbbmax.IsOrigin) { doc.SaveFile(fileoutpath); return(0); } string logfile = documentspath + "\\" + Path.GetFileName(fileoutpath) + ".txt"; List <string> log = new List <string>(); //log.Add("scalefactor###" + scalefactor); //selbbmin = new Point3D(-7.000, 14.000, 17.000); //selbbmax = new Point3D(-5.000, 16.000, 19.000); Point3D mid = selbbmin.ToVector3D().Add(selbbmax).ToVector3D().Divide(2).ToPoint3D(); Vector3D diff = new Point3D(1, 1, 1).ToVector3D(); double deltaval = 0.01; Vector3D delta = new Point3D(deltaval, deltaval, deltaval).ToVector3D(); double clearance = 0; while (diff.X > 0 && diff.Y > 0 && diff.Z > 0) { clearance += deltaval; selbbmax = selbbmax.Subtract(delta); selbbmin = selbbmin.Add(delta); diff = selbbmax.ToVector3D().Subtract(selbbmin.ToVector3D()); } Transform3D EndTransform = new Transform3D(); Transform3DComponents Transform3DComponent = EndTransform.Factor(); Transform3DComponent.Scale = selbbmax.ToVector3D().Subtract(selbbmin.ToVector3D()); Rotation3D ScaleOrientation = new Rotation3D(new UnitVector3D(0, 0, 1), 0); Transform3DComponent.Rotation = ScaleOrientation; Transform3DComponent.Translation = mid.ToVector3D(); EndTransform = Transform3DComponent.Combine(); doc.Models.OverridePermanentTransform(clipbox, EndTransform, true); try { DocumentClash documentClash = doc.GetClash(); DocumentClashTests myClashTests = documentClash.TestsData; ClashTest myClashTestorg = myClashTests.Tests[0] as ClashTest; ClashTest myClashTest = myClashTestorg.CreateCopy() as ClashTest; myClashTest.TestType = ClashTestType.Clearance; myClashTest.Tolerance = Math.Pow((3 * Math.Pow(clearance, 2)), 0.5); myClashTest.Status = ClashTestStatus.New; myClashTests.TestsEditTestFromCopy(myClashTestorg, myClashTest); myClashTests.TestsRunTest(myClashTestorg); myClashTest = myClashTests.Tests[0] as ClashTest; ModelItemCollection myClashingElements = new ModelItemCollection(); for (var i = 0; i < myClashTest.Children.Count; i++) { ClashResult myClash = myClashTest.Children[i] as ClashResult; myClashingElements.AddRange(myClash.Selection2); } myClashingElements.Invert(doc); doc.Models.SetHidden(myClashingElements, true); SelectionSet allhidden = new SelectionSet(myClashingElements); allhidden.DisplayName = "hidden"; myselectionsets.AddCopy(allhidden); myClashTests.TestsClearResults(myClashTest); //clipbox.AddRange((doc.SelectionSets.RootItem.Children[0] as SelectionSet).GetSelectedItems()); doc.Models.ResetPermanentTransform(clipbox); doc.SaveFile(fileoutpath); } catch (Exception e) { log.Add(e.Message + "###" + e.StackTrace); } finally { File.WriteAllText(logfile, string.Join("\r\n", log)); } return(0); }