Beispiel #1
0
        void FillSourceNameList()
        {
            // nothing selected
            if (listObjectType.SelectedIndex == -1)
            {
                return;
            }

            listProperties.Items.Clear();

            KeyValuePair <RXClass, List <ObjectId> > pair = (KeyValuePair <RXClass, List <ObjectId> >)listObjectType.Items[listObjectType.SelectedIndex];

            string[] sourceNames = PropertyDataServices.FindAutomaticSourceNames(pair.Key.Name, ScheduleSample.GetDatabase());

            StringCollection selectedNames = null;

            if (runtimeData.classPropertiesMap.ContainsKey(pair.Key))
            {
                selectedNames = runtimeData.classPropertiesMap[pair.Key];
            }

            foreach (string name in sourceNames)
            {
                if (selectedNames == null)
                {
                    listProperties.Items.Add(name);
                }
                else
                {
                    listProperties.Items.Add(name, selectedNames.Contains(name));
                }
            }
        }
Beispiel #2
0
        // Property sets
        public static bool AddStairPropertySetToSolid(Solid3d sol)
        {
            bool   result = false;
            Editor ed     = Application.DocumentManager.MdiActiveDocument.Editor;

            ObjectId psdId = GetPropertySetDefinitionIdByName(MyPlugin.psdName);

            // Create property set definition if not existing
            if (psdId == ObjectId.Null)
            {
                MyFunctions.CreateStairPropertySetDefinition(MyPlugin.psdName);
                ed.WriteMessage("\n Property set defenition ALCStairSolid created");
            }

            using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                try
                {
                    Autodesk.AutoCAD.DatabaseServices.DBObject dbobj = tr.GetObject(sol.Id, OpenMode.ForWrite);
                    PropertyDataServices.AddPropertySet(dbobj, psdId);
                    result = true;
                }
                catch
                {
                    result = false;
                    ed.WriteMessage("\n AddStairPropertySetToSolid function failed");
                }
                tr.Commit();
                return(result);
            }
        }
Beispiel #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);
            }
        }
        public static void attachpropertysetstoobjects()
        {
            DocumentCollection docCol   = Application.DocumentManager;
            Database           localDb  = docCol.MdiActiveDocument.Database;
            Editor             ed       = docCol.MdiActiveDocument.Editor;
            Document           doc      = docCol.MdiActiveDocument;
            CivilDocument      civilDoc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;

            //Reference ODTables
            Tables tables = HostMapApplicationServices.Application.ActiveProject.ODTables;
            DictionaryPropertySetDefinitions dictPropSetDef = new DictionaryPropertySetDefinitions(localDb);

            using (Transaction tx = localDb.TransactionManager.StartTransaction())
            {
                //Change here to add other types of objects
                HashSet <Entity> ents = new HashSet <Entity>();
                ents.UnionWith(localDb.HashSetOfType <Line>(tx));
                ents.UnionWith(localDb.HashSetOfType <Spline>(tx));
                ents.UnionWith(localDb.HashSetOfType <DBPoint>(tx));
                ents.UnionWith(localDb.HashSetOfType <Polyline>(tx));
                ents.UnionWith(localDb.HashSetOfType <Polyline3d>(tx));
                ents.UnionWith(localDb.HashSetOfType <BlockReference>(tx));
                //ents = ents.Where(x => x.Layer == "0-FJV_fremtid").ToHashSet();

                foreach (Entity ent in ents)
                {
                    using (Records records =
                               tables.GetObjectRecords(0, ent.Id, Autodesk.Gis.Map.Constants.OpenMode.OpenForRead, false))
                    {
                        int recordsCount = records.Count;
                        for (int i = 0; i < recordsCount; i++)
                        {
                            Record record      = records[i];
                            int    recordCount = record.Count;
                            string tableName   = record.TableName;

                            //Attach correct property set to entity
                            Oid dictId = dictPropSetDef.GetAt(tableName);
                            if (dictId == Oid.Null)
                            {
                                ed.WriteMessage($"\nODTable {tableName} does not have corresponding propertyset!" +
                                                $"Create propertysets first.");
                                tx.Abort();
                                return;
                            }
                            //Add property set to the object
                            ent.CheckOrOpenForWrite();
                            PropertyDataServices.AddPropertySet(ent, dictId);
                        }
                    }
                }
                tx.Commit();
                prdDbg("Finished!");
            }
        }
