Rhino.GetUserText strips user text of vbNewLines


Hello - try putting an
& chr(10)
in your text when you set the user text in RhinoScript.

-Pascal

Unpossible, we’re using Rhino.EditBox to populate UserText.

%<usertext(“ObjID”,“ObjDescr”)>% outputs it properly. EditBox shows it properly. Rhino.GetUserText breaks it.

You can look for chr(13) and split the lines yourself:

Dim x: x = Rhino.EditBox()
Dim y: y = Split(x, chr(13))

-Pascal

Python/Rhinoscriptsyntax seem to be working OK in this respect if I understood the problem

image

image

image

I think this is RhinoScript - it looks like in order for user text to contain the line feed you need to add it explicitly, maybe something like this-

Sub Main()
	Dim x: x = Rhino.EditBox()
	Dim y: y = Split(x, chr(13))
	Dim textString, item
	textString = ""
	For Each item In y
		textString = textString & item & chr(10) 
	Next
	rhino.SetDocumentUserText "Key", textString
End Sub

Looks like if there is a fix it may be in EditBox… @dale is that true?

-Pascal

1 Like

And then it gets fixed… :wink:

Hm - now this works… still testing…

I have no idea what I was doing before but this now works to set multiline document and object user text.

Sub Main()
	Dim x: x = Rhino.EditBox()
	rhino.SetDocumentUserText "Key1", x
	rhino.SetUsertext Rhino.SelectedObjects()(0), "ObjKey", x
End Sub

-Pascal

import scriptcontext as sc
import rhinoscriptsyntax as rs

OX = rs.ViewCPlane()
rs.ViewCPlane(None, rs.WorldXYPlane())
rs.ClearCommandHistory()

while True:
    Pick = rs.GetObjectEx("Pick object to call out", 4124, False, True)
    if (Pick):
        if rs.ObjectType(Pick[0]) == 4096:
            for BlockItem in rs.BlockObjects(sc.doc.Objects.Find(Pick[0]).InstanceDefinition.Name):
                if rs.GetUserText(BlockItem,"ObjDescr"): LdrTxt = rs.GetUserText(BlockItem,"ObjDescr")
    else:
        break
    rs.AddText(LdrTxt,Pick[3],0.1)
    print LdrTxt

print "Leader plop done\n"
rs.ViewCPlane(None,OX)

I cannot reproduce this here in my tests - can you post an example file for your script that has the user text already set in the block objects?

Block.3dm (48.8 KB)

I fixed the text like this: rs.LeaderText(rs.FirstObject(), rs.LeaderText(rs.FirstObject())
I don’t care what you coding gurus have to say about it. To me, this hack looks like quartering a person in one stroke. :stuck_out_tongue:

1 Like

Not a coding guru, simply trying to figure out how it’s going wrong so a proper bug report can be filed, as I cannot reproduce what is happening when I set a multi-line user text on an object with SetUserText(), retrieve it with GetUserText() and add it to the document with AddText() - it stays multi-line here throughout.

Yeah - I saw the single line initially, somehow, but then it just worked as expected… can’t reproduce, but I also don’t have any idea what I goofed on, if anything, at first, that Asterisk might also be stumbling on…

-Pascal

If I explode the block and select the surface, I see this:

So the user text is correct (multiline) in the file.

If I run the script above, I do get the single line:

Now will look into where in the script this happens…

So if I put a breakpoint in after getting the user text, it does appear to be single line in the script:

The question is why…

I was just jesting, but you are. :wink:

So those usertexts were applied to objects in R5 initially and surfaces were copy pasted into R6. Maybe that has something to do with the bug?.. You can use this file too. Those surfaces are R5 copy-pastes.
PDF test.3dm (87.1 KB)

Ah, that’s definitely another path to check… A bunch of text stuff changed from V5 to V6 and not everything translates 1 to 1… Will try an experiment on my own here…

OK, so far no luck, if I set a multiline text in V5 with python or vb rhinoscript SetUserText() it stays multiline when I copy/paste into V6…

How did you originally create the multiline user text and attach it to the object? OK, I see - EditBox/VB… Will try that.

Nope - still multiline… :confounded: I dunno - someone else with more knowledge than I will need to start picking this apart…

This is how it was added.

Dim Pick, ldrText, Snaps
	
	Snaps = Rhino.OsnapMode
	Rhino.OsnapMode 177
	
	Do
		Rhino.EnableRedraw True
		Do
			Pick = Rhino.GetPoint("Pick detail element to describe",,,, True)
			If IsNull(Pick) Or IsEmpty(Pick) Then Rhino.OsnapMode Snaps: Exit Sub
		Loop While IsNull(Pick(1))
		
		Rhino.EnableRedraw False
		ldrText = Rhino.GetUserText(Pick(1), "ObjDescr")
		If IsNull(ldrText) Then ldrText = ""
		ldrText = Rhino.EditBox(ldrText,, "DETAIL ELEMENT DESCRIPTION:")
		If Not IsNull(ldrText) Then Rhino.SetUserText Pick(1), "ObjDescr", ldrText
	Loop

Wait, I think I can finally reproduce it. Hang on…

Yep. @pascal

  1. apply a multi-line user text in V5 to an object (doesn’t matter what, a circle will do)
  2. copy paste to V6.
  3. If you look in the user text properties panel, it still shows multiline
  4. But, if run a python script like below, it’s single line.
import rhinoscriptsyntax as rs
obj=rs.GetObject()
result=rs.GetUserText(obj,"My_Key")
print result

Here, if I set the user text in V5 as

This
is
a
circle

The script prints

Thisisacircle

Voilà… Must be something with how newlines/carriage returns are handled.

@Helvetosaur - the check is in the mail. Thanks for digging…

-Pascal

Could be related to this.