AnsweredAssumed Answered

Error w/ XYEventSourceName

Question asked by thewhinton on Nov 19, 2014
Latest reply on Nov 21, 2014 by thewhinton



     I am trying to programmatically access a lyr file and load it to the map. The lyr file is an XY Event Theme built using the 'Make XY Event Layer' tool in ArcToolbox. Accessing the lyr file is no problem, but when I try to get a handle on the event source and load it to the map, I get an error that says 'The XYEventSourceName has not been setup correctly'.


     Here is the code I have for this block of the program, after I get the underlying layer from the lyr file:


if (layer instanceof IFeatureLayer) {


     IDataLayer2 pDLayer = (IDataLayer2) layer


     if (pDLayer.getDataSourceName() instanceof IXYEventSourceName) {


          // Create and populate event properties

          IXYEvent2FieldsProperties props = new IXYEvent2FieldsProperties();




          // Create spatial reference

          ISpatialReferenceFactory refFactory - new SpatialReferenceEnvironment();

          IGeographicCoordinateSystem spatRef = refFactory.createGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1927);


          // Get a name object for source

          IDataset sourceDataset = (IDataset) pDLayer;

          IName sourceDsName = sourceDataset.getFullName();


          // Create an XYEventSourceName

          IXYEventSourceName xySrcNm = new XYEventSourceName();





          // Create the XY Event Source

          IName srcName = (IName) xySrcNm;

          IXYEventSource xyEventSource = (IXYEventSource);




     So it bombs on the command, with the error that the event source name is not setup correctly. I think the problem is in the blue section, but that's just a guess. I have looked through several discussions, and got the gist of the code from Any suggestions are appreciated.