// another way to find the index of a property definition //private static int FindPropertyDefinitionIndex(PropertySetDefinition psd, string propertyName) //{ // PropertyDefinition propDef = new PropertyDefinition(); // propDef.Name = propertyName; // return psd.Definitions.IndexOf(propDef); //} private static ScheduleTableStyle CreateStyle(UiData uiData, PropertySetDefinition psd, Transaction trans) { Database db = ScheduleSample.GetDatabase(); ScheduleTableStyle style = new ScheduleTableStyle(); style.SetToStandard(db); style.SubSetDatabaseDefaults(db); // sets the object type to which the schedule table style applies StringCollection filter = new StringCollection(); foreach (RXClass rc in uiData.classPropertiesMap.Keys) { filter.Add(rc.Name); } style.AppliesToFilter = filter; CreateChildNodes(uiData.headerColumnDesignData, style.Tree, psd, style); //add it into database DictionaryScheduleTableStyle scheduleTableStyleDict = new DictionaryScheduleTableStyle(db); style.Title = uiData.scheduleTableStyleName; scheduleTableStyleDict.AddNewRecord(uiData.scheduleTableStyleName, style); trans.AddNewlyCreatedDBObject(style, true); return(style); }
/// <summary> /// Creates the whole property sets, schedule table style and schedule table in database. /// </summary> /// <param name="uiData">The data saved from the wizard.</param> /// <returns>Returns the object id of the property set definition, schedule table style and schedule table.</returns> public static ScheduleTableCreateResult CreateScheduleTable(UiData uiData) { ScheduleTableCreateResult result = new ScheduleTableCreateResult(); Database db = ScheduleSample.GetDatabase(); DBTransactionManager tm = db.TransactionManager; using (Transaction trans = tm.StartTransaction()) { try { PropertySetDefinition psd = CreatePropertySetDefinition(uiData, trans); result.PropertySetDefinitionId = psd.Id; if (result.PropertySetDefinitionId == ObjectId.Null) { throw (new System.Exception("Failed to create property set definition.")); } ScheduleTableStyle style = CreateStyle(uiData, psd, trans); result.StyleId = style.Id; if (result.StyleId == ObjectId.Null) { throw (new System.Exception("Failed to create property style.")); } AddPropertySetToObjects(uiData, result.PropertySetDefinitionId, trans); ScheduleTable table = CreateScheduleTable(uiData, result.PropertySetDefinitionId, result.StyleId, trans); result.ScheduleTableId = table.Id; if (result.ScheduleTableId == ObjectId.Null) { throw (new System.Exception("Failed to create Schedule Table.")); } Editor editor = ScheduleSample.GetEditor(); PromptPointResult editorResult = editor.GetPoint("Please pick a point to insert the schedule table:"); if (editorResult.Status == PromptStatus.OK) { table.Location = editorResult.Value; table.Scale = 10; trans.Commit(); } else { trans.Abort(); } } catch (System.Exception) { trans.Abort(); return(null); } finally { trans.Dispose(); } } return(result); }
private static ScheduleTableStyleColumn CreateColumn(PropertyClassData nodeData, PropertySetDefinition psd, ScheduleTableStyle style) { Database db = ScheduleSample.GetDatabase(); ScheduleTableStyleColumn column = new ScheduleTableStyleColumn(); column.SetToStandard(db); column.SubSetDatabaseDefaults(db); column.PropertySetDefinitionId = psd.Id; column.ColumnType = ScheduleTableStyleColumnType.Normal; column.Heading = nodeData.DisplayName; column.PropertyId = psd.Definitions.IndexOf(nodeData.PropertyName); return(column); }
private static List <ScheduleTableStyleHeaderNode> CreateChildNodes(List <ColumnHeaderNode> childNodes, ScheduleTableStyleHeaderTree tree, PropertySetDefinition psd, ScheduleTableStyle style) { Database db = ScheduleSample.GetDatabase(); List <ScheduleTableStyleHeaderNode> nodesCreated = new List <ScheduleTableStyleHeaderNode>(); foreach (ColumnHeaderNode childNode in childNodes) { if (childNode.IsColumn) { PropertyClassData data = childNode.ColumnData; ScheduleTableStyleColumn column = CreateColumn(data, psd, style); style.Columns.Add(column); nodesCreated.Add(column); } else if (childNode.IsHeader) { string headerName = childNode.NodeData as string; List <ScheduleTableStyleHeaderNode> myChildren = CreateChildNodes(childNode.Children, tree, psd, style); ScheduleTableStyleHeaderNode header = tree.InsertNode(headerName, tree.Root.Children.Count, tree.Root, myChildren.ToArray()); nodesCreated.Add(header); } else { throw new ArgumentException("Cannot resolve node type properly when creating schedule table style."); } } return(nodesCreated); }