I’m attempting to replicate this Rhinoscript code in python:
Call Rhino.OsnapMode(1 + 256)
This turns on the “near” and “perpendicular” OSNAPs.
In python I tried this:
rs.OsnapMode(1 + 256)
and it shuts all of the OSNAPs off. If I try various numbers in the parenthesis, I get unpredictable results. For example, according to the help file, using 1 should turn on “Near” but 2 does. If I try this with “Near” turned on:
mode = rs.OsnapMode()
print mode
it returns 50190. With “Near” and “Perpendicular” on I get a value of 574478 returned.
What am I missing? I tried to replicate the example but it gave an error. Clearly I still have a lot to learn about python!!
"""Returns or sets the object snap mode. Object snaps are tools for
specifying points on existing objects
Parameters:
mode [opt] = The object snap mode or modes to set. Object snap modes
can be added together to set multiple modes
0 None
2 Near
8 Focus
32 Center
64 Vertex
128 Knot
512 Quadrant
2048 Midpoint
8192 Intersection
0x20000 End
0x80000 Perpendicular
0x200000 Tangent
0x8000000 Point
Returns:
if mode is not specified, then the current object snap mode(s)
if mode is specified, then the previous object snap mode(s)
"""
That folder contains all the files that constitute Rhinoscriptsyntax for Python. If you open any of them in a text editor, it shows all the Rhinocommon methods for that category that the rhinoscriptsyntax is calling. An excellent guide for delving into RhinoCommon as well, and perhaps for detecting the occasional bug. I created a shortcut to this folder (or a Win 8 tile) as I consult stuff in there rather often.
rs.OsnapMode is in application.py and what I posted is part of the docstring (long comment) with a description of the method.
Dan you can also just step through the rs.Whatever() by running it in the Python editor with a break point- this (potentially) takes you through all the relevant py files at the relevant locations as you step through it, so you can see the RhinoCommon stuff go by.