public SchemaEntityOpr(Element ele) { if (false == GetEntityFrom(ele)) { m_sch = SchemaOpr.Instance().schema; m_entity = new Entity(m_sch); } }
public SchemaEntityOpr(Entity ent) { if (null != ent && ent.Schema.GUID == SchemaOpr.Instance().schema.GUID) { m_sch = ent.Schema; m_entity = ent; } }
/// <summary> /// 从element获取扩展存储 /// </summary> /// <param name="ele"></param> /// <returns></returns> public bool GetEntityFrom(Element ele) { Entity ent = ele.GetEntity(SchemaOpr.Instance().schema); if (ent.IsValid()) { m_sch = ent.Schema; m_entity = ent; return(true); } // return(false); }
/// </structural_toolkit_2015> /// <structural_toolkit_2015> /// <summary> /// Build document body for result document /// </summary> /// <param name="calculationParameters">Code calculation parameters</param> /// <param name="element">Revit element for which result document is built</param> /// <param name="document">Active Revit document</param> /// <returns>DocumentBody object</returns> public override DocumentBody BuildResultDocumentBody(Autodesk.Revit.DB.ExtensibleStorage.Entity calculationParameters, Element element, Autodesk.Revit.DB.Document document) { Autodesk.Revit.DB.CodeChecking.Storage.StorageService service = Autodesk.Revit.DB.CodeChecking.Storage.StorageService.GetStorageService(); Autodesk.Revit.DB.CodeChecking.Storage.StorageDocument storageDocument = service.GetStorageDocument(document); Guid activePackageId = storageDocument.CalculationParamsManager.CalculationParams.GetInputResultPackageId(Server.ID); Autodesk.Revit.DB.CodeChecking.Storage.ResultStatus status = storageDocument.ResultsManager.GetResultStatus(element, activePackageId, Server.ID); DocumentBody body = new DocumentBody(); if (!status.IsError()) { // create body object // get results schema for the current element string schemaName = calculationParameters.Schema.SchemaName; switch (schemaName) { case "ResultBeam": ResultLinearElement resultBeam = new ResultBeam(); resultBeam.SetProperties(calculationParameters); WriteResultsToNoteForLinearElements(body, resultBeam, document, ElementType.Beam); break; case "ResultColumn": ResultLinearElement resultColumn = new ResultColumn(); resultColumn.SetProperties(calculationParameters); WriteResultsToNoteForLinearElements(body, resultColumn, document, ElementType.Column); break; case "ResultFloor": ResultSurfaceElement resultFloor = new ResultSurfaceElement(); resultFloor.SetProperties(calculationParameters); WriteResultsToNoteForSurfaceElements(body, resultFloor, document, element, ElementType.Floor); break; case "ResultWall": ResultSurfaceElement resultWall = new ResultSurfaceElement(); resultWall.SetProperties(calculationParameters); WriteResultsToNoteForSurfaceElements(body, resultWall, document, element, ElementType.Wall); break; } } return(body); }
public ManageExcelLinksForm(Document _doc, Guid _schemaGuid) { doc = _doc; schemaGuid = _schemaGuid; InitializeComponent(); // Read the schema information Schema schema = Schema.Lookup(schemaGuid); if (schema != null) { Autodesk.Revit.DB.ExtensibleStorage.DataStorage ds = null; ICollection <ElementId> dsCollector = new FilteredElementCollector(doc).OfClass(typeof(DataStorage)).ToElementIds(); foreach (ElementId eid in dsCollector) { DataStorage dStor = doc.GetElement(eid) as DataStorage; if (dStor.Name == Properties.Settings.Default.DataStorageName) { ds = dStor; break; } } if (ds != null) { Autodesk.Revit.DB.ExtensibleStorage.Entity entity = null; entity = ds.GetEntity(schema); ExcelScheduleEntity schedEntity = ds.GetEntity <ExcelScheduleEntity>(); if (schedEntity != null) { elementIds = schedEntity.ScheduleId; paths = schedEntity.ExcelFilePath; worksheets = schedEntity.WorksheetName; dateTimes = schedEntity.DateTime; pathTypes = schedEntity.PathType; } //if (entity.IsValid()) //{ // elementIds = entity.Get<IList<ElementId>>("ScheduleId"); // paths = entity.Get<IList<string>>("ExcelFilePath"); // worksheets = entity.Get<IList<string>>("WorksheetName"); // dateTimes = entity.Get<IList<string>>("DateTime"); // try // { // pathTypes = entity.Get<IList<int>>("PathType"); // } // catch // { // List<int> tempPaths = new List<int>(); // for (int i = 0; i < elementIds.Count; i++) // { // tempPaths.Add(0); // } // pathTypes = tempPaths; // } //} } ////Autodesk.Revit.DB.ExtensibleStorage.Entity entity = null; //try //{ // entity = doc.ProjectInformation.GetEntity(schema); //} //catch { } //if (entity != null) //{ // try // { // elementIds = entity.Get<IList<ElementId>>("ScheduleId"); // paths = entity.Get<IList<string>>("ExcelFilePath"); // worksheets = entity.Get<IList<string>>("WorksheetName"); // dateTimes = entity.Get<IList<string>>("DateTime"); // try // { // pathTypes = entity.Get<IList<int>>("PathType"); // } // catch // { // List<int> tempPaths = new List<int>(); // for (int i = 0; i < elementIds.Count; i++) // { // tempPaths.Add(0); // } // pathTypes = tempPaths; // } // } // catch { } // if (elementIds == null) // { // elementIds = new List<ElementId>(); // paths = new List<string>(); // worksheets = new List<string>(); // dateTimes = new List<string>(); // pathTypes = new List<int>(); // } //} } contentOnlyCheckBox.IsChecked = contentOnly; contentOnlyCheckBox.ToolTip = "When reloading, only get new content and not style information or modify rows/columns.\nChanging this setting is only remembered while this Manage Excel Links window is open."; //linkDataGrid.ItemsSource = LinkedData; // Build the table BuildTable(); }
private void ConvertButton_Click(object sender, RoutedEventArgs e) { //System.Windows.MessageBox.Show("Selection: " + linkDataGrid.SelectedItems[0].GetType().FullName); // Strip this schema object from the entity. //DataRowView selectedRow = (DataRowView)linkDataGrid.SelectedItems[0]; if (linkDataGrid.SelectedItems[0] is LinkData selectedLinkData) { //string cell = selectedRow.Row.ItemArray[3].ToString(); // Read the schema information Autodesk.Revit.DB.ExtensibleStorage.Schema schema = Autodesk.Revit.DB.ExtensibleStorage.Schema.Lookup(schemaGuid); if (schema != null) { Autodesk.Revit.DB.ExtensibleStorage.Entity entity = null; DataStorage ds = SchemaManager.GetDataStorage(doc); try { entity = ds.GetEntity(schema); } catch { } if (entity != null) { elementIds = entity.Get <IList <ElementId> >("ScheduleId"); paths = entity.Get <IList <string> >("ExcelFilePath"); worksheets = entity.Get <IList <string> >("WorksheetName"); dateTimes = entity.Get <IList <string> >("DateTime"); pathTypes = entity.Get <IList <int> >("PathType"); int index = -1; for (int i = 0; i < elementIds.Count; i++) { try { //int intValue = Convert.ToInt32(cell); if (elementIds[i].IntegerValue == selectedLinkData.ElementId) { index = i; } } catch { } } if (index >= 0) { elementIds.RemoveAt(index); paths.RemoveAt(index); worksheets.RemoveAt(index); dateTimes.RemoveAt(index); pathTypes.RemoveAt(index); Transaction trans = new Transaction(doc, "Convert Excel Document to Import"); trans.Start(); if (elementIds.Count > 0) { entity.Set <IList <ElementId> >("ScheduleId", elementIds); entity.Set <IList <string> >("ExcelFilePath", paths); entity.Set <IList <string> >("WorksheetName", worksheets); entity.Set <IList <string> >("DateTime", dateTimes); entity.Set <IList <int> >("PathType", pathTypes); ds.SetEntity(entity); } else { // Delete the entity data ds.DeleteEntity(schema); doc.Delete(ds.Id); } trans.Commit(); BuildTable(); } } } } }
private void ReloadFromButton_Click(object sender, RoutedEventArgs e) { //DataRowView selectedRow = (DataRowView)linkDataGrid.SelectedItems[0]; LinkData selectedRow = (LinkData)linkDataGrid.SelectedItems[0]; if (selectedRow != null) { // Find an Excel File System.Windows.Forms.OpenFileDialog openDlg = new System.Windows.Forms.OpenFileDialog() { Title = "Reload From an Excel File", Filter = "Excel Files (*.xls; *.xlsx)|*.xls;*.xlsx", RestoreDirectory = true }; System.Windows.Forms.DialogResult result = openDlg.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { string excelFilePath = openDlg.FileName; if (System.IO.File.Exists(excelFilePath)) { // read the Excel file and create the schedule Excel.Application excelApp = new Excel.Application(); Excel.Workbook workbook = excelApp.Workbooks.Open(excelFilePath); Excel.Sheets wbWorksheets = workbook.Worksheets; List <WorksheetObject> worksheetObjs = new List <WorksheetObject>(); foreach (Excel.Worksheet ws in wbWorksheets) { WorksheetObject wo = new WorksheetObject(); string name = ws.Name; wo.Name = name; Excel.Range range = ws.UsedRange; try { range.CopyPicture(Excel.XlPictureAppearance.xlPrinter, Excel.XlCopyPictureFormat.xlBitmap); if (Clipboard.GetDataObject() != null) { IDataObject data = Clipboard.GetDataObject(); if (data.GetDataPresent(DataFormats.Bitmap)) { System.Drawing.Image img = (System.Drawing.Image)data.GetData(DataFormats.Bitmap, true); wo.Image = img; } } } catch { } worksheetObjs.Add(wo); } // Pop up the worksheet form WorksheetSelectForm wsForm = new WorksheetSelectForm(worksheetObjs, this, doc); wsForm.ShowDialog(); if (wsForm.DialogResult.HasValue && wsForm.DialogResult.Value) { for (int i = 0; i < elementIds.Count; i++) { try { int intValue = selectedRow.ElementId; if (elementIds[i].IntegerValue == intValue) { // read and reload the file. Scheduler creator = new Scheduler(); creator.ModifySchedule(doc, elementIds[i], excelFilePath, worksheetObj.Name, "Reload Excel Schedule", pathTypes[i], contentOnly); string docPath; if (doc.IsWorkshared) { docPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(doc.GetWorksharingCentralModelPath()); } else { docPath = doc.PathName; } if ((PathType)pathTypes[i] == PathType.Relative) { paths[i] = PathExchange.GetRelativePath(excelFilePath, docPath); } else { paths[i] = excelFilePath; } worksheets[i] = worksheetObj.Name; System.IO.FileInfo fi = new System.IO.FileInfo(excelFilePath); dateTimes[i] = fi.LastWriteTimeUtc.ToString(); // Read the schema information Autodesk.Revit.DB.ExtensibleStorage.Schema schema = Autodesk.Revit.DB.ExtensibleStorage.Schema.Lookup(schemaGuid); if (schema != null) { Autodesk.Revit.DB.ExtensibleStorage.Entity entity = null; DataStorage ds = SchemaManager.GetDataStorage(doc); try { entity = ds.GetEntity(schema); } catch { } if (entity != null) { Transaction trans = new Transaction(doc, "Update Excel Document"); trans.Start(); entity.Set <IList <string> >("ExcelFilePath", paths); entity.Set <IList <string> >("WorksheetName", worksheets); entity.Set <IList <string> >("DateTime", dateTimes); entity.Set <IList <int> >("PathType", pathTypes); ds.SetEntity(entity); trans.Commit(); BuildTable(); } } } } catch { } } } try { workbook.Close(); Marshal.ReleaseComObject(worksheets); //Marshal.ReleaseComObject(worksheet); Marshal.ReleaseComObject(workbook); excelApp.Quit(); Marshal.ReleaseComObject(excelApp); } catch { } } } } }