Exemplo n.º 1
0
        public static List <SSProp> GetCustomProperties(this IAcSmComponent comp, bool removeProps = false,
                                                        SheetSet ss = null)
        {
            var cpb          = comp.GetCustomPropertyBag();
            var props        = new List <SSProp>();
            var cpbPropNames = new List <string>();
            var cpbList      = SsToList(cpb.GetPropertyEnumerator(), e =>
            {
                e.Next(out var propName, out var item);
                cpbPropNames.Add(propName);
                return(item);
            }).ToList();

            for (var i = 0; i < cpbList.Count; i++)
            {
                var cpbItem  = cpbList[i];
                var propName = cpbPropNames[i];
                var flags    = cpbItem.GetFlags();
                if (flags != PropertyFlags.CUSTOM_SHEETSET_PROP && flags != PropertyFlags.CUSTOM_SHEET_PROP)
                {
                    continue;
                }

                var value = cpbItem.GetValue()?.ToString();
                var prop  = new SSProp
                {
                    Name  = propName,
                    Value = value,
                    Type  = GetPropType(flags)
                };
                props.Add(prop);
                if (removeProps)
                {
                    if (flags == PropertyFlags.CUSTOM_SHEET_PROP && ss != null)
                    {
                        // Удалить это свойство во всех листах
                        var sheets = ss.Nodes.SelectMany(s => s.GetSheets());
                        foreach (var sheet in sheets)
                        {
                            try
                            {
                                sheet.sheet.GetCustomPropertyBag().SetProperty(propName, null);
                            }
                            catch
                            {
                                //
                            }
                        }
                    }

                    cpb.SetProperty(propName, null);
                }
            }

            return(props);
        }
Exemplo n.º 2
0
        public static AcSmCustomPropertyValue GetProperty(this IAcSmComponent comp, string propName)
        {
            var bag = comp.GetCustomPropertyBag();

            return(bag.GetProperty(propName));
        }