Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5897

Storing calculations inside class with python

$
0
0

Hello,

I want to create a class with a number of related properties which are calculated inside the class when certain property is assigned but I can not make it…

python code below is a simplified version of my class, which does not work as expected

two values displayed on the end should not be the same, but they are…

what am I doing wrong ?

thanks in advance…

import rhinoscriptsyntax as rs

class Test:

    def __init__(self,obj=None):
    
        self.Object=obj
        self.Volume=0.0
        self.m3=0.0

    def Volume(self):
        return self.Volume
    
    def Volume(self,x):
        self.Volume=x
        self.m3=x/1000000000

    def m3(self):
         return self.m3

def m3():

    obj = rs.GetObject()

    T = Test(obj)
    vol = rs.SurfaceVolume(obj)[0]
    T.Volume =vol

    print vol
    print T.m3

return

m3()

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 5897

Trending Articles