Update of the Attributes User Text Window

Hi,

I am changing some of the attributes of the RhinoObject in User Text window manually. After change of certain UserStrings, some other strings are changed as well via Event Watcher Class.
However, I cannot see an update immediately when having focus in the same window. In order to see effect, I need to switch to other window like Object or Material and then back. How to force an update of the values in User text window without switch?
I am already using CommitChanges however still need to switch to other window and back.

Thanks,
Dmitriy

@Dmitriy I may need some more specific info or an example to try but in general the user text panel watches the following RhinoDoc events when it’s being displayed as an Attribute Text panel: ReplaceRhinoObject, ModifyObjectAttributes, and AddRhinoObject

If you select a document object with the attribute user text panel active then type SetUserText and pass in a sample key/value does the Attribute Text display the new user text after you complete the SetUserText command?

Hello @Trav

Thanks for quick reply.
Yes, I am using MofidyObjectAttributes event. And it works quite well: after I modify one field in AttributesUserText window - event is triggered. But when doing new assignments for other fields under this event using SetUserString - these are not updated in the table immediately (after I press Enter or change the focus to the different cell). Switching from AttributesUserText windows to other and back updates all fields.

Now, coming to your question: when I select a document object with the Attributes User Text panel active and type SetUserText command and press Enter, then Rhino hides this panel and shows Viewport Properties window.

So, in short - all assignments of user strings are done correctly, but what is missing - update of the User strings table. I think, if I could call an update of the table at the end of the MofidyObjectAttributes event - this would solve the problem. Is it possible to do such a forced update in RhinoCommon?

Thanks,
Dmitriy

@Dmitriy this seems to work fine here. Let me know if you are still having troubles.

import Rhino
import scriptcontext

def SampleCreateObjectAttributeText():
    
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Select object for attribute text")
    go.Get()
    if(go.CommandResult() != Rhino.Commands.Result.Success):
        return go.CommandResult()

    rhobj = go.Object(0).Object()
    att = rhobj.Attributes.Duplicate()
    att.SetUserString("MyKey","MyValue")
    att.SetUserString("MyKey2","MyValue2")
    att.SetUserString("MyKey3","MyValue3")

    scriptcontext.doc.ActiveDoc.Objects.ModifyAttributes(rhobj.Id,att,True)

    return Rhino.Commands.Result.Success


if( __name__ == '__main__' ):
    SampleCreateObjectAttributeText()

Run with an object preselected and the attribute panel open. It shouldnt flash.

0496

1 Like

Hello @Trav

Thanks, but it doesn’t work on my side.
See simple example enclosed: 3dm file + GH file.
When pressing AssignNew button on the RCP - values are not updated in the table.
Only switching window helps.


AttrExample.3dm (245.8 KB)
AttrExample.gh (2.9 KB)

Kind regards,
Dmitriy

P.S. I am on R6 SR26

Thanks @Dmitriy I can reproduce and see why this is happening. The object properties page events are refreshing the ui contents for user text panels when they’re in attribute text mode. Grasshopper doesn’t seem to trigger these page events. I have a couple of ideas on how to make this work better for you.

For now a cheap hack is to select and deselect your object through your script (which is happening if you ran a script, or command outside of grasshopper during the modify/replace object events). Doing this will trigger the page controller to refresh.

https://mcneel.myjetbrains.com/youtrack/issue/RH-58329

1 Like