Question about SharpCap.RunRefocus

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
Eyeke2
Posts: 26
Joined: Thu Mar 14, 2024 4:08 pm

Question about SharpCap.RunRefocus

#1

Post by Eyeke2 »

I’d like to call SharpCap.RunRefocus() periodically from a script, but it appears that this function requires a successful focusing scan to have been run first. If no previous focusing scan exists, the call fails with an error message saying that a focusing scan must be performed first.

Is there any scripting/API-accessible interface or property that can be used to check whether a valid previous focusing scan exists before calling SharpCap.RunRefocus()?
User avatar
admin
Site Admin
Posts: 17342
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Question about SharpCap.RunRefocus

#2

Post by admin »

Hi,

not directly, but you can take advantage of the sequencer equivalent 'REFOCUS' step, which fails without a message box if there is no data. From python, you can use this as follows

Code: Select all

>>> def Progress(sender, args):
... 	print(args.EventData)
... 
>>> SharpCap.Sequencer.Progress += Progress
>>> SharpCap.Sequencer.RunSequence("REFOCUS")
Starting  : 
Starting  : Refocus using the same settings as the most recently used autofocus run
Error     : 'No previous autofocus information stored, cannot refocus' while running step Refocus using the same settings as the most recently used autofocus run
Info      : 'No previous autofocus information stored, cannot refocus' while running step 
End       : Sequence halted due to error.
>>> SharpCap.Sequencer.Progress -= Progress
Finished
By putting some logic in the progress event handling, you can work out if the refocus failed due to no data or some other reason, or if it ran OK.

cheers,

Robin
Eyeke2
Posts: 26
Joined: Thu Mar 14, 2024 4:08 pm

Re: Question about SharpCap.RunRefocus

#3

Post by Eyeke2 »

Thanks, Robin! Very fast reply as usual, and very helpful.

I’ll give the sequencer `REFOCUS` step approach a try. That should be enough for my current use case, especially if it fails cleanly without showing a message box when no previous autofocus data is available.

If at some point you add a scripting/API method to query the most recent autofocus/refocus state or results directly, I’d be very interested to know.

Regards,
Leo
Eyeke2
Posts: 26
Joined: Thu Mar 14, 2024 4:08 pm

Re: Question about SharpCap.RunRefocus

#4

Post by Eyeke2 »

Will the messages captured by Progress event handler be always in plain English, or will they be different for localized language version of SharpCap?

Thanks,
Leo
admin wrote: Sat Jun 13, 2026 1:03 pm Hi,

not directly, but you can take advantage of the sequencer equivalent 'REFOCUS' step, which fails without a message box if there is no data. From python, you can use this as follows

Code: Select all

>>> def Progress(sender, args):
... 	print(args.EventData)
... 
>>> SharpCap.Sequencer.Progress += Progress
>>> SharpCap.Sequencer.RunSequence("REFOCUS")
Starting  : 
Starting  : Refocus using the same settings as the most recently used autofocus run
Error     : 'No previous autofocus information stored, cannot refocus' while running step Refocus using the same settings as the most recently used autofocus run
Info      : 'No previous autofocus information stored, cannot refocus' while running step 
End       : Sequence halted due to error.
>>> SharpCap.Sequencer.Progress -= Progress
Finished
By putting some logic in the progress event handling, you can work out if the refocus failed due to no data or some other reason, or if it ran OK.

cheers,

Robin
User avatar
admin
Site Admin
Posts: 17342
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Question about SharpCap.RunRefocus

#5

Post by admin »

Hi,

they are always in English - very little of the user interface is localised and even less of things like notification messages.

I will be adding a 'CanRefocus' property into SharpCap 4.2 to make this a bit easier.

cheers,

Robin
Eyeke2
Posts: 26
Joined: Thu Mar 14, 2024 4:08 pm

Re: Question about SharpCap.RunRefocus

#6

Post by Eyeke2 »

Thank you, Robin. That would be a very welcome addition to the SharpCap scripting API. I’ll follow this topic for updates.

Regards,
Leo
Post Reply