Intro to Python Scripting: 19 Simple Class

Software: 
Tag: 
Video Duration: 
6 minutes
Author: 
Zach Downey

This is a very simple and somewhat useless class definition to create a line from two points. It does cover some basics of class creation in Python and is a stepping stone to some more interesting classes we will create later. You can find more info about classes in the Python documentation.

import rhinoscriptsyntax as rs
 
class MyLine:
 
    def __init__(self, pt1, pt2):
 
        self.pt1 = pt1
        self.pt2 = pt2
 
    def makeLine(self):
        rs.AddLine(self.pt1,self.pt2)
 
 
line1 = MyLine([0,0,0], [2,2,2])
line1.makeLine()
 
 
line2 = MyLine([2,0,0], [2,2,2])
line2.makeLine()

Rating

Please rate this tutorial below. Thanks.

5
Average: 4.6 (7 votes)

Comments

actually u forgot to tell us before the example (what is a class!!6),,this tutorial suppose that u have a previous experience in programming ,, it's not for total beginners like myself ,,
actually u forgot to tell us before the example (what is a class!!),,this tutorial suppose that u have a previous experience in programming ,, it's not for total beginners like myself ,,
actually u forgot to tell us before the example (what is a class!!),,this tutorial suppose that u have a previous experience in programming ,, it's not for total beginners like myself ,,

Want to Contribute?

Want to be an author? Drop us a line here we'd love to have you.

Already have a video you'd like to post? Send us a link and we'll get you going.

:)