Beispiel #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);
         }
     }
 }
        public static void SetParameters(this Grevit.Types.Component component, DBObject dbobject)
        {
            Document    doc = Application.DocumentManager.MdiActiveDocument;
            Database    db  = doc.Database;
            Transaction tr  = db.TransactionManager.StartTransaction();

            using (tr)
            {
                List <Grevit.Types.Parameter> parameters = component.parameters;

                if (parameters != null && parameters.Count > 0)
                {
                    ObjectIdCollection source_setIds = PropertyDataServices.GetPropertySets(dbobject);

                    foreach (Grevit.Types.Parameter param in parameters)
                    {
                        foreach (ObjectId source_id in source_setIds)
                        {
                            PropertySet source_pset            = (PropertySet)tr.GetObject(source_id, OpenMode.ForWrite, false, false);
                            PropertySetDataCollection allProps = source_pset.PropertySetData;
                            foreach (PropertySetData ii in allProps)
                            {
                                int    id    = ii.Id;
                                string name  = source_pset.PropertyIdToName(id);
                                object value = source_pset.GetAt(id);

                                if (name == param.name)
                                {
                                    if (value.GetType() == typeof(string))
                                    {
                                        source_pset.SetAt(id, param.value);
                                    }
                                    if (value.GetType() == typeof(double))
                                    {
                                        source_pset.SetAt(id, param.value);
                                    }
                                    if (value.GetType() == typeof(int))
                                    {
                                        source_pset.SetAt(id, param.value);
                                    }
                                    if (value.GetType() == typeof(bool))
                                    {
                                        source_pset.SetAt(id, param.value);
                                    }
                                }
                            }
                        }
                    }
                }

                tr.Commit();
            }
        }
Beispiel #7
0
        public static bool IsStairPropertySetOnSolid(Solid3d sol)
        {
            bool result = false;

            using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                ObjectIdCollection setIds = PropertyDataServices.GetPropertySets(sol);
                if (setIds.Count > 0)
                {
                    foreach (ObjectId id in setIds)
                    {
                        PropertySet pset = (PropertySet)id.GetObject(OpenMode.ForRead);
                        if (pset.PropertySetDefinitionName == MyPlugin.psdName)
                        {
                            result = true;
                            break;
                        }
                    }
                }
                tr.Commit();
            }
            return(result);
        }
Beispiel #8
0
        private Dictionary <string, Dictionary <string, object> > GetPropertySets(DBObject o)
        {
            var propertySetsDTO = new Dictionary <string, Dictionary <string, object> >();
            var propertySetIds  = PropertyDataServices.GetPropertySets(o);

            foreach (ObjectId propertySetId in propertySetIds)
            {
                using (Transaction transProp = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
                {
                    using (PropertySet propertySet = transProp.GetObject(propertySetId, OpenMode.ForWrite) as PropertySet)
                    {
                        var propertySetDTO = new Dictionary <string, object>();
                        propertySetsDTO.Add(propertySet.PropertySetDefinitionName, propertySetDTO);
                        foreach (PropertySetData propertySetData in propertySet.PropertySetData)
                        {
                            propertySetDTO.Add(propertySet.PropertyIdToName(propertySetData.Id), propertySetData.GetData());
                        }
                    }
                }
            }

            return(propertySetsDTO);
        }
Beispiel #9
0
        public static bool SetStairPropertiesToSolid(Solid3d sol, BaseStairObject bso)
        {
            bool result = false;

            if (!IsStairPropertySetOnSolid(sol))
            {
                AddStairPropertySetToSolid(sol);
            }

            using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                ObjectIdCollection setIds = PropertyDataServices.GetPropertySets(sol);
                if (setIds.Count > 0)
                {
                    foreach (ObjectId id in setIds)
                    {
                        PropertySet pset = (PropertySet)id.GetObject(OpenMode.ForWrite);
                        if (pset.PropertySetDefinitionName == MyPlugin.psdName && pset.IsWriteEnabled)
                        {
                            // Get the ObjectID of the property set definition by name
                            // Get the value of the property definition
                            pset.SetAt(pset.PropertyNameToId("name"), bso.Name);
                            pset.SetAt(pset.PropertyNameToId("_tread"), bso.Tread);
                            pset.SetAt(pset.PropertyNameToId("_riser"), bso.Riser);
                            pset.SetAt(pset.PropertyNameToId("_landing"), bso.Landing);
                            pset.SetAt(pset.PropertyNameToId("_width"), bso.Width);
                            pset.SetAt(pset.PropertyNameToId("_slope"), bso.Slope);
                            pset.SetAt(pset.PropertyNameToId("_steps"), bso.Steps);
                            result = true;
                            break;
                        }
                    }
                }
                tr.Commit();
            }
            return(result);
        }
Beispiel #10
0
        public static BaseStairObject GetStairPropertiesFromSolid(Solid3d sol)
        {
            BaseStairObject retBso = null;

            using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                ObjectIdCollection setIds = PropertyDataServices.GetPropertySets(sol);
                if (setIds.Count > 0)
                {
                    foreach (ObjectId id in setIds)
                    {
                        PropertySet pset = (PropertySet)id.GetObject(OpenMode.ForRead);

                        if (pset.PropertySetDefinitionName == MyPlugin.psdName)
                        {
                            // Get the ObjectID of the property set definition by name
                            // Get the value of the property definition
                            BaseStairObject bso = new BaseStairObject
                            {
                                Id      = sol.Id,
                                Name    = Convert.ToString(pset.GetAt(pset.PropertyNameToId("name"))),
                                Steps   = Convert.ToInt32(pset.GetAt(pset.PropertyNameToId("_steps"))),
                                Tread   = Convert.ToDouble(pset.GetAt(pset.PropertyNameToId("_tread"))),
                                Riser   = Convert.ToDouble(pset.GetAt(pset.PropertyNameToId("_riser"))),
                                Landing = Convert.ToDouble(pset.GetAt(pset.PropertyNameToId("_landing"))),
                                Width   = Convert.ToDouble(pset.GetAt(pset.PropertyNameToId("_width"))),
                                Slope   = Convert.ToDouble(pset.GetAt(pset.PropertyNameToId("_slope")))
                            };
                            retBso = bso;
                        }
                    }
                }
                tr.Commit();
            }
            return(retBso);
        }
Beispiel #11
0
        public void AddPropertySet()
        {
            Database db       = HostApplicationServices.WorkingDatabase;
            ObjectId layoutId = SymbolUtilityServices.GetBlockModelSpaceId(db);

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var bt  = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                var btr = tr.GetObject(layoutId, OpenMode.ForRead) as BlockTableRecord;

                btr.Name = "bimcad";
                Line line = new Line(Point3d.Origin, new Point3d(10, 15, 0));

                PropertySetDefinition psDef = new PropertySetDefinition();

                PropertyDefinition propertyDef = new PropertyDefinition();
                propertyDef.DataType = Autodesk.Aec.PropertyData.DataType.Text;
                propertyDef.Id       = 1;

                psDef.Definitions.Add(propertyDef);
                PropertySet ps = new PropertySet();
                ps.PropertySetDefinition = psDef.Id;

                ps.SetAt(propertyDef.Id, "hello World");

                PropertyDataServices.AddPropertySet(line, ps.Id);
                Circle circle = new Circle(Point3d.Origin, Vector3d.ZAxis, 10);

                btr.AppendEntity(line);
                btr.AppendEntity(circle);

                ObjectId id = bt.Add(btr);
                tr.AddNewlyCreatedDBObject(btr, true);
                tr.Commit();
            }
        }
        public static void populatepropertysetswithoddata()
        {
            DocumentCollection docCol   = Application.DocumentManager;
            Database           localDb  = docCol.MdiActiveDocument.Database;
            Editor             ed       = docCol.MdiActiveDocument.Editor;
            Document           doc      = docCol.MdiActiveDocument;
            CivilDocument      civilDoc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;

            //Reference ODTables
            Tables tables = HostMapApplicationServices.Application.ActiveProject.ODTables;
            DictionaryPropertySetDefinitions dictPropSetDef = new DictionaryPropertySetDefinitions(localDb);

            using (Transaction tx = localDb.TransactionManager.StartTransaction())
            {
                try
                {
                    //I need to work with 3d polylines
                    //Change here to add other types of objects
                    HashSet <Entity> ents = new HashSet <Entity>();
                    ents.UnionWith(localDb.HashSetOfType <Line>(tx));
                    ents.UnionWith(localDb.HashSetOfType <Spline>(tx));
                    ents.UnionWith(localDb.HashSetOfType <DBPoint>(tx));
                    ents.UnionWith(localDb.HashSetOfType <Polyline>(tx));
                    ents.UnionWith(localDb.HashSetOfType <Polyline3d>(tx));
                    ents.UnionWith(localDb.HashSetOfType <BlockReference>(tx));
                    //ents = ents.Where(x => x.Layer == "0-FJV_fremtid").ToHashSet();

                    foreach (Entity ent in ents)
                    {
                        ObjectIdCollection psIds = PropertyDataServices.GetPropertySets(ent);
                        List <PropertySet> pss   = new List <PropertySet>();
                        foreach (Oid oid in psIds)
                        {
                            pss.Add(oid.Go <PropertySet>(tx, OpenMode.ForWrite));
                        }

                        using (Records records =
                                   tables.GetObjectRecords(0, ent.Id, Autodesk.Gis.Map.Constants.OpenMode.OpenForRead, false))
                        {
                            int recordsCount = records.Count;
                            for (int i = 0; i < recordsCount; i++)
                            {
                                Record record    = records[i];
                                string tableName = record.TableName;
                                //Specific to my implementation
                                if (tableName == "IdRecord")
                                {
                                    continue;
                                }

                                PropertySet propertySet = pss.Find(x => x.PropertySetDefinitionName == tableName);
                                if (propertySet == null)
                                {
                                    tx.Abort();
                                    ed.WriteMessage($"\nPropertySet with the name {tableName} could not be found!");
                                    return;
                                }

                                Table            table = tables[tableName];
                                FieldDefinitions fDefs = table.FieldDefinitions;
                                int fieldsCount        = fDefs.Count;

                                for (int j = 0; j < fieldsCount; j++)
                                {
                                    FieldDefinition fDef      = fDefs[j];
                                    string          fieldName = fDef.Name;

                                    int      columnIndex = fDefs.GetColumnIndex(fieldName);
                                    MapValue value       = record[columnIndex];

                                    int psIdCurrent = propertySet.PropertyNameToId(fieldName);
                                    propertySet.SetAt(psIdCurrent, GetMapValueData(value));
                                }
                            }
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    tx.Abort();
                    ed.WriteMessage(ex.ToString());
                    return;
                }
                tx.Commit();
                prdDbg("Finished!");
            }
        }