bolsover
Senior Member
I'm doing my level best to create some reusable scripts for a new project - but one particular issue is causing me real problem..
I want to break the project into a few modules and have a 'main' script that accepts user input and collects the values into an array and calls routines from the modules as needed.
The problem I'm facing is that I can't figure out how to invoke (some) AlibreScript classes methods from these separate modules.
I have the following 'main' script:
This part of test case does draw a circle on the XY plane using the public constructor circlea = Circle([1,1], 3, False)
The script then instantiates a new TestClass from the separate Python file (module) 'CalledModule'
Here is the code for the CalledModule file:
This code will draw circlea but fails with the call to circleb = Circle([0,0],5,False) with the message "NameError: global name 'Circle' is not defined"
I don't understand why this should fail in the CalledModule when the same code in the 'main' routine runs without problem.
I'm guessing I need some import statement - but I can't work out what that might be.
Any help would be much appreciated.
DB
I want to break the project into a few modules and have a 'main' script that accepts user input and collects the values into an array and calls routines from the modules as needed.
The problem I'm facing is that I can't figure out how to invoke (some) AlibreScript classes methods from these separate modules.
I have the following 'main' script:
This part of test case does draw a circle on the XY plane using the public constructor circlea = Circle([1,1], 3, False)
The script then instantiates a new TestClass from the separate Python file (module) 'CalledModule'
Code:
from __future__ import division
sys.path.append(ScriptFolder)
import CalledModule
reload(CalledModule)
part = CurrentPart()
sketch = part.AddSketch("Test", part.GetPlane('XY-Plane'))
circlea = Circle([1,1], 3, False)
sketch.AddCircle(circlea)
testClass = CalledModule.TestClass(sketch)
Here is the code for the CalledModule file:
This code will draw circlea but fails with the call to circleb = Circle([0,0],5,False) with the message "NameError: global name 'Circle' is not defined"
I don't understand why this should fail in the CalledModule when the same code in the 'main' routine runs without problem.
I'm guessing I need some import statement - but I can't work out what that might be.
Code:
from __future__ import division
class TestClass:
def __init__(self, sk):
self.sketch = sk
self.drawCircle()
def drawCircle(self):
circlea = self.sketch.AddCircle(1,1, 8, False)
self.sketch.AddDimension(circlea)
print circlea.Radius
circleb = Circle([0,0],5,False)
self.sketch.AddCircle(circleb)
Any help would be much appreciated.
DB