trying to hack together some other scripts into a nice editable view of DocumentUserText to attach to attach to text in a layout drawing. the following returns the list but it doesn’t use the edits when it’s run again, like it get re-initialized.
help appreciated! thank you
import rhinoscriptsyntax as rs
import Rhino as rh
import scriptcontext
def DocumentDataInput():
Keylist = rs.GetDocumentUserText()
if not Keylist:
rs.MessageBox('No Object Data')
else:
UserDataList = []
for n in Keylist:
b = rs.GetDocumentUserText()
UserDataList.append(b)
newlist = []
newlist = rs.PropertyListBox(
Keylist, UserDataList, "User Data", "User Data Key List")
if newlist:
for c in range(len(Keylist)):
rs.SetDocumentUserText(Keylist[c], newlist[c])
DocumentDataInput()
@piac yes, i’m trying to make a workflow for creating, editing, and applying the user text to text in a layout title block.
it’s very cumbersome working with it natively. i got pretty good with RhinoScript, but this Python is new territory for me so I’m hacking together other scripts hoping to get what I’m going for.
it would be nice if there was a one stop window for working with User and Document text, create key’s and value, delete key’s, edit values, and most of all get it in a text field.
thanks in advance.
EDIT:
here is another part that I’m working on to pick a User Text Key and assign it to text. I know I’ve got them mixed up with one working with User Text and the other Document text, I just wanted to post it up for more context on what I’m trying to do.
# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs
import Rhino as rh
import scriptcontext
# get User Keys Listed in File
def GetID():
keys = []
values =[]
objsId = rs.AllObjects()
for i in objsId:
keys_i = rs.GetUserText(i, None, False)
if len(keys_i) > 0:
for k in keys_i:
value = rs.GetUserText(i, k, False)
if k in keys:
index_k = keys.index(k)
if not (value in values[index_k]):
values[index_k].append(value)
else:
keys.append(k)
values.append([value])
keyListResult = rs.ListBox(keys, "Keys to select:", "Select Objs by Key/Value")
print keyListResult
# Pick the text to apply the User Text Key and value to display it in the selected text
objectId = rs.GetObject("Pick any object")
if objectId:
clip = rs.ClipboardText(objectId)
tokenPrefix = '%<usertext("'
tokenMid = '","'
tokenEnd = '")>%'
print "Copied Identifier: ", objectId
rs.TextObjectText(objectId, tokenPrefix + clip + tokenMid + keyListResult + tokenEnd)
rs.SelectObject(objectId)
GetID()