#######################################################
## M I C R O S C O P E
##
## Macro name: Get and set focus position
## Required files: none
## Required hardware: microscope with motorized focus drive
##
## GET FOCUS POSITION
## SET FOCUS POSITION
##
#######################################################
##
##
## Remove all open images
Zen.Application.Documents.RemoveAll()
##
##
## Get current focus position
## Show focus position
focPos = Zen.Devices.Focus.ActualPosition
focusinfo = 'Focus Pos: ' + str(focPos)
Zen.Windows.Show(focusinfo)
##
##
## Set focus position
## Show new focus position
newfocPos = focPos + 50
Zen.Devices.Focus.MoveTo(newfocPos)
## an alternative to set the position
#Zen.Devices.Focus.TargetPosition = newfocPos
#Zen.Devices.Focus.Apply()
focusinfo = 'New Focus Pos: ' + str(Zen.Devices.Focus.ActualPosition)
Zen.Windows.Show(focusinfo)
##
#######################################################
Is there a direct way to move the objective to the load position and back to the work position? I can do it by storing the values, but I would like to avoid this step.
text=("Focus on sample.\n" +
"Press continue when done.")
Zen.Application.Pause(text)
focusWork=Zen.Devices.Focus.ActualPosition
text=("Move objective to load position.\n" +
"Press continue when done.\n" +
"Objective will move back to work positon.")
Zen.Application.Pause(text)
focusLoad=Zen.Devices.Focus.ActualPosition
Zen.Devices.Focus.MoveTo(focusWork)
Is there anyway to programatically change the software autofocus settings (e.g. Sampling, Quality, Range Coverage, Sharpness Measure, Search Range, The actual range, Automatic Range and Autofocus ROI) ? I know I could do auto focus by calling Zen.Acquisition.FindAutoFocus()
this is an open feature request already for the ZEN Software regarding OAD interface. So with the current version this is not possible, But there are still a few things one can do.
SWAF_experiment = Zen.Acquisition.Experiments.GetByName(SWAF_Experiment_Name)
# !!! ATTENTION - ADVANCED TOPIC !!!
# optional - modify your experiment here when required by modifying the experiment XML directly
# run the SWAF
Zen.Acquisition.FindAutofocus(SWAF_experiment)
# get the resulting z-position after SWAF
z_SWAF = Zen.Devices.Focus.ActualPosition
The actual experiment must be set up on as usual on the acquisition tab.
By the way, it is also possible to create experiments with an extra channel for the SWAF only, which is not used during the actual acquistion.
this is an open feature request already for the ZEN Software regarding OAD interface. So with the current version this is not possible, But there are still a few things one can do.
SWAF_experiment = Zen.Acquisition.Experiments.GetByName(SWAF_Experiment_Name)
# !!! ATTENTION - ADVANCED TOPIC !!!
# optional - modify your experiment here when required by modifying the experiment XML directly
# run the SWAF
Zen.Acquisition.FindAutofocus(SWAF_experiment)
# get the resulting z-position after SWAF
z_SWAF = Zen.Devices.Focus.ActualPosition
The actual experiment must be set up on as usual on the acquisition tab.
By the way, it is also possible to create experiments with an extra channel for the SWAF only, which is not used during the actual acquistion.