I’m writting a simple Rhinoscript.
I would like to affect a layer (already in the document) to a DotText, based on the 2 first characters of the text inside the Dot…
Using the command Rhino.TextDotText(), I have can have the text easily, but then I can’t find a way to compare only the 2 first characters.
There will always be 7 characters, but the 4 last are numbers that are variable.
This is the 2 first character that will define the Dot’s layer.
For now, the script works with the exact Dot text, taking 1000 as a variable :
Dim Selection
Selection = rhino.SelectedObjects
If IsNull(Selection) Then
Selection = Rhino.GetObjects("Selectionner les DOT", 8192)
End If
For x = 0 To ubound(Selection)
If Rhino.IsTextDot(Selection(x)) Then
If Rhino.TextDotText(Selection(x)) = "ST_1000" Then
Rhino.ObjectLayer Selection(x), "Acier"
ElseIf Rhino.TextDotText(Selection(x)) = "BO_1000" Then
Rhino.ObjectLayer Selection(x), "Boulonnerie"
ElseIf Rhino.TextDotText(Selection(x)) = "GL_1000" Then
Rhino.ObjectLayer Selection(x), "Bois"
ElseIf Rhino.TextDotText(Selection(x)) = "CA_1000" Then
Rhino.ObjectLayer Selection(x), "Cables"
ElseIf Rhino.TextDotText(Selection(x)) = "AS_1000" Then
Rhino.ObjectLayer Selection(x), "Profils aluminium"
Else
Rhino.ObjectLayer Selection(x), "Divers"
End If
End If
Next
You might want to look at the Pyrhon startswith function. Say your dots look like XX_nnnn where XX could be any combination of letters and nnnn could be any number.
text="AB_1234"
if text.startswith("AB"):
print "Match"
else:
print "No Match"
So, you will need to use the VB “Left” function with the number 2 to get the first two characters of the text dot text. Then you can compare that it to your layers first two letters using similar VB methods.
I recommend you switch to Python instead of VBScript unless you have a very good reason to prefer the latter. Multiple members of McNeel staff have recommended this on this forum in recent years.
Well… I did not thought of it at first, I had some example of rhinoscript accessible.
But I did switch today on learning Python, as I faced this issue.
I understood that Python will open much more possibilities, or will allow more flexibility. Plus, it seems that there are more ressources on this subject.
Thanks anyway for your help @Helvetosaur , I’ll try your solution to see if it works. Won’t hesitate to fill you in with the result for common knowledge.