I hope the screencast makes it more clear.
What I'm trying to do is after I set my location, coordinate system and the drawing units and you click on next.
AutoCAD asks = Select a point for the location <0,0,0> :
Default its 0,0,0. But I want this point to be on <147500,218590,0>
I want to be able to to that in the code.
In the code Kean sets the geolocation first geoPt (so thats the geoposition), and I thought that the wcsPt was the insertion point of that Geopoint.
But when I look at the result of the code and the result when I do it manually its not the samen. See screenshot.
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
namespace GeoLocationAPI
{
public class Commands
{
[CommandMethod("IGR")]
public void InsertGeoRef()
{
var doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null)
return;
var ed = doc.Editor;
var db = doc.Database;
var msId = SymbolUtilityServices.GetBlockModelSpaceId(db);
// Check whether the drawing already has geolocation data
bool hasGeoData = false;
try
{
var gdId = db.GeoDataObject;
hasGeoData = true;
}
catch { }
if (hasGeoData)
{
ed.WriteMessage("\nDrawing already has geo-location data!");
return;
}
var data = new GeoLocationData();
data.BlockTableRecordId = msId;
data.PostToDb();
data.CoordinateSystem = "Belge72.Lambert72a";
data.TypeOfCoordinates = TypeOfCoordinates.CoordinateTypeGrid
var geoPt = new Point3d(51.277178, 4.332933, 0);
var wcsPt = new Point3d(147500,218590,0); //data.TransformFromLonLatAlt(geoPt);
data.DesignPoint = wcsPt;
data.ReferencePoint = geoPt;
ed.Command("_.GEOMAP", "_AERIAL");
using (var tr = db.TransactionManager.StartTransaction())
{
var ms =
tr.GetObject(msId, OpenMode.ForWrite) as BlockTableRecord;
if (ms != null)
{
var circle = new Circle(wcsPt, Vector3d.ZAxis, 7000);
circle.ColorIndex = 1;
ms.AppendEntity(circle);
tr.AddNewlyCreatedDBObject(circle, true);
}
tr.Commit();
}
ed.Command("_.ZOOM", "_OBJECT", "_L", "");
}
}
}