Могу ли я изменить текстовое содержимое в программе просмотра?

Я понимаю, что доступ к базе данных доступен только для чтения, но могу ли я изменить текст, отображаемый средством просмотра, т.е. перезаписать атрибут displayValue элементов MText? С уважением, Грегор

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
}

person Gregor    schedule 01.03.2019    source источник


Ответы (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 ) ); 

Наслаждайся этим!

person Eason Kang    schedule 03.03.2019
comment
Исон, да. это работает - и позволяет мне динамически изменять свойства, когда они отображаются во всплывающем окне средства просмотра свойств. Однако я просил об изменении текста (отображаемого значения свойства содержимого текстового объекта ACAD) в том виде, в каком он отображается в средстве просмотра. Приложение предназначено для перезаписи текстовых элементов динамическим содержимым из базы данных или измеренными свойствами с устройств IoT. Обычно это делается путем создания настраиваемых всплывающих окон или добавления объектов threejs. Интересно, смогу ли я напрямую подключиться к текстовым элементам. - person Gregor; 05.03.2019