sharpcap object is not accessible in sharpcap scripting environment
Re: sharpcap object is not accessible in sharpcap scripting environment
Attached is the script I ran for the 2nd example.
- Attachments
-
- SharpCap Pro Scripts for Testing.py
- (5.18 KiB) Downloaded 204 times
- admin
- Site Admin
- Posts: 17580
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: sharpcap object is not accessible in sharpcap scripting environment
Hi,
right, that's a good result - when the bug has occurred we can see that 'SharpCap' is no longer the same object that it was, instead it's a label that is referring to the imported namespace created by (I think) the 'import SharpCap' line. I would take that import out (and maybe the import of SharpCap.UI too if you can get away with it) and see if that helps.
If you need particular types from those namespaces for your script, use 'from SharpCap import <typename>' rather than importing the whole namespace.
cheers,
Robin
right, that's a good result - when the bug has occurred we can see that 'SharpCap' is no longer the same object that it was, instead it's a label that is referring to the imported namespace created by (I think) the 'import SharpCap' line. I would take that import out (and maybe the import of SharpCap.UI too if you can get away with it) and see if that helps.
If you need particular types from those namespaces for your script, use 'from SharpCap import <typename>' rather than importing the whole namespace.
cheers,
Robin
Re: sharpcap object is not accessible in sharpcap scripting environment
I have tried your suggestions before without success. While researching on the Internet, I came across the following suggestion to resolve the problem:
# stash the real object before anything else can clobber it
_original_SharpCap = SharpCap
# everywhere in your code...
# -> call _original_SharpCap instead of SharpCap
cams = _original_SharpCap.Cameras
I tried it and it worked for a while. Eventually, though, I got the same results as before. This is very confusing since the script will work once and then fails thereafter. I do not have this problem with any other software applications, including those I use for photography, home automation, etc. I have tried most everything I could source through searches on the Internet and nothing has worked consistently. Can you suggest some coding I could use as a workaround? I am running Windows 11, 64 bit on a newly purchased laptop. All software and drivers have been updated the their most current version. I really need to get this solved and would appreciate any help you can give me. Thanks in advance ...
# stash the real object before anything else can clobber it
_original_SharpCap = SharpCap
# everywhere in your code...
# -> call _original_SharpCap instead of SharpCap
cams = _original_SharpCap.Cameras
I tried it and it worked for a while. Eventually, though, I got the same results as before. This is very confusing since the script will work once and then fails thereafter. I do not have this problem with any other software applications, including those I use for photography, home automation, etc. I have tried most everything I could source through searches on the Internet and nothing has worked consistently. Can you suggest some coding I could use as a workaround? I am running Windows 11, 64 bit on a newly purchased laptop. All software and drivers have been updated the their most current version. I really need to get this solved and would appreciate any help you can give me. Thanks in advance ...
Re: sharpcap object is not accessible in sharpcap scripting environment
A number of the attributes, e.g. SelectedCamera, Camera, Name, etc. DO NOT appear in the auto-complete menu. Why is that happening in my installation? There is nothing to indicate that my installation of SharpCap was not successful. Additionally, I cannot find any attribute that identifies the "active" camera in the various attribute settings.
- admin
- Site Admin
- Posts: 17580
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: sharpcap object is not accessible in sharpcap scripting environment
Hi,
I think you are still fighting with the same problem of the SharpCap variable being overwritten somehow - once that has happened, you will see all the symptoms you describe...
* Autocomplete will not give the right results any more because 'SharpCap' is no longer the right value
* When you re-start your script again after the SharpCap variable is overwritten, it will reset 'original_SharpCap' to the new (wrong) value of the SharpCap variable
If you only ran the script once during the lifetime of a SharpCap run, then the 'original_SharpCap' would be set correctly and not change and I think all would be fine.
Unfortunately there is no way in Python to define a variable, like 'SharpCap', as being unchangeable, so I can't change the code to protect against this sort of overwriting. What I will do for the next update is add a second variable holding the main SharpCap API object - this will be in a variable called 'SHARPCAP_APPLICATION'. Hopefully this will be much less prone to accidental overwriting because the name will not match any types or namespaces that might be imported or used.
cheers,
Robin
I think you are still fighting with the same problem of the SharpCap variable being overwritten somehow - once that has happened, you will see all the symptoms you describe...
* Autocomplete will not give the right results any more because 'SharpCap' is no longer the right value
* When you re-start your script again after the SharpCap variable is overwritten, it will reset 'original_SharpCap' to the new (wrong) value of the SharpCap variable
If you only ran the script once during the lifetime of a SharpCap run, then the 'original_SharpCap' would be set correctly and not change and I think all would be fine.
Unfortunately there is no way in Python to define a variable, like 'SharpCap', as being unchangeable, so I can't change the code to protect against this sort of overwriting. What I will do for the next update is add a second variable holding the main SharpCap API object - this will be in a variable called 'SHARPCAP_APPLICATION'. Hopefully this will be much less prone to accidental overwriting because the name will not match any types or namespaces that might be imported or used.
cheers,
Robin
Re: sharpcap object is not accessible in sharpcap scripting environment
Has SHARPCAP_APPLICATION been added to the most recent update (not automatic but downloaded from site)? Can you give me the script command to invoke it? I am still having issues with the SharpCap API and do not understand why it's being "changed" or what is causing it to change. Thanks for your help on this matter.
Re: sharpcap object is not accessible in sharpcap scripting environment
Apologies ... I found the solution.