Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory"); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); ws = workspaceFactory.OpenFromFile(pGdbSource.Dir + "\\" + pGdbSource.File, 0); if (ws != null) { IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)ws; IFeatureLayer featureLayer = new FeatureLayerClass(); string FCName = (pGdbSource.BrowseName != "") ? pGdbSource.BrowseName : pGdbSource.ItemName; featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass(FCName); ILayer layer = (ILayer)featureLayer; if ((featureLayer.FeatureClass.FeatureType == esriFeatureType.esriFTAnnotation) && (featureLayer is FeatureLayerClass)) { // Get the GeometryDef from the feature class's shape field. String shapeFieldName = featureLayer.FeatureClass.ShapeFieldName; int shapeFieldIndex = featureLayer.FeatureClass.FindField(shapeFieldName); IFields fields = featureLayer.FeatureClass.Fields; IField shapeField = fields.get_Field(shapeFieldIndex); IGeometryDef geometryDef = shapeField.GeometryDef; IAnnotateLayerPropertiesCollection annotateLayerPropsCollection = (featureLayer as FeatureLayerClass).AnnotationProperties; // Create a graphics layer scale object. IGraphicsLayerScale graphicsLayerScale = new GraphicsLayerScaleClass(); try { graphicsLayerScale.ReferenceScale = mxDocument.ActiveView.FocusMap.MapScale; } catch (Exception ex) { graphicsLayerScale.ReferenceScale = 0.0; } graphicsLayerScale.Units = mxDocument.ActiveView.FocusMap.MapUnits; // Create the overposter properties for the standard label engine. IOverposterProperties overposterProperties = new BasicOverposterPropertiesClass(); ISymbolCollection symbolCollection = new SymbolCollectionClass(); ISymbolCollection2 symbolCollection2 = (ISymbolCollection2)symbolCollection; // Create the annotation layer factory. IAnnotationLayerFactory annotationLayerFactory = new FDOGraphicsLayerFactoryClass(); IDataset pDataset = (featureLayer as FeatureLayerClass) as IDataset; // Create the annotation feature class and an annotation layer for it. IAnnotationLayer annotationLayer = annotationLayerFactory.CreateAnnotationLayer (featureWorkspace, pDataset as IFeatureDataset, FCName, geometryDef, null, annotateLayerPropsCollection, graphicsLayerScale, symbolCollection, false, false, false, true, overposterProperties, "configKeyword"); // Get the feature class from the feature layer. featureLayer = (IFeatureLayer)annotationLayer;
Solved! Go to Solution.
IAnnotationLayerFactory annotationLayerFactory = new FDOGraphicsLayerFactoryClass(); IAnnotationLayer annotationLayer = annotationLayerFactory.OpenAnnotationLayer(featureWorkspace, null, FCName);
IAnnotationLayerFactory annotationLayerFactory = new FDOGraphicsLayerFactoryClass(); IAnnotationLayer annotationLayer = annotationLayerFactory.OpenAnnotationLayer(featureWorkspace, null, FCName);