Author Topic: Implement TagAddSelected - anchored annotation for Aec  (Read 2266 times)

0 Members and 1 Guest are viewing this topic.

kaefer

  • Guest
Implement TagAddSelected - anchored annotation for Aec
« on: November 16, 2011, 05:03:34 AM »
Here's an attempt to do the Aec TagAddSelected command in C#.

That is, select a MV-Block reference on screen, or enter the name of a MV-Block definition and a LayerKey manually, and after placing the resultant tags then add the required property sets without further user interaction. I need a little peer review to confirm that I'm not completely off the tracks with this. I'm not using a selection set, but do loop over the entity prompt. The jigs are shamelessly stolen from gile, with many thanks.

I think my code is bug compatible with regard to UCS settings that result in non-annotative tags, but not quite bug compatible when the aec object does not support the property set (will add it regardless).  The following code does the gathering of the property set names; the complete source is attached.

Code: [Select]
        // Check all display representations of the MVBlock definition for
        // property sets that are to be added to the anntotated Geo
        void AddPropertySetsToGeo()
        {
            aecDb.DBObject style = geo.StyleId.GetObject<aecDb.DBObject>();

            IEnumerable<string> pSetNamesFromStyle =
                from pSet in PropertyDataServices.GetPropertySets(style).GetObjects<PropertySet>()
                select pSet.PropertySetDefinitionName.ToUpper();

            IEnumerable<string> pSetNamesPresent =
                from pSet in PropertyDataServices.GetPropertySets(geo).GetObjects<PropertySet>()
                select pSet.Name.ToUpper();

            string[] pSetNamesToAdd =
                br.BlockDefId
                .GetObject<aecDb.MultiViewBlockDefinition>()
                .DisplayRepresentationDefinitions
                .Cast<aecDb.MultiViewBlockDisplayRepresentationDefinition>()
                .SelectMany(mvbdrd =>
                    mvbdrd.ViewDefinitions
                    .Cast<aecDb.MultiViewBlockViewDefinition>())
                .Select(mvbvd => mvbvd.BlockId.GetObject<BlockTableRecord>())
                .Where(btr => btr.HasAttributeDefinitions)
                .SelectMany(btr => btr.GetObjects<AttributeDefinition>())
                .Where(ad => !ad.Constant)
                .Select(ad => ad.Tag.Split(':'))
                .Where(sa => sa.Length == 2)
                .Select(sa => sa[0].ToUpper())
                .Except(pSetNamesFromStyle.Concat(pSetNamesPresent))
                .ToArray();

            if (pSetNamesToAdd.Length > 0)
            {
                DictionaryPropertySetDefinitions dictDefs =
                    new DictionaryPropertySetDefinitions(db);
                geo.UpgradeOpen();
                foreach (string pSetName in pSetNamesToAdd)
                {
                    if (dictDefs.Has(pSetName, tr))
                        PropertyDataServices.AddPropertySet(
                            geo, dictDefs.GetAt(pSetName));
                    else
                        ed.WriteMessage(
                            "\nProperty set \"{0}\" not found. ",
                            pSetName);
                }
            }
        }