Adding Geopositionmarker To Different Location Through API

By Madhukar Moogala

Recently, I have received a query from an ADN partner about positioning Geomaps on AutoCAD, you can add GeoLocationData to AutoCAD drawing, this geolocation data is stored under Modelspace’s extension dictionary.

To can create programmatically GeoLocationData, please find this helpful blog.

In the current blog we ‘ll see how we can add new position marker to different place in the drawing with Geolocationdata.

At the end of code, I have uploaded a screencast, which shows moving from Autodesk’s Hyderabad Office to Autodesk’s Bangalore Office.

void addMarker(ads_point wcsPoint)
  {
  AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
  if (pDb == NULL)
    return;
 
  AcGePoint3d pt(wcsPoint[0], wcsPoint[1], wcsPoint[2]);
  struct resbuf buf;
  double geoPositionMarkerRaidus = 0.0;
 
  if(acedGetVar(_T("GEOMARKPOSITIONSIZE"), &buf) == RTNORM)
    {
    geoPositionMarkerRaidus = buf.resval.rreal > 0 ?  buf.resval.rreal : 1.0;
    }
  double radius = geoPositionMarkerRaidus;
 
  AcDbSmartObjectPointer pGeoPositionMarker;
  AcDbGeoPositionMarker *tmpMarker = new AcDbGeoPositionMarker(pt, radius, radius/2);
 
  pGeoPositionMarker.acquire(tmpMarker);
  if (eOkVerify(pGeoPositionMarker.openStatus()))
    {
    //set to current layer
    pGeoPositionMarker->setLayer( pDb->clayer() );
    AcDbObjectId modelSpaceId = acdbSymUtil()->blockModelSpaceId(pDb);
 
      {
      AcDbSmartObjectPointer modelSpaceBTR(modelSpaceId, AcDb::kForWrite);
      if (!eOkVerify(modelSpaceBTR.openStatus())) return ;
 
      //add position marker into db
      Acad::ErrorStatus es = Acad::eOk;
      AcDbObjectId newPositionMarkerId;
      es = modelSpaceBTR->appendAcDbEntity( newPositionMarkerId, pGeoPositionMarker);
      if (!eOkVerify(es))
        {
        return;
        }
      }
 
 
    }
  }
void InsertMarker()
  {
 
  CString prompt[2];
  prompt[0] = _T("Latitude");
  prompt[1] = _T("Longitude");
  CString keyword = _T("eXit");
  int limits[] = {90,180};
  double latLon[2];
  TCHAR result[133];
  int i=0;
  /*Get Lat and Long from user*/
  while(i limits[i])
        {
        acutPrintf(_T("nInvalidInput"));
        }
      else
        {
        latLon[i] = degree;
        i++;
        }
      }
    else
      {
      acutPrintf(_T("nInvalidInput"));
      }
      }
    else
      {
      return;
      }
    }
  AcDbObjectId geoDataId;
  if(eOkTest(acdbGetGeoDataObjId(acdbHostApplicationServices()->workingDatabase(), geoDataId)))
    {
    AcDbSmartObjectPointer pGeoData(geoDataId, AcDb::kForRead);
    if(eOkTest(pGeoData.openStatus()))
      {
      AcGePoint3d location;
      if(eOkTest(pGeoData->transformFromLonLatAlt(latLon[1], latLon[0], 0, location.x, location.y, location.z)))
        {
        addMarker(asDblArray(location));
        return;
        }
      }
    }
  }

Comments

2 responses to “Adding Geopositionmarker To Different Location Through API”

  1. Very good it is powerful
    ////////////
    thank you

  2. Very good it is powerful
    //////////////
    thank you

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading