Пример #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 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);
        }