Is there a way in Python to access a layout user text in Rhino WIP?
User text on layouts and details is stored on the
RhinoViewport object member for both the page (
RhinoPageView) and any details (
Cool, could you please throw-in a simple example? I couldn’t find the method (which is not a big surprise since I am a beginner )
Does this example make sense:
import scriptcontext as sc #set userstring on active view def set_userstring(key, value): view_port = sc.doc.Views.ActiveView.MainViewport view_port.SetUserString(key,value) #read back userstring def get_userstring(key): view_port = sc.doc.Views.ActiveView.MainViewport return view_port.GetUserString(key) print get_userstring('fookey') set_userstring('fookey','foovalue') print get_userstring('fookey')
Hi @Willem, thanks!
I have no experience with scriptcontext so far and I haven’t found any list/documentation of the methods. Any idea where should I look at?
What I wanted to do with the code is to list through all layouts and spit out all the user text (key,value) stored in each layout.
This code snippet prints all user strings attached to a page view (e.g. layout):
import Rhino import scriptcontext as sc page_views = sc.doc.Views.GetViewList(False, True) for pv in page_views: print(pv.PageName) col = pv.MainViewport.GetUserStrings() if col: for s in col.AllKeys: print(s, col[s])