Exemplo n.º 1
0
        public void ShowSample()
        {
            ObjectIdCollection ids = PickObjectSet("Please pick the objects to be scheduled:");

            if (ids.Count == 0)
            {
                return;
            }

            Dictionary <RXClass, List <ObjectId> > classDictionary           = new Dictionary <RXClass, List <ObjectId> >();
            Dictionary <RXClass, List <ObjectId> > ineligibleClassDictionary = new Dictionary <RXClass, List <ObjectId> >();
            StringCollection eligibleClassNames = new StringCollection();

            eligibleClassNames.AddRange(PropertyDataServices.FindEligibleClassNames());
            foreach (ObjectId id in ids)
            {
                if (!eligibleClassNames.Contains(id.ObjectClass.Name))
                {
                    if (!ineligibleClassDictionary.ContainsKey(id.ObjectClass))
                    {
                        ineligibleClassDictionary[id.ObjectClass] = new List <ObjectId>();
                    }

                    ineligibleClassDictionary[id.ObjectClass].Add(id);
                }
                else
                {
                    if (!classDictionary.ContainsKey(id.ObjectClass))
                    {
                        classDictionary[id.ObjectClass] = new List <ObjectId>();
                    }

                    classDictionary[id.ObjectClass].Add(id);
                }
            }

            if (classDictionary.Keys.Count == 0)
            {
                GetEditor().WriteMessage("No eligible object is selected. Schedule table sample will now quit.");
                return;
            }

            UiData runtimeData = new UiData();

            runtimeData.classObjectIdsMap           = classDictionary;
            runtimeData.ineligibleClassObjectIdsMap = ineligibleClassDictionary;
            WizardSheetPropertySetDefinition sheetPsd = new WizardSheetPropertySetDefinition();
            WizardSheetScheduleTableStyle    sheetSts = new WizardSheetScheduleTableStyle();
            WizardSheetSummary sheetSummary           = new WizardSheetSummary();
            WizardManager      wizard = new WizardManager();

            wizard.AddSheet(sheetPsd);
            wizard.AddSheet(sheetSts);
            wizard.AddSheet(sheetSummary);
            wizard.RuntimeData = runtimeData;
            if (wizard.ShowWizard() == System.Windows.Forms.DialogResult.OK)
            {
                ScheduleTableCreateResult result = ScheduleTableCreateEx.CreateScheduleTable(runtimeData);
            }
        }
Exemplo n.º 2
0
        /// <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);
        }