Skip to content

Instantly share code, notes, and snippets.

@onionmk2
Last active February 16, 2020 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onionmk2/84bcf625e50798bfd659bc2a3b3af503 to your computer and use it in GitHub Desktop.
Save onionmk2/84bcf625e50798bfd659bc2a3b3af503 to your computer and use it in GitHub Desktop.
show "control points" or "solid point" in rhono
#from typing import Any, Iterable
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
doc = Rhino.RhinoDoc.ActiveDoc # type: Rhino.RhinoDoc
objectTable = doc.Objects # type: Rhino.DocObjects.Tables.ObjectTable
selected_objects = objectTable.GetSelectedObjects(includeLights=False, includeGrips=False) # type: Iterable[Rhino.DocObjects.RhinoObject]
# selected_objects, whose type is EnumeratorWrapper, can not use len(selected_objects) nor selected_objects.Count
selection_exists_count = 0
for o in selected_objects:
selection_exists_count = selection_exists_count + 1
if selection_exists_count ==0:
# prompt user selection
objs = rs.GetObjects("Select objects") # type: Iterable[Rhino.DocObjects.RhinoObject]
else:
# obj = selected_objects don't work. Perhaps because one EnumeratorWrapper can one iteration, we have to assign again.
objs = objectTable.GetSelectedObjects(includeLights=False, includeGrips=False)# type: Iterable[Rhino.DocObjects.RhinoObject]
curves_of_surfs = []
poly_surfaces = []
for obj in objs:
if rs.IsPolysurface(obj):
# for some reason,
# we can not do rs.Command("_SolidPtOn Enter") here
poly_surfaces.append(obj)
else:
# we cannot use rs.EnableObjectGrips(obj) because the points disappear after selection changed.
if rs.IsCurve(obj) or rs.IsSurface(obj):
curves_of_surfs.append(obj)
for obj in curves_of_surfs:
rs.Command("_SelNone")
rs.SelectObject(obj)
rs.Command(" _PointsOn Enter")
# Note:
# if obj is closed-polysurface,
# we can not use _PointsOn.
# we can use _SolidPtOn
# if obj is open-polysurface,
# we can not use _PointsOn.
# we **can** use _SolidPtOn
for obj in poly_surfaces:
rs.Command("_SelNone")
rs.SelectObject(obj)
rs.Command("_SolidPtOn Enter")
rs.Redraw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment