Thursday, August 20, 2009

py2rhino - object methods

Once you have create an instance of a graphic object, you can then start to do stuff with this object using the methods belonging to those objects. Since the list of things that you can do is so long, the the methods have been grouped into sub-namespaces. The main object namespaces are as follows:
  • dupl: duplicate - make copies of an object or parts of an object
  • modf: modify - change the object in some way
  • eval: evaluate - evaluate an object for a given parameter
  • trfm: transform - transform an object, for example move or rotate
  • defm: deform - deform an object, for example shear
  • test: test - perform various test on an object
  • prop: properties - get or set object properties
  • stat: state - the state of the object, for example locking and hiding object
  • func: function - various other functions that can be performed with the object
To create some examples, lets first create a curve:
import py2rhino as p2r
points = ((0,-10,0), (0,0,0),(2,0,0),(3,4,0),(7,9,0))
crv = p2r.obj.NurbsCurve.create_by_pnts(points, degree=3)

Here is a duplication example - rebuilding the curve. Note that the method returns a boolean indicating if it worked or not.
success = crv.dupl.rebuild(4, 20)

Here is a transformation example- moving the curve. Note that the method returns a boolean indicating if it worked or not.
success = crv.trfm.move((0,0,0),(0,0,20))

Here is an evaluation example - getting the tanget at a particular parameter along the curve:
tangent = crv.eval.tangent(0.5)

Here is a deformation example - shearing the object.
tangent = crv.defm.shear((0,0,0), (0,10,0), 45, True)

Here is a test example - testing is a curve is planar - i.e. lies on a plane. All these methods return a boolean value.
tangent = crv.test.is_planar()

Here is a properties example - getting the start point of the curve.
start_point = crv.prop.start_pnt()

Here is a state example - locking the curve.
success = crv.stat.lock(30)

Here is a functions example - dividing a curve to create a series of point along the curve.
points = crv.func.divide_crv(30)

No comments:

Post a Comment