Doublequotes for variables

Hi,
I wrote a very simple script (actually my first transit from macros to scripts) to render specific viewports. It should let you pick a folder and render the views into it named accordingly.

Problem occures when using a folder that contains spaces. Forums say put your strings in quotes but how do I quote a string in a variable?

Option Explicit

Call RenderVisu()
Sub RenderVisu()

Dim folder  
folder = Rhino.BrowseForFolder
If IsNull(folder) Then Exit Sub

Dim answer
answer = Rhino.MessageBox(folder, 1)
If answer = 2 Then Exit Sub

Rhino.Command "_-SetActiveViewport 01_TOP"
Rhino.Command "_Render _-SaveRenderWindowAs " & folder & "01_TOP.png" 
Rhino.Command "_CloseRenderWindow"

Rhino.Command "_-SetActiveViewport 02_BOTTOM"
Rhino.Command "_Render _-SaveRenderWindowAs " & folder & "02_BOTTOM.png"
Rhino.Command "_CloseRenderWindow"

Rhino.MessageBox("Done")

End Sub

Thanks in advance

You need to add in the quotes around the folder string in the surrounding strings you’re joining, at the end of the previous and the start of the next. So you need…I forget if it’s 2 or 3 quotes in Python? Just keep adding quotes till it works. :slight_smile:

Here’s a page with the various ways to put quotes in strings in Python: Kite

If you’re just starting with scripting why not learn Python? Just curious.

For Rhinoscript (VB) you can use chr(34) for a double quote character. So to enclose the folder/file path in quotes, it might look something like this:

Rhino.Command "_Render _-SaveRenderWindowAs " & chr(34) & folder & "01_TOP.png" & chr(34)

Hi @kral,

If you find yourself needing to do this frequently, you might just make a utility function you can call. This makes your code easier to read.

Option Explicit

Call Main

Sub Main()
	Dim str : str = "Hello Rhino!"
	Call Rhino.Print(str)
	str = QuoteStr(str)
	Call Rhino.Print(str)
End Sub

Function QuoteStr(str)
	QuoteStr = Chr(34) + str + Chr(34)
End Function

– Dale

1 Like

I could write a noble essay about learning both while learning Rhinoscript helps me understand it´s implementation in Python but in reality – time is tight and I could mash this “code” together using examples I found online like good old doctor Frankenstein.

But yeah I´m learning python as well. :wink: