コード例 #1
0
        private static ScheduleTable CreateScheduleTable(UiData uiData, ObjectId propertySetDefinitionId, ObjectId styleId, Transaction trans)
        {
            Database         db  = ScheduleSample.GetDatabase();
            BlockTableRecord btr = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

            ScheduleTable scheduleTable = new ScheduleTable();

            scheduleTable.SetToStandard(db);
            scheduleTable.SetDatabaseDefaults(db);
            scheduleTable.StyleId = styleId;
            scheduleTable.SetDefaultLayer();

            btr.AppendEntity(scheduleTable);
            trans.AddNewlyCreatedDBObject(scheduleTable, true);

            ObjectIdCollection selectionSet = new ObjectIdCollection();

            foreach (List <ObjectId> idSetByObjectType in uiData.classObjectIdsMap.Values)
            {
                foreach (ObjectId id in idSetByObjectType)
                {
                    selectionSet.Add(id);
                }
            }

            scheduleTable.SetSelectionSet(selectionSet, new ObjectIdCollection());
            scheduleTable.AutomaticUpdate = true;

            return(scheduleTable);
        }
コード例 #2
0
        // 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);
        }
コード例 #3
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);
            }
        }
コード例 #4
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);
        }
コード例 #5
0
 private static void AddPropertySetToObjects(UiData uiData, ObjectId propertySetDefinitionId, Transaction trans)
 {
     foreach (List <ObjectId> ids in uiData.classObjectIdsMap.Values)
     {
         foreach (ObjectId id in ids)
         {
             Autodesk.AutoCAD.DatabaseServices.DBObject obj = trans.GetObject(id, OpenMode.ForWrite) as Autodesk.AutoCAD.DatabaseServices.DBObject;
             PropertyDataServices.RemovePropertySet(obj, propertySetDefinitionId);
             PropertyDataServices.AddPropertySet(obj, propertySetDefinitionId);
         }
     }
 }
コード例 #6
0
        private static PropertySetDefinition CreatePropertySetDefinition(UiData uiData, Transaction trans)
        {
            Database db = ScheduleSample.GetDatabase();

            string           psdName   = uiData.propertySetDefinitionName;
            StringCollection appliesTo = new StringCollection();

            foreach (RXClass rc in uiData.classPropertiesMap.Keys)
            {
                appliesTo.Add(rc.Name);
            }

            // create the property set definition
            PropertySetDefinition psd = new PropertySetDefinition();

            psd.SetToStandard(db);
            psd.SubSetDatabaseDefaults(db);
            psd.AlternateName = psdName;
            psd.IsLocked      = false;
            psd.IsVisible     = true;
            psd.IsWriteable   = true;

            psd.SetAppliesToFilter(appliesTo, false);

            Dictionary <string, List <RXClass> > propertyClassesMap = uiData.classPropertiesMap.GroupClassesByProperty();

            foreach (string propertyName in propertyClassesMap.Keys)
            {
                PropertyDefinition propDef = new PropertyDefinition();
                propDef.SetToStandard(db);
                propDef.SubSetDatabaseDefaults(db);
                propDef.Name        = propertyName;
                propDef.Automatic   = true;
                propDef.Description = propertyName;
                propDef.IsVisible   = true;
                propDef.IsReadOnly  = true;
                foreach (RXClass objectType in propertyClassesMap[propertyName])
                {
                    propDef.SetAutomaticData(objectType.Name, propertyName);
                }
                psd.Definitions.Add(propDef);
            }

            DictionaryPropertySetDefinitions propDefs = new DictionaryPropertySetDefinitions(db);

            propDefs.AddNewRecord(uiData.propertySetDefinitionName, psd);
            trans.AddNewlyCreatedDBObject(psd, true);
            return(psd);
        }