Warm tip: This article is reproduced from serverfault.com, please click

How can I get the viewer coordinates of AutoCAD geometry?

发布于 2020-11-25 18:27:53

I am using the 2D Autodesk Forge Viewer, and I'm looking for a way to determine the X,Y coordinate of a block reference object from AutoCAD.

I have the dbID for the geometry element, and. I can get some information through NOP_VIEWER.getProperties() and NOP_VIEWER.getDimensions(), but neither of those have the X,Y coordinate.

Questioner
Wesley Reed
Viewed
0
Wesley Reed 2020-11-30 23:53:36

With help from Xiaodong below, I was able to devise the following solution to get the X,Y coordinate of an object using its dbId

const geoList = NOP_VIEWER.model.getGeometryList().geoms;
const readers = [];

for (const geom of geoList) {
  if (geom) {
    readers.push(new Autodesk.Viewing.Private.VertexBufferReader(geom, NOP_VIEWER.impl.use2dInstancing));
  }
}

const findObjectLocation = (objectId) => {
  for (const reader of readers) {
    let result;
    reader.enumGeomsForObject(objectId, {
      onLineSegment: (x, y) => {
        result = { x, y };
      },
    });

    if (result) {
      return result;
    }
  }

  throw new Error(`Unable to find requested object`);
};