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.
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`);
};