Hello.
I use "ZEN 2.6 system" and create a macro.
I'm using a ".czexp" file, but the <RelativeSearchRange> parameter setting doesn't work.
Have you hit on any possible causes of the problem?
By the way, Z stack setting using "Zen.Acquisition.Execute" seems to have no problem.
Code:
experiment1 = Zen.Acquisition.Experiments.GetByName("MyExp.czexp")
outputexp = Zen.Acquisition.FindAutofocus(experiment1)
experiment1.Close()
FindAutofocus experiment
Thank you for your reply.
I already set <IsAutomaticRange> to "false".
[ATTACH]427[/ATTACH]
Attach two files.
The range doesn't change when I run it from a macro.
If I manually switch files from ZEN, the range will change.
I thank you in advance for your reply.
I already set <IsAutomaticRange> to "false".
[ATTACH]427[/ATTACH]
Attach two files.
The range doesn't change when I run it from a macro.
If I manually switch files from ZEN, the range will change.
I thank you in advance for your reply.
- Attachments
-
- czexp_file.zip
- (15.88 KiB) Downloaded 188 times
Hello Yosuke,
yes, you are right! This is a bug!
But I can offer you a workaround:
This worked for me in Zen 2.6 HF7.
yes, you are right! This is a bug!
But I can offer you a workaround:
Code: Select all
ze = ZenExperiment()
ze.Load('MyExp')
outputexp = Zen.Acquisition.FindAutofocus(ze)
Configuring SWAF from Python Script
HI guys,
to be able to adjust the SWAF from a script please use code like this:
to be able to adjust the SWAF from a script please use code like this:
Code: Select all
from System import Array
from System import ApplicationException
from System import TimeoutException
blockindex = 1
exp = Zen.Acquisition.Experiments.GetByName('001_Detail_Zoom=10')
##############################
### SetAutofocusParameters ###
##############################
# Method 1. Call SetAutofocusParameters and directly modify whatever you want to modify. ##
# Does not work via COM. ##
# By default, all acquisition blocks are modified.
exp.SetAutofocusParameters(sampling = ZenSoftwareAutofocusSampling.Fine)
exp.SetAutofocusParameters(searchStrategy = "Smart", fixedRangeLowerLimit = -123, fixedRangeUpperLimit = 321)
# Pass the 'block' argument to modify only one block.
# Block indices start at zero (1).
exp.SetAutofocusParameters(block=blockindex, sampling=ZenSoftwareAutofocusSampling.Coarse)
# You can also use static method syntax to call SetAutofocusParameters.
ZenSoftwareAutofocusExperimentExtensions.SetAutofocusParameters(exp, sampling=ZenSoftwareAutofocusSampling.Fine)
ZenSoftwareAutofocusExperimentExtensions.SetAutofocusParameters(exp, searchStrategy = "Smart", fixedRangeLowerLimit=-123, fixedRangeUpperLimit = 321)
ZenSoftwareAutofocusExperimentExtensions.SetAutofocusParameters(exp, block=blockindex, sampling=ZenSoftwareAutofocusSampling.Coarse)
# Method 2. Create a new ZenSoftwareAutofocusSetting and set whatever you want to set. Then call SetAutofocusParameters. ##
# Works in COM. ##
s = ZenSoftwareAutofocusSetting()
s.Sampling = ZenSoftwareAutofocusSampling.Fine
s.SearchStrategy = "Smart"
s.SetSearchRangeFixed(-200, 300)
# This can be persisted as XML.
print(s.XML)
s.SaveToXmlFile(r'c:\Output\bla.xml')
s = ZenSoftwareAutofocusSetting()
s.LoadFromXmlFile(r'c:\Output\bla.xml')
print(s.XML)
# SetAutofocusParameters:
exp.SetAutofocusParameters(s)
# With explicit block
exp.SetAutofocusParameters(s, block=blockindex)
# Static method syntax.
ZenSoftwareAutofocusExperimentExtensions.SetAutofocusParameters(exp, s)
ZenSoftwareAutofocusExperimentExtensions.SetAutofocusParameters(exp, s, block=blockindex)
# Method 3. Get the ZenSoftwareAutofocusSetting from the experiment. ##
# Works in COM. ##
# By default, get the parameters from the current experiment block.
s = exp.GetAutofocusParameters()
# Or specify block explicitly.
s = exp.GetAutofocusParameters(blockindex)
s.Sampling = ZenSoftwareAutofocusSampling.Medium
print(s.XML)
exp.SetAutofocusParameters(s)
##############################
### FindAutofocus (Locate) ###
##############################
# This method is now guaranteed to return AFTER the autofocus has finished.
# It now returns the z of maximum sharpness unless an autofocus error occurs.
# In that case it will raise an ApplicationException.
# The default timeout is 30 s.
# If the method times out you will get a TimeOutException.
try:
print("Zen.Acquisition.FindAutofocus()")
z = Zen.Acquisition.FindAutofocus()
print(z)
except ApplicationException as e:
print(e.Message)
except TimeoutException as e:
print(e.Message)
# You can also specify a timeout explicitly (in seconds).
try:
print("Zen.Acquisition.FindAutofocus(1)")
z = Zen.Acquisition.FindAutofocus(1)
print(z)
except ApplicationException as e:
print(e.Message)
except TimeoutException as e:
print(e.Message)
# A timeout of zero or less disables the timeout.
try:
print("Zen.Acquisition.FindAutofocus(0)")
z = Zen.Acquisition.FindAutofocus(timeoutSeconds=0)
print(z)
except ApplicationException as e:
print(e.Message)
exp.Close()
##################################
### FindAutofocus (Experiment) ###
##################################
#exp = Zen.Acquisition.Experiments.ActiveExperiment
exp = Zen.Acquisition.Experiments.GetByName('001_Detail_Zoom=10')
exp.SetAutofocusParameters(searchStrategy="Full", sampling=ZenSoftwareAutofocusSampling.Coarse, relativeRangeSize=105)
# This method is now guaranteed to return AFTER the autofocus has finished.
# It now returns the z of maximum sharpness unless an autofocus error occurs.
# In that case it will raise an ApplicationException.
# The default timeout is 30 s.
# If the method times out you will get a TimeOutException.
try:
print("Zen.Acquisition.FindAutofocus(exp)")
z = Zen.Acquisition.FindAutofocus(exp)
print(z)
except ApplicationException as e:
print(e.Message)
except TimeoutException as e:
print(e.Message)
# You can also specify a timeout explicitly (in seconds).
try:
print("Zen.Acquisition.FindAutofocus(exp, 1)")
z = Zen.Acquisition.FindAutofocus(exp, 1)
print(z)
except ApplicationException as e:
print(e.Message)
except TimeoutException as e:
print(e.Message)
# A timeout of zero or less disables the timeout.
try:
print("Zen.Acquisition.FindAutofocus(exp, 0)")
z = Zen.Acquisition.FindAutofocus(exp, timeoutSeconds=0)
print(z)
except ApplicationException as e:
print(e.Message)
exp.Close()