Пример #1
0
        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();
            }
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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);
        }
        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!");
            }
        }