Access to Capture Profiles

Discussions on extending SharpCap using the built in Python scripting functionality
Inok
Posts: 5
Joined: Mon Oct 04, 2021 6:38 pm

Access to Capture Profiles

#1

Post by Inok »

Hi, I would like to get the loaded name of the Capture Profiles in the Camera Control Panel but I don't find the object. Is this object accessible in python?
User avatar
admin
Site Admin
Posts: 13177
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Access to Capture Profiles

#2

Post by admin »

Hi,

unfortunately not with Python scripting - you can only load and save profiles, not query the name of the currently loaded profile.

sorry,

Robin
Inok
Posts: 5
Joined: Mon Oct 04, 2021 6:38 pm

Re: Access to Capture Profiles

#3

Post by Inok »

Hi Robin, Thanks for the quick reply. I try to explain my pain, perhaps is there a better way to solve it.
I work for a public observatory and SharpCap is used by several demonstrators. We want to simplify the operation for live stacking. We already defined the object of interest as capture profile. The final solution is to load the capture profile according the object telescope is pointing. For this I want to start a server in python to communicate with the telescope software. When I get the object from the telescope SW I would load the the capture profile.
When live stacking is done, we would store the image to a web server for accessing by the visitors.
In the first step (my question is pointing) I just want to store the image to the web server.
I thought to use the TargetName field but then the demonstrators has to enter the name first.
You see, behind my question is a more complex use case.
Is there a better way or is it possible to get access to the capture profile object in one of the next releases?

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

Re: Access to Capture Profiles

#4

Post by admin »

Hi Konrad,

I was going to suggest a workaround using the 'Notes' field in the capture profile, but I just tested and it looks like that field is not loaded from profile :(

I will add a 'LastLoadedProfile' property to the camera - it will be read only, but should solve your use case.

cheers,

Robin
Inok
Posts: 5
Joined: Mon Oct 04, 2021 6:38 pm

Re: Access to Capture Profiles

#5

Post by Inok »

Thank you Robin,
I will test it as soon it is available.
Best regards
Konrad
amister
Posts: 7
Joined: Wed Aug 02, 2023 3:47 pm

Re: Access to Capture Profiles

#6

Post by amister »

Hi, I was wondering if someone could provide the API object needed to load a capture profile. I tried navigating the api via the help and "." functions but it's not obvious to me (I'm not a native scripter/programmer).

If someone could provide the object then I was going to use chatgpt to help me create a python script that would load one capture profile from time range X, and a different capture profile for time range Y.


So far I found SharpCap.Settings.CaptureProfiles.Equals but when I try to use that in the console it tells me it's read only object.


Thank you in advance.
User avatar
admin
Site Admin
Posts: 13177
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Access to Capture Profiles

#7

Post by admin »

Hi,

you can load a profile by name like this

Code: Select all

SharpCap.SelectedCamera.LoadCaptureProfile("test (ZWO ASI174MC)")
Note that the name of the profile here is 'test' - the extra space and the name of the camera in parenthesis afterwards is required for the load to work.

cheers,

Robin
amister
Posts: 7
Joined: Wed Aug 02, 2023 3:47 pm

Re: Access to Capture Profiles

#8

Post by amister »

thank you!
amister
Posts: 7
Joined: Wed Aug 02, 2023 3:47 pm

Re: Access to Capture Profiles

#9

Post by amister »

HI, I was able to get a script working that changes the profile based on time and it's working great.

I've decided to try and enhance the script by having it make a API call to a 3rd party service and obtain that sunset and sunrise times for that geo area, and then change the profile based on those times.

The problem is the script needs to import the 'requests' module and I'm getting a error from IronPython saying no module named requests.

Is there a way around this or is this just a limitation of the Iron Python implementation?
User avatar
admin
Site Admin
Posts: 13177
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Access to Capture Profiles

#10

Post by admin »

Hi,

as far as I can see, the 'requests' module is not part of the python base library, so it does not get installed with SharpCap (looks like you would normally install it with pip).

If requests is a pure python module then you can obtain the .py code, pop it in a folder and then add it to the python search path, then import it. You would also need to sort out the .py files for any modules it depends on. Unfortunately you cannot do this for any modules that use c-python libraries.

Code: Select all

>>> import sys
>>> sys.path.append("c:\path\to\library")
Another approach is to do it the 'IronPython' way by relying on classes in the .Net framework - for instance

Code: Select all

>>> clr.AddReference("System.Net.Http")
>>> from System.Net.Http import HttpClient
>>> hc = HttpClient()
>>> text = hc.GetStringAsync("https://www.google.com").Result
>>> print(text)
You can even hook into SharpCap's internal implementation of this

Code: Select all

>>> from SharpCap.Sequencer.Steps import AstroEventUtils, TimeOfDay
>>> sunset = AstroEventUtils.GetTimeOfNext(SharpCap, TimeOfDay.Sunset)
>>> print (sunset)
05/08/2023 19:48:00
This will use the location of your ASCOM mount (if connected) or fall back to the location set up for polar alignment if that has been set - or else give an error.

Strictly speaking this last approach depends on internal SharpCap details, so it possibly change in a future version.

cheers,

Robin
Post Reply