如何获取 AutoCAD 几何图形的查看器坐标?
How can I get the viewer coordinates of AutoCAD geometry?
我正在使用 2D Autodesk Forge Viewer,我正在寻找一种方法来确定来自 AutoCAD 的块参考对象的 X、Y 坐标。
我有几何元素的 dbID,并且。我可以通过 NOP_VIEWER.getProperties()
和 NOP_VIEWER.getDimensions()
获取一些信息,但是它们都没有 X,Y 坐标。
我记得,方块实体确实没有位置数据。如果对块的原生位置数据有任何评论,我会与工程师团队核实。一种替代方法是使用 AutoCAD 的 Forge Design Automation 自行提取数据,但需要额外的代码。
在 Forge 转换源 DWG 之后,实体被转换为图元。通过API,可以获取图元的几何信息,如直线起点、圆心。两个博客说的很详细:
https://forge.autodesk.com/blog/working-2d-and-3d-scenes-and-geometry-forge-viewer
https://forge.autodesk.com/blog/working-2d-and-3d-scenes-and-geometry-forge-viewer
本质上就是使用了回调函数:
VertexBufferReader.prototype.enumGeomsForObject = function(dbId, callback)
回调对象需要这些可选函数:
• onLineSegment(x0, y0, x1, y1, viewport_id)
• onCircularArc(centerX, centerY, startAngle, endAngle, radius, viewport_id)
• onEllipticalArccenterX, centerY, startAngle, endAngle, major, minor, tilt, viewport_id)
• onTriangleVertex(x, y, viewport_id)
.
在下面小东的帮助下,我设计了以下解决方案,使用对象的 dbId 获取对象的 X、Y 坐标
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`);
};
我正在使用 2D Autodesk Forge Viewer,我正在寻找一种方法来确定来自 AutoCAD 的块参考对象的 X、Y 坐标。
我有几何元素的 dbID,并且。我可以通过 NOP_VIEWER.getProperties()
和 NOP_VIEWER.getDimensions()
获取一些信息,但是它们都没有 X,Y 坐标。
我记得,方块实体确实没有位置数据。如果对块的原生位置数据有任何评论,我会与工程师团队核实。一种替代方法是使用 AutoCAD 的 Forge Design Automation 自行提取数据,但需要额外的代码。
在 Forge 转换源 DWG 之后,实体被转换为图元。通过API,可以获取图元的几何信息,如直线起点、圆心。两个博客说的很详细:
https://forge.autodesk.com/blog/working-2d-and-3d-scenes-and-geometry-forge-viewer https://forge.autodesk.com/blog/working-2d-and-3d-scenes-and-geometry-forge-viewer
本质上就是使用了回调函数:
VertexBufferReader.prototype.enumGeomsForObject = function(dbId, callback)
回调对象需要这些可选函数:
• onLineSegment(x0, y0, x1, y1, viewport_id)
• onCircularArc(centerX, centerY, startAngle, endAngle, radius, viewport_id)
• onEllipticalArccenterX, centerY, startAngle, endAngle, major, minor, tilt, viewport_id)
• onTriangleVertex(x, y, viewport_id)
.
在下面小东的帮助下,我设计了以下解决方案,使用对象的 dbId 获取对象的 X、Y 坐标
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`);
};