Skip to content

Instantly share code, notes, and snippets.

@pgolay
Last active June 7, 2019 17:26
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 pgolay/2e6dab632c9f962a1e1ab2cbba9da7d0 to your computer and use it in GitHub Desktop.
Save pgolay/2e6dab632c9f962a1e1ab2cbba9da7d0 to your computer and use it in GitHub Desktop.
Select the outer user set number of points from a curve or surface, optionally the inverse
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
def SelOuterPoints():
ids = None
while True:
maxPts = 1
if sc.sticky.has_key('MAX_OUTER_PTS'):
maxPts = sc.sticky['MAX_OUTER_PTS']
flip = False
if sc.sticky.has_key('FLIP_OUTER_PTS'):
flip = sc.sticky['FLIP_OUTER_PTS']
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select open curves and surfaces.")
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve|Rhino.DocObjects.ObjectType.Surface
go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.OpenSurface |Rhino.Input.Custom.GeometryAttributeFilter.OpenCurve
go.AcceptNumber(True, False)
opInvert = Rhino.Input.Custom.OptionToggle(flip, 'No', 'Yes')
go.AddOptionToggle("InvertPoints", opInvert)
opMax = Rhino.Input.Custom.OptionInteger(maxPts, True,1)
go.AddOptionInteger("NumberOfPoints", opMax)
rc = go.GetMultiple(1,0)
if go.CommandResult()!=Rhino.Commands.Result.Success:
return go.CommandResult()
if rc==Rhino.Input.GetResult.Number:
num = go.Number()
if num.is_integer:
maxPts = int(num)
sc.sticky['MAX_OUTER_PTS'] = maxPts
continue
if rc==Rhino.Input.GetResult.Option:
maxPts = opMax.CurrentValue
flip = opInvert.CurrentValue
sc.sticky['FLIP_OUTER_PTS'] = flip
sc.sticky['MAX_OUTER_PTS'] = maxPts
continue
if rc==Rhino.Input.GetResult.Object:
ids = [go.Object(n).ObjectId for n in range(go.ObjectCount)]
break
if not ids: return
if not maxPts: return
sc.sticky['MAX_OUTER_PTS'] = maxPts
SelThePoints(maxPts, ids, flip)
def SelThePoints(ptCount, ids, flip):
rs.EnableRedraw(False)
for id in ids:
if rs.ObjectGripsSelected(id):
rs.EnableObjectGrips(id, False)
rs.EnableObjectGrips(id)
selIdx = []
if rs.IsCurve(id):
count = rs.CurvePointCount(id)
for i in range(0, ptCount):
selIdx.append(i)
selIdx.append((count -1)-i)
else:
srf = rs.coercegeometry(id).Faces[0].UnderlyingSurface()
pts = srf.Points
count = rs.SurfacePointCount(id)
max = count[0] * count[1]
# U
if not srf.IsClosed(0):
for n in range(0,count[1]):
selIdx.append (n)
for i in range(1, ptCount):
selIdx.append (n + (i*count[1]))
for n in range(max-count[1], max):
selIdx.append( n)
for i in range(1, ptCount):
selIdx.append(n - (i*count[1]))
#V
if not srf.IsClosed(1):
for n in range(0,count[0]):
idxNear = n*count[1]
idxFar = idxNear + count[1]-1
selIdx.append( idxNear )
selIdx.append(idxFar)
for i in range(ptCount):
selIdx.append(idxNear + i)
selIdx.append(idxFar - i)
if flip:
for i in range(count[0] * count[1]):
if i not in selIdx: rs.SelectObjectGrip(id, i)
else:
for i in selIdx:
rs.SelectObjectGrip(id, i)
rs.EnableRedraw(True)
if __name__ == '__main__': SelOuterPoints()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment