2
$\begingroup$

My .py file got big enough that it was time to split it into multiple files. Originally, it would have some bpy.props, then later functions could access that with

    lanes = bpy.props.IntProperty( 
    name = "Lanes",
    default = 2,
    description = "Number of lanes"
    )

def execute (self, context):
    def someFunction():
        print(self.lanes)

someFunction is now so big enough I split it into a separate file, imported with importlib.reload. init.py runs and can import that function and run it, but messes up when trying to refer to self again:

curveSetup() missing 1 required positional argument: 'self'

The script previously found self because it was one giant file. how do I access self again now they're in different files?

$\endgroup$
  • $\begingroup$ I'm not super familiar with with python in blender, but it sounds like you're having a scope problem. When working with python, you'll want to split up classes and functions into separate files pretty commonly - since Blender's Python is no different, you should have no problem doing the same. In your example however, you provide very little detail. How are your files structured? What do they look like? "self" is usually a variable accessed from within a class instance. Your snippet doesn't include a Class definition. $\endgroup$ – MaVCArt Mar 30 '18 at 21:47
1
$\begingroup$

A buddy helped out with this. In the secondary file, I added an optional argument def someFunction(lanes) and use print(lanes) instead of print(self.lanes). Then in init.py, when I call the function I use someFunction(self.lanes)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.