Importing SharpCap loses access to SharpCap application object (and a few other basic questions)

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
FlankerOneTwo
Posts: 6
Joined: Sun Feb 25, 2024 6:14 pm

Importing SharpCap loses access to SharpCap application object (and a few other basic questions)

#1

Post by FlankerOneTwo »

Hi,

I've noticed that "import SharpCap" (which I need to do in order to access things like tracking rate, etc) reassigns the SharpCap identifier to the module, whereas it previously referred to the Application object. I can do "SC = SharpCap" before this of course to save the Application object, but is there a way to refer to it after the SharpCap module has been imported? I see that it is of type SharpCap.Models.Application but there doesn't seem to be a way to get a handle to the active application from that class.

The related question is, is there a way to reinitialize the Python environment, or force a running script to use a new environment? If I've run the script once, "SharpCap" has been redirected to point to the module, then when I re-run the script during debugging, the line SC = SharpCap obviously no longer works correctly. That's why I'd rather set "SC" more directly instead of with the potentially ambiguous "SharpCap". I could just set a "FIRST_RUN" variable to know whether or not to set SC, but that seems like a kludge.

What are the different options for the MessageBoxButtons?
Is there a method construct a dialog box for the user to input values?
Is there a way to know which instance of SharpCap this is, if there are multiple instances running on the same machine?
Finally, is there a way to sound a beep, play an audio file, etc?

Thanks!

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

Re: Importing SharpCap loses access to SharpCap application object (and a few other basic questions)

#2

Post by admin »

Hi Patrick,

you can use 'import SharpCap as XYZ' to avoid the name clash, although there isn't a great deal directly in the SharpCap root namespace that is useful for scripting. It may be better to import the types you want with 'import typename from SharpCap.Base' or whatever. Note that stuff you might find beyond what can be found by exploring from the base SharpCap object is not officially supported via scripting and may change/vanish if I need to make changes.

The MessageBoxButtons type comes from the underlying Windows Forms framework (https://learn.microsoft.com/en-us/dotne ... esktop-8.0) you can clr.AddReference to System.Windows.Forms.dll and then import the type. You should also use Windows Forms to create any UI that you want - this can be done in python, but may be easier in C# (make a DLL with the form in it, use it from your python).

I think you can work out the instance number from SharpCap.Caption which gives you the title of the main window.

Sound should be playable using the same approach that would work for C# - just translate the calls to python - System.Media.SystemSounds.Exclamation.Play() would probably get something (after appropriate clr.AddReference).

There is no way to re-init the environment without restarting SharpCap though...

cheers,

Robin
FlankerOneTwo
Posts: 6
Joined: Sun Feb 25, 2024 6:14 pm

Re: Importing SharpCap loses access to SharpCap application object (and a few other basic questions)

#3

Post by FlankerOneTwo »

Perfect, thanks so much for your help. This is amazing work that you've done, and will make for some amazing (hopefully fully automated) eclipse imaging!
Post Reply