Getting/modifying object coordinates

Getting/modifying object coordinates

Anonymous
Not applicable
1,506 Views
2 Replies
Message 1 of 3

Getting/modifying object coordinates

Anonymous
Not applicable

As part of a utility planning project I need to place a large number of objects on to the map at certain geo-coordinates. I would like to do that by using the C# or VB.Net API of AutoCad Map 2020 but found no way to access/define the coordinate data of an object. On the other hand the coordinates can be easily checked/modified within the AutoCad Map 2020 application under the Modify/Properties menu. Here it is possible to change the x,y coordinate values within the pop-up window's  'Geometry' table and the object 'moves' to the new location.  That is exactly the functionality that I can not find within the .Net API. The following VBA code gives access to the ODTables of an object but the coordinates are not among them:

Dim tables As ObjectData.Tables
tables = activeProj.ODTables

Dim table As ObjectData.Table
table = tables.Item(FieldName)

Dim fieldDefs As ObjectData.FieldDefinitions = table.FieldDefinitions
Dim recs As ObjectData.Records
recs = table.GetObjectTableRecords(0, BlckID, Constants.OpenMode.OpenForRead, True)

Thanks in advance for any hints about accessing the coordinates data.

 

0 Likes
Accepted solutions (1)
1,507 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

I am not sure I understand what you really want to do. What do you mean by "geo-coordinate"? if the said "large number of objects are already in drawing, the coordinate would be X/East and Y/North, (regardless what projected map coordinate system is assigned to the drawing, like UTM83-xx...), right? So, I assume you want to get/modify the coordinates/geometries of entities according to your business requirements. 

 

Since all entities you see in AutoCAD editor are just visual presentation of geometries (with other properties, like layer, color...), if you can access entity via API (be it LISP, VBA/COM, or .NET API), you can have access to all geometric information of an entity, and modify some of them. The geometric information has nothing to do with ObjectData (well, for some business reason, one could use ObjectData to store redundant entity geometry, of course).

 

The convenience provided by Property window, where one can change geometric data of an selected entity, is built on a set of APIs, on which AutoCAD .NET API is based. So, certainly you can change a line's length by changing one of its EndPoint, or you move move it by given displacement, rather easily. By the way, these basic process of using API is from plain AutoCAD API and apply to all AutoCAD verticals. AutoCAD Map add its on API on top of AutoCAD API, dealing map specific operations, such as ObjectData/Classification, map query....

 

Quick .NET API code of getting/modifying a line (assume you have code to asked user to selected a line, and selected 2 points)

 

Public void ModifyLine(ObjectId lineId, Point3d startPt, Point3d endPt)

{

    using (var tran = lineId.Database.TransactionManager.StartTransaction())

    {

        var line = (Line)tran.GetObject(lineId, OpenMode.ForWrite);

 

        // access Line's geometries

       Debug.WriteLine($"Start point => {line.StartPoint.ToString()}"

       Debug.WriteLine($"End point => {line.EndPoint.ToString()}"

 

       // modify Line's geometries

        line.StartPoint = startPoint;

        line.EndPoint = endPoint;

 

        tran.Commit()

    }

}

 

Of course, you can do similar thing with LISP, or VBA.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

Anonymous
Not applicable

Many thanks for your reply. The issue I have raised can be solved on that basis.

0 Likes