Add Text via Script


#1

Hi I’m,
I’m trying to add text via script the script is running from catia v5
I’m able to connect to Rhino just fine I’m able to save the files in the format that i need no problem but I’m unable to add a single piece of text.

Here is the code that I’m trying to use
oRhinoScript.Command ("_Text" & Chr(34) & “0,0” & Chr(34) & “_Enter” & Chr(34) & aryText(j) & Chr(34) & “_Enter”)

The string value of sryText(j) looks like this
PN: CR-1201
QTY: 1


#2

You miss spaces between your commands, if you use Rhinoscript.Command you still need them like you would type them in the command bar:

oRhinoScript.Command ("-_Text " & Chr(34) & "0,0" & Chr(34) & " _Enter " & Chr(34) & aryText(j) & Chr(34) & " _Enter")

Cheers


#3

For some strange reason even adding the spaces between the commands is not working it fails to put any text into it.

As I mentioned before this script is running form the catia v5 side with a call to Rhino like this

Set oRhino = GetObject("", “Rhino5.Interface”)

Set oRhinoScript = oRhino.GetScriptObject

I’m reading in the iges file I exported from catia with the command
oRhinoScript.Command ("_-Open " & Chr(34) & FullFileName & Chr(34))
This works fine
Then after trying to add text
oRhinoScript.Command ("-_Text " & Chr(34) & “0,0” & Chr(34) & " _Enter " & Chr(34) & “TEST” & Chr(34) & " Enter")
I’m doing a save as dxf
oRhinoScript.Command ("
-SaveAs " & Chr(34) & NewFileName & Chr(34) & " _Enter")
This is my first time working with Rhino and it’s been rather frustrating that adding a piece of text is what’s killing the progress on my project.


#4

Okay after going back and carefully creating text in Rhino by command line only I think I have it the Space bar is used similar to enter.
I have zero experience working with Rhino so the syntax is foreign to me
I finally was able to generate a piece of text.


(Dale Fugier) #5

Something doesn’t look right. Why so many Chr(34) statements? The only time you need to surround a string with double-quote characters is if your string has a space in it. In this case, the only string that you may want to surround with double-quotes is the actual text string.

For example:

strText = "Hello Rhino!"
oRhinoScript.Command("_-Text 0,0,0 " & Chr(34) & strText & Chr(34))

Note, scripting the Text command does not require the Enter token.

Also, you can make your life easier by writing a utility function to double-quote strings.

Function Quote(ByVal str)
    Quote = Chr(34) & CStr(str) & Chr(34)
End Function

With this, the above would look like this:

strText = Quote("Hello Rhino!")
oRhinoScript.Command("_-Text 0,0,0 " & strText)

Hope this helps.


#6

I was working from an example someone else gave me.
Your explanation cleared this up for me as far as how the syntax works.
If strText has Chr(10) in it what would be the syntax for entering it using the
"_Text 0,0,0 " command

Thanks,
Dana


#7

This is what ended up working for one line of text

oRhinoScript.Command ("-_Text 0,0 " & Chr(34) & StrText & Chr(34) & Chr(32))