Hi,
I tried to use Zen.Application.RunMacro('My Macro') within an existing macro but the system complaints about recursively starting a macro. Is there a way to do that? If not, do you have any recommendation for a workaround? The OADs tend to consist of a mixture of Zen-specific commands and ironpython so as far as I can see it is not just to transform them into separate .py files which I could call from my main OAD macro.
Kind Regards
Fredrik Olsson
Run a second Zen macro from main macro
Hi,
I made some tests. I started with an OAD script, removed intitial and end info within brackets and change file type to .py since in my Zen 2 Core v2.5 I could not see anyway to save the macro directly as a .py file. I then imported the py module into an OAD macro. Ordinary ironpython stuff in the py module works fine when calling functions but Zen-related commands fail. Any suggestion?
BR
Fredrik Olsson
I made some tests. I started with an OAD script, removed intitial and end info within brackets and change file type to .py since in my Zen 2 Core v2.5 I could not see anyway to save the macro directly as a .py file. I then imported the py module into an OAD macro. Ordinary ironpython stuff in the py module works fine when calling functions but Zen-related commands fail. Any suggestion?
BR
Fredrik Olsson
Hello Fredrik,
Zen.Application.RunMacro does not work under Zen Core and is not recommended in Zen blue.
Zen.Application.RunMacro does not work under Zen Core and is not recommended in Zen blue.
In a module Zen is not defined and you have to pass Zen like a variable to the module function.Ordinary ironpython stuff in the py module works fine when calling functions but Zen-related commands fail.
Hi,
Do you mean passing "Ze i s s . Micro . S c r i p t i n g . ZenWrapperLM"? and then define set Zen within the py-file which I have seen in some examples?
My main problem is that my OAD library tend to grow and needs to be separated into separate modules which can be called from a main OAD macro.
BR
Fredrik Olsson
Do you mean passing "Ze i s s . Micro . S c r i p t i n g . ZenWrapperLM"? and then define set Zen within the py-file which I have seen in some examples?
My main problem is that my OAD library tend to grow and needs to be separated into separate modules which can be called from a main OAD macro.
BR
Fredrik Olsson
What I mean is something like
I hope this helps!
Code: Select all
class MyClass:
def MyFunction(self, Zen):
Zen.Windows.Show('Test')
myClass = MyClass()
myClass.MyFunction(Zen)
-
- Posts: 7
- Joined: Sat Aug 15, 2020 5:18 am
Re: Run a second Zen macro from main macro
Revisiting this post from long ago...
I have repeatedly tried this , and always get "No module named..." error when trying this.
For example, I have "temp.czmac";
and also I have "temp1.czmac", saved in the same macro folder.
I tried also saving the temp1.czmac in the Zen.exe folder, but no luck.
What obvious thing am I missing here?
I have repeatedly tried this , and always get "No module named..." error when trying this.
For example, I have "temp.czmac";
Code: Select all
import temp1
myClass = MyClass()
myClass.MyFunction(Zen)
Code: Select all
class MyClass:
def MyFunction(self, Zen):
Zen.Windows.Show('Test')
What obvious thing am I missing here?
-
- Posts: 180
- Joined: Wed May 20, 2020 10:10 am
Re: Run a second Zen macro from main macro
Hello Dan,
there are mainly two ways to do it:
One file:
Two files:
MyClassLib.py
MyClassProg.czmac
For simplicity MyClassLib.py is in the same folder as MyClassProg.czmac
Now, starting MyClassProg should work.
there are mainly two ways to do it:
One file:
Code: Select all
class MyClass:
def MyFunction(self, Zen):
Zen.Windows.Show('Test')
myClass = MyClass()
myClass.MyFunction(Zen)
MyClassLib.py
Code: Select all
class MyClass:
def MyFunction(self, Zen):
Zen.Windows.Show('Test')
Code: Select all
from MyClassLib import MyClass
myClass = MyClass()
myClass.MyFunction(Zen)
Now, starting MyClassProg should work.