Rhino scripting or Python for this?

Hi

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.

Thanks a lot.

Here’s one way to do it:

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)

Thanks @owen, it´s beautifull to see this working.

One small question, can I post the coordinates according to the active Cplane?

Thanks a lot

I held off on learning Python for a while, preferring to stick to the vbscript I knew pretty well, and regret that.

Something like this might work:

import rhinoscriptsyntax as rs

inputPtIDs = rs.GetObjects("select points", 1)
inputPts = [rs.coerce3dpoint(ID) for ID in inputPtIDs]

plane=rs.ViewCPlane()

for pt in inputPts:
    pt_xf=rs.XformWorldToCPlane(pt,plane)
    tagText = "({0}, {1}, {2}) CP".format(pt_xf.X, pt_xf.Y, pt_xf.Z)
    rs.AddTextDot(tagText, pt)

–Mitch

@JimCarruthers you still have time :slight_smile:

I´m trying to learn the basics also, but to see this simple script working is REALLY motivating.

Perfect!!! Thanks a lot Mitch

Hi,

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.

1 Like