I have some Document User Text embedded in some blocks. I’m using these blocks in a project, and I’m wondering if it is possible to extract this data when they are used in a project, attaching this data to the block instance’s Attribute User Text fields?
Yep this is in Rhino 8, I can use grasshopper, but would prefer to use Python if possible! I’ve tried so many methods and I can only seem to get the document text for the document the block is inserted into, not in the actual block itself.
I think some others may have to pipe in here to see what is possible. Once the data is attached to the block, it is not document text anymore, but user text on the definition in the block table. Does this thread help a bit with Python: Can you add User Text to Block Definition?
As for Grasshopper, this is the method to import and read the block definition data (Originally Document data on the external files):
Sorry, took me a bit to get back to this. Here is some code using Python to get to the Key/Values from the block definition. This data was originally created by importing the Blocks into this file. And Document data is now on the definition:
import Rhino
def DumpInstanceDefinitinUserText():
filter = Rhino.DocObjects.ObjectType.InstanceReference
rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select block instance", False, filter)
if not objref or rc != Rhino.Commands.Result.Success:
return
iref = objref.Object()
if not isinstance(iref, Rhino.DocObjects.InstanceObject):
return
idef = iref.InstanceDefinition
if not idef:
return
# https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.namevaluecollection
dict = idef.GetUserStrings()
for Ustrings in range(dict.Count):
print(dict.GetKey(Ustrings) + " contains " + dict.Get(Ustrings))
DumpInstanceDefinitinUserText()