For a button in Rhino, I’m trying to write a tool with Rhinoscript to pick points in Rhino. My target is to name the point with a ID and a Text Entity and increment the number with the given starting value.
Option Explicit
Call Main
Sub Main
Dim nValue, bContinue
Dim strObject, arrPoint, arrPlane
nValue = Rhino.GetInteger("Starting value")
If IsNull(nValue) Then Exit Sub
bContinue = True
While (bContinue)
strObject = Rhino.GetObject("Select point", 1, False)
If Not IsNull(strObject) Then
Call Rhino.ObjectName(strObject, CStr(nValue))
arrPoint = Rhino.PointCoordinates(strObject)
arrPlane = Rhino.MovePlane(Rhino.ViewCPlane, arrPoint)
Call Rhino.AddText(CStr(nValue), arrPlane, 300.0, "Arial", 0, 2)
nValue = nValue + 1
Else
bContinue = False
End If
Wend
End Sub
Hi,
If you are new to scripting then I suggest using Python (a scripting language) rather than VBScript (a scripting language) unless you have a good reason to prefer VBScript.
Graham
Thank you for the reply, the script works now! I think that you worked with strings instead of picking a point as an array. Is it possible to use ‘Rhino.GetPoint’ to place a point with a snap in a particular location and name it with an incrementing ID and Text?
I tried to translate the Text too by a Vector however it didn’t work(I commented in green). I put the rvb file in the attachment. Maybe you have time to look to it.
Thank you for the message. I don’t know if Python is able to use the same commands out of Rhino as Rhinoscript?
I looked in the RhinoPythonPrimer, It looks like that it is possible to make Rhino toolbarbuttons with the use of Python?
Yes the primer describes the rhinoscriptsyntax module in Python which is based upon the syntax of RhinoScript - there are some differences and the usual frustrations when switching from one way of thinking to another but I found the transition very easy overall.
Yes you can attach a Python script to a toolbar button, either directly or via a _RunPythonScript call.
Python is a very popular choice for beginners due to the clear syntax and shallow learning curve. It is also extremely popular for many experienced coders because the language contains powerful feature when you need them like multiple inheritance, packaging, introspection, type hints, etc which allow you to be very productive without being limited in what you can produce. At some point you may wish to look beyond rhinscriptsynax to the underlying Python RhinoCommon libraries but that is for another day…
You’re welcome To put it much more simply and to quote the RhinoPython primer:
“Python offers exciting new potentials for programming in Rhino with Object-Oriented functionality, simple syntax, access to the .NET framework and a vast number of user-built libraries to extend Rhino’s functionality. The same powerful methods that were previously in VBscript are still available, as well as a ton of other exciting methods and features available natively with Python.”