我可以在查看器中更改文本内容吗? [英] Can I change text contents in the viewer?

查看:125
本文介绍了我可以在查看器中更改文本内容吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I understand that access to the db is read-only, but can I change the text that is displayed by the viewer, i.e. overwrite the displayValue attribute of MText elements? Kind regards, Gregor

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
}

推荐答案

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

Not sure why you want to change the specific text of the item properties. The simplest way is to create a driven class of the ViewerPropertyPanel and override 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 ) ); 

享受吧!

这篇关于我可以在查看器中更改文本内容吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