【问题标题】:Can I change text contents in the viewer?我可以在查看器中更改文本内容吗?
【发布时间】:2019-03-03 15:41:38
【问题描述】:

我知道对 db 的访问是只读的,但我可以更改查看器显示的文本,即覆盖 MText 元素的 displayValue 属性吗?亲切的问候,格雷戈尔

viewer.getProperties(dbid, (props) => {
        // get set of properties for a dbid
        // var properties = props.properties is an array of properties
}

{
attributeName: "Contents"
displayCategory: "Text"
displayName: "Contents"
displayValue: "some text i would like to change"
hidden: false
precision: 0
type: 20
units: null
}

【问题讨论】:

    标签: autodesk-forge


    【解决方案1】:

    不确定为什么要更改项目属性的特定文本。最简单的方法是创建ViewerPropertyPanel 的驱动类并覆盖ViewerPropertyPanel.prototype.setNodeProperties

    class MyViewerPropertyPanel extends Autodesk.Viewing.Extensions.ViewerPropertyPanel {
        constructor( viewer ) {
            super( viwer );
        }
    
        setNodeProperties( nodeId ) {
            var that = this;
            this.propertyNodeId = nodeId;
            that.currentModel.getProperties(nodeId, function (result) {
                if (!that.viewer)
                    return;
    
                that.setTitle(result.name);
                //!!!<<<<
                // Modofy contents of `result.properties` here
                //!!!<<<<
                that.setProperties(result.properties);
                that.highlight(that.viewer.searchText);
    
                that.resizeToContent();
    
                if (that.isVisible()) {
                    var toolController = that.viewer.toolController,
                        mx = toolController.lastClickX,
                        my = toolController.lastClickY,
                        panelRect = that.container.getBoundingClientRect(),
                        px = panelRect.left,
                        py = panelRect.top,
                        pw = panelRect.width,
                        ph = panelRect.height,
                        canvasRect = that.viewer.canvas.getBoundingClientRect(),
                        cx = canvasRect.left,
                        cy = canvasRect.top,
                        cw = canvasRect.width,
                        ch = canvasRect.height;
    
                    if ((px <= mx && mx < px + pw) && (py <= my && my < py + ph)) {
                        if ((mx < px + (pw / 2)) && (mx + pw) < (cx + cw)) {
                            that.container.style.left = Math.round(mx - cx) + 'px';
                            that.container.dockRight = false;
                        } else if (cx <= (mx - pw)) {
                            that.container.style.left = Math.round(mx - cx - pw) + 'px';
                            that.container.dockRight = false;
                        } else if ((mx + pw) < (cx + cw)) {
                            that.container.style.left = Math.round(mx - cx) + 'px';
                            that.container.dockRight = false;
                        } else if ((my + ph) < (cy + ch)) {
                            that.container.style.top = Math.round(my - cy) + 'px';
                            that.container.dockBottom = false;
                        } else if (cy <= (my - ph)) {
                            that.container.style.top = Math.round(my - cy - ph) + 'px';
                            that.container.dockBottom = false;
                        }
                    }
                }
            });
        }
    }
    
    // Replace propertry panel to our owned
    viewer.setPropertyPanel( new MyViewerPropertyPanel( viewer ) ); 
    

    尽情享受吧!

    【讨论】:

    • 伊森,是的。这有效 - 它允许我动态更改属性,因为它们显示在属性查看器弹出窗口中。然而,我要求的是更改文本(ACAD 文本对象的内容属性的显示值),因为它显示在查看器中。该应用程序将使用数据库中的动态内容或物联网设备的测量属性覆盖文本元素。通常这是通过创建自定义弹出窗口或添加 threejs 对象来完成的。我想知道我是否可以直接挂钩文本元素。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多