示例#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);
        }
示例#2
0
        public static void AddCustomProperty(this AcSmCustomPropertyBag bag, IAcSmComponent comp,
                                             SSProp prop, SheetSet ss = null)
        {
            var customProp = new AcSmCustomPropertyValue();

            customProp.InitNew(comp);
            customProp.SetFlags(GetPropType(prop.Type));
            customProp.SetValue(prop.Value);
            bag.SetProperty(prop.Name, customProp);
            if (prop.Type == PropType.Sheet && ss != null)
            {
                foreach (var sheet in ss.Nodes.SelectMany(s => s.GetSheets()))
                {
                    var sheetBag = sheet.sheet.GetCustomPropertyBag();
                    sheetBag?.AddCustomProperty(sheet.sheet, prop);
                }
            }
        }