A text object that references another text object for content? (Text Fields Related)

Hi all!

I’m not sure if this is a really easy question or a really hard question. I would like to have a text instance A that can reference another text instance B for its content. Something similar to the way %% inside a text instance can reference the page name of my layout. My need is, let’s say I have a list of labels on a layout, and I would like to have another text instance on my layout located over the top of a detail that I’m using to label some geometry… So anytime I change the my label text, it is reflected on the geometry label text. I would consider using Blocks, but the issue I run into is when I duplicate the layout page, I don’t want page 2 labels to reference page 1.

Any thoughts?

Are you familiar with SetUserText, GetUsertext and %[usertext(“39f3be9d-eb95-4e64-90b6-ed54f49aff71”,“blah”)]%?
(replace [] with <>)

@astrisk I’m semi-familiar (okay, not completely), but it seems a little more heavy in process than what I’m looking for, and additionally, text B wouldn’t automatically update when I change the text of A, correct?

I’m sort of creating a layout template file I can use where I have essentially a spreadsheet of info that will update text objects in other parts of the layout.

Something like this?

If yes, then it’s done with UserText and script to enter data.

Yep :slight_smile:

You are awesome.

I’m going to give this a shot!

All your data is set to some object (in my case it’s text) as User Text. And to display it you use %[usertext…
The script is there for a better UI.

Option Explicit

Call TitleEditor()

Sub TitleEditor()

Dim i
Dim TMP, Ttl, RelProp
Dim Key, Val, NewVal

TMP = Rhino.GetCurveObject("Pick Title Border to edit release properties", True)
If Not IsNull(TMP) Then Ttl = TMP(0) Else Exit Sub
If IsNull(Rhino.GetUserText(Ttl, "Title")) Or Not Rhino.GetUserText(Ttl, "Title") = "Border" Then Exit Sub

RelProp = Rhino.GetUserText(Ttl, "RelProp")
Key = Rhino.GetUserText(RelProp)
ReDim Val(UBound(Key))

For i=0 To UBound(Key)
	Val(i) = Rhino.GetUserText(RelProp, Key(i))
Next

NewVal = Rhino.PropertyListBox(Key, Val, "DO NOT LEAVE BLANK FIELDS!!", "Release properties")
If Not IsArray(NewVal) Then Exit Sub

For i=0 To UBound(Key)
	Rhino.SetUserText RelProp, Key(i), NewVal(i)
Next

Rhino.AddPoint Array(0, 0, 0)
Rhino.DeleteObject Rhino.FirstObject

End Sub

If you post your title pic or file, I could tell you how I’d handle it.

So, I would like the text of Screw 1 to be the same as whatever I type in the first box- aka #1 XYZ.

What is the order of operations for getting/setting usertext? And should I be looking at the text ID or the userData ID?

In this particular case I’d SetUserText to text that says #10 XYZ like this:

Pre-select your #10 XYZ text object
SetUserText [Enter]
Screw [Enter]
“Screw 1” [Enter] (Use quotation marks to register space as space and not Enter command)

Then double click in it to edit its Text field or use properties tab.
and add %^usertext(“Object ID”,“Screw”)^%
where Object ID is #10 XYZ text ID. ^^ - are lesser and greater signs (this forum wouldn’t display them :/)
Copy paste it to SCREW 1 text field.
Now they both will show the same thing: “Screw 1”

All this can be scripted or macro’ed.

You can add another screw to the same text, you just need to name it differently, like “Screw2” with “Other screw” description.

Now to edit it, you’d have to re- setusertext for Screw or Screw2 and all the screw texts will update automatically.
You can’t copy paste them to the next page 'cause the copied texts would still have your first page Text ID.

Super interesting. That macro seems highly useful for actually editing these values… How do I go about making this title border it’s asking to edit release properties for?

That’s done by the script that I posted earlier.
In your case it’d be slightly different, 'cause in my workflow the lines that make up the Part Drawing title block contain the reference to text object that contains all the title info in its usertext. That title is created by another script too. XD

I agree with you, “expression” that displays another text object text would be a much simpler solution. But I don’t think it exists in Rhino 5.

Scripts on scripts… how deep does the rabbit hole go :grinning: ? I’d love to take a look at your title block script- even if it takes a couple of scripts to write that. I’m pretty surprised there isn’t an easier/built in way to do this.

Here’s the relevant part of it:

	Rhino.Command "_Import X:\Engineering\RhinoScripts\PD-Title.3dm", False
	
	If IsEmpty(RelProp) Then
		RelProp = Rhino.AddText("RELEASE PROPERTIES:" & Chr(13) & "PM:" & Chr(13) & "Drafter:" & Chr(13) & "Job:" & Chr(13) & "Release:" & Chr(13) & "Material:" & Chr(13) & "Color:", Array(-455, y - 63, 0), 12, "ISOCPEUR", 0, 2)
		Rhino.ObjectLayer Rhino.FirstObject, "DIMs"
		Rhino.ObjectColor Rhino.FirstObject, RGB(200, 200, 200)
		Rhino.SetUserText RelProp, "PM", "XYZ"
		Rhino.SetUserText RelProp, "Drafter", "INI"
		Rhino.SetUserText RelProp, "Job", "12345 Some really nice project"
		Rhino.SetUserText RelProp, "Release", "0"
		Rhino.SetUserText RelProp, "Material", "4MM PE REYNOBOND"
		Rhino.SetUserText RelProp, "Color", "Mica Green *12345678*"
		PropPM = "%<usertext(" & chr(34) & RelProp & chr(34) & "," & chr(34) & "PM" & chr(34) & ")>%"
		PropBy = "%<usertext(" & chr(34) & RelProp & chr(34) & "," & chr(34) & "Drafter" & chr(34) & ")>%"
		PropJob = "%<usertext(" & chr(34) & RelProp & chr(34) & "," & chr(34) & "Job" & chr(34) & ")>%"
		PropRel = "%<usertext(" & chr(34) & RelProp & chr(34) & "," & chr(34) & "Release" & chr(34) & ")>%"
		PropMat = "%<usertext(" & chr(34) & RelProp & chr(34) & "," & chr(34) & "Material" & chr(34) & ")>%"
		PropCol = "%<usertext(" & chr(34) & RelProp & chr(34) & "," & chr(34) & "Color" & chr(34) & ")>%"
		Rhino.AddText "-", Array(-450, y - 63, 0), 12, "ISOCPEUR", 2, 0
		Rhino.ObjectLayer Rhino.FirstObject, "DIMs"
		Rhino.ObjectColor Rhino.FirstObject, RGB(200, 200, 200)
		Rhino.TextObjectText Rhino.FirstObject, PropPM & chr(13) & PropBy & chr(13) & PropJob & chr(13) & PropRel & chr(13) & PropMat & chr(13) & PropCol
		Rhino.AddObjectsToGroup Array(RelProp, Rhino.FirstObject), Rhino.AddGroup
	End If
	
	Title = Rhino.SelectedObjects
	Rhino.MoveObjects Title, Array(0, 0, 0), Array(x, y, 0)
	
	For i=0 To UBound(Title)
		If x > 0 And Rhino.GetUserText(Title(i), "Delete") = "Rest" Then Rhino.DeleteObject Title(i)
		If Rhino.GetUserText(Title(i), "Delete") = "This" Then Rhino.DeleteObject Title(i)
		If Rhino.GetUserText(Title(i), "Title") = "Border" Then Rhino.SetUserText Title(i), "RelProp", RelProp
		If Rhino.GetUserText(Title(i), "Project") = "Manager" Then Rhino.TextObjectText Title(i), PropPM
		If Rhino.GetUserText(Title(i), "Drafter") = "Ini" Then Rhino.TextObjectText Title(i), PropBy
		If Rhino.GetUserText(Title(i), "Job") = "Name" Then Rhino.TextObjectText Title(i), "JOB: " & PropJob
		If Rhino.GetUserText(Title(i), "Release") = "Number" Then Rhino.TextObjectText Title(i), PropRel
		If Rhino.GetUserText(Title(i), "Material") = "Specs" Then Rhino.TextObjectText Title(i), PropMat
		If Rhino.GetUserText(Title(i), "Finish") = "Color" Then Rhino.TextObjectText Title(i), PropCol
		If Rhino.GetUserText(Title(i), "Panel") = "Name" Then
			Rhino.TextObjectText Title(i), tag
			Rhino.TextObjectText Title(i), Left(tag, InStr(tag, chr(13)))
		End If
		If Rhino.GetUserText(Title(i), "Total") = "Quantity" Then
			If InStr(tag, "thus") = 0 Then
				qty = "1"
			Else
				qty = Right(tag, Len(tag) - InStr(tag, chr(10)))
				qty = Left(qty, InStr(qty, " "))
			End If
			Rhino.TextObjectText Title(i), qty
		End If
	Next