I have been using Macro commands and I´m very happy with it´s simplicity, BUT I guess it has it´s limitations.
I have several points in my file and I want to run the command “EvaluatePt” to place the coodinates on screen of every point I have selected.
I think I would prefer to try Python since I belive it will allow me to do more stuff, but I´m receptive to Rhino scripting.
What ever works is fine.
import rhinoscriptsyntax as rs
inputPtIDs = rs.GetObjects("select points", 1)
inputPts = [rs.coerce3dpoint(ID) for ID in inputPtIDs]
for pt in inputPts:
tagText = "({0}, {1}, {2})".format(pt.X, pt.Y, pt.Z)
rs.AddTextDot(tagText, pt)
As promised in my other message, here are a few comments to explain what’s going on:
#this imports the rhinoscriptsyntax library, which provides the simplest access to Rhino in python
# you should always import "as rs" for consistency with the rest of the community
import rhinoscriptsyntax as rs
#sometimes you'll "import Rhino" for access to Rhino.Geometry, etc...
#or maybe you'll "import math" or another builtin python module
#the first line prompts the user to select inputs
#the "1" forces the user to only select points
inputPtIDs = rs.GetObjects("select points", 1)
#this line converts the list of GUIDs returned by GetObjects into 3dpoint objects, so we can get their x,y,z values
#this syntax is "list comprehension" in python, a very useful python concept to read up on
inputPts = [rs.coerce3dpoint(ID) for ID in inputPtIDs]
# stores the current view cPlane
plane=rs.ViewCPlane()
#we now loop through all the selected points:
#each of these lines happens once for each point.
for pt in inputPts:
#convert the world coordinates to Cplane coordinates
pt_xf=rs.XformWorldToCPlane(pt,plane)
#use python string formatting to create the text tag content
tagText = "({0}, {1}, {2}) CP".format(pt_xf.X, pt_xf.Y, pt_xf.Z)
#add the text dot object to the Rhino document
rs.AddTextDot(tagText, pt)
… and that’s it.
List comprehension and string formatting are both good things to read up on, very useful both in and outside Rhino.
The rhinoscript library is super handy, you can think of it as another set of Rhino commands, many with close analogues in Rhino. These are very similar to Rhino.methods in vb Rhinoscript.
Rhinoscript is actually build on top of RhinoCommon, and sometimes you’ll want to use Rhino objects directly. For example, when you reference “pt_xf.X” you are using a Rhino.Geometry.Point3d object. But don’t worry about that too much at the start.
Good luck with Rhino Python, it’s super useful and pretty accessible once you get into it.