-
Notifications
You must be signed in to change notification settings - Fork 335
/
Copy pathSampleSetCurveWeight.py
55 lines (49 loc) · 2.21 KB
/
SampleSetCurveWeight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
################################################################################
# SampleSetCurveWeight.py
# Copyright (c) 2018 Robert McNeel & Associates.
# See License.md in the root of this repository for details.
################################################################################
import clr
import Rhino
import System
import rhinoscriptsyntax as rs
import scriptcontext as sc
################################################################################
# Set the weight of a curve control point like the Weight command.
# Keeping this version so I have reference to a fancy Overloads example.
################################################################################
def SetCurveWeightEx(nc, i, w):
nc.Points.MakeRational()
# There are a couple of versions of NurbsCurvePointList.GetPoint.
# This code helps call the correct one.
tref = clr.GetClrType(Rhino.Geometry.Point3d).MakeByRefType()
rc, p = nc.Points.GetPoint.Overloads[System.Int32, tref](i)
if w != 1.0 and Rhino.RhinoMath.IsValidDouble(w):
nc.Points.SetPoint(i, p, w)
else:
nc.Points.SetPoint(i, p, 1.0)
################################################################################
# Set the weight of a curve control point like the Weight command.
################################################################################
def SetCurveWeight(nc, i, w):
nc.Points.MakeRational()
p = nc.Points[i].Location
if w != 1.0 and Rhino.RhinoMath.IsValidDouble(w):
nc.Points.SetPoint(i, p, w)
else:
nc.Points.SetPoint(i, p, 1.0)
################################################################################
# Main function
################################################################################
def SampleSetCurveWeight():
crv_id = rs.GetObject(preselect=True)
crv = rs.coercecurve(crv_id)
nc = crv.ToNurbsCurve()
SetCurveWeight(nc, 2, 0.1)
sc.doc.Objects.Replace(crv_id, nc)
sc.doc.Views.Redraw()
# Check to see if this file is being executed as the "main" python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.
if __name__ == "__main__":
SampleSetCurveWeight()