Ejemplo n.º 1
0
        public void OnAfterLoadDiagram(ISchematicInMemoryDiagram inMemoryDiagram)
        {
            // if add-in is not enabled then quit
            if (State != ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled)
            {
                return;
            }

            IEnumSchematicInMemoryFeature enumSchemElements;
            ISchematicInMemoryFeature     schemElement;
            string        nameRelatedCN = "";
            int           numRelatedOID = 0;
            IFeatureClass esriFeatureClass;
            IFeature      esriFeature;
            ISchematicInMemoryFeatureLinkerEdit schemFeatureLinkerEdit = (ISchematicInMemoryFeatureLinkerEdit) new SchematicLinker();
            ISchematicObjectClass        myObjectType;
            ISchematicAttribute          schemAttributeCID;
            ISchematicAttribute          schemAttributeOID;
            ISchematicAttributeContainer schemAttributeContainer;

            IWorkspace esriWorkspace;

            Microsoft.VisualBasic.Collection colFCByName;

            colFCByName   = new Microsoft.VisualBasic.Collection();
            esriWorkspace = inMemoryDiagram.SchematicDiagramClass.SchematicDataset.SchematicWorkspace.Workspace;

            // Retrieve all schematic element of the diagram

            enumSchemElements = (IEnumSchematicInMemoryFeature)inMemoryDiagram.SchematicInMemoryFeatures;
            enumSchemElements.Reset();

            schemElement = enumSchemElements.Next();
            while (schemElement != null)
            {
                // retrieve attribute
                myObjectType            = schemElement.SchematicElementClass;
                schemAttributeContainer = (ISchematicAttributeContainer)schemElement.SchematicElementClass;
                schemAttributeCID       = schemAttributeContainer.GetSchematicAttribute(AttClassNameName, false);
                schemAttributeOID       = schemAttributeContainer.GetSchematicAttribute(AttObjectIdName, false);
                if (schemAttributeCID != null && schemAttributeOID != null)
                {
                    // get value of attribute
                    nameRelatedCN = schemAttributeCID.GetValue((ISchematicObject)schemElement).ToString();
                    numRelatedOID = System.Convert.ToInt32(schemAttributeOID.GetValue((ISchematicObject)schemElement));

                    // get feature from geodatabase
                    esriFeatureClass = FindFeatureClassByName(esriWorkspace, nameRelatedCN, colFCByName);
                    if (esriFeatureClass != null)
                    {
                        // get feature from FeatureClass
                        esriFeature = esriFeatureClass.GetFeature(numRelatedOID);
                        if (esriFeature != null)
                        {
                            // Associate geographical feature with schematic feature
                            schemFeatureLinkerEdit.Associate(schemElement, esriFeature);
                        }
                    }
                }
                schemElement = enumSchemElements.Next();
            }
            colFCByName.Clear();
            colFCByName = null;
        }