I have implemented this code to create point event layer by xy text file, however I'm wondering how to create a point graphic by xy value?

  • This script draws point graphic by mouse down. When I steer away from the mouse down event and input my xy values manually it does not draw.

  • Using the Point class looks like it might also be a solution, however I'm not sure how to implement this code without getting a null reference error on point.setX line.

Dim point As New Point()
Dim markerElement As New MarkerElement()    

Dim map As IMap = mxdoc.FocusMap

Map.addElement(markerElement, 0)

Any suggestions on how to create a graphic point by xy value?

Thank You


2 Answers 2


In the ArcGIS Resource Center is a discussion about Working with map elements which gives you an example on how to create a Point:

Dim point As IPoint = New PointClass()
point.X = 0
point.Y = 0

Then you can use the AddGraphicToMap snippet to draw the graphic on the map using the supplied colors.

  • I tried your code and still got the NullReference exception not set to an object reference error on point.setX(-100.0) line. Any ideas?
    – artwork21
    Jan 25, 2012 at 16:21
  • @artwork21 I've reworked your code replacing your new Point() with new PointClass(). Feb 2, 2012 at 3:51

What API are you using...it looks like a mix of VB.NET and javascript or according to one of your links. If you are using VB.NET turn on Option Explicit and Option Strict and I'd bet you get some errors.

The IPoint interface doesn't expose 'setX' in .NET. You need to call:

point.X = 0
point.Y = 0

The complete code would look like:

Dim map As ESRI.ArcGIS.Carto.IMap = mxdoc.FocusMap

Dim point As IPoint = New ESRI.ArcGIS.Geometry.Point()
point.SpatialReference = map.SpatialReference
point.X = -100
point.Y = 40

Dim rgbColor As ESRI.ArcGIS.Display.IRgbColor = New ESRI.ArcGIS.Display.RgbColor()
rgbColor.Blue = 200

AddGraphicToMap(map, point, rgbColor, rgbColor)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.