No module named Base

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
cveillet
Posts: 8
Joined: Tue Jul 25, 2023 11:50 pm

No module named Base

#1

Post by cveillet »

Sorry for this basic question (new to SharpCap!) I must be missing something very basic...

I want to launch SharpCap from the command line with a script.

Here is the command:

Code: Select all

C:/"Program Files/SharpCap 4.0 (64 bit)/SharpCap.exe" /runscript "c:\Data\RINGSS\python_code\SharpCap.py"
The script is:

Code: Select all

import clr
clr.AddReference("SharpCap.Base")
clr.AddReference("SharpCap.Interfaces")
from System import AppDomain
clr.AddReference([t for t in AppDomain.CurrentDomain.GetAssemblies() if t.GetName().Name == "SharpCap.App"][0])
del AppDomain
SharpCap.SelectedCamera = SharpCap.Cameras[1]
SharpCap.SelectedCamera = SharpCap.Cameras[0]
SharpCap.SelectedCamera.GetControl(CommonPropertyIDs.Exposure).Value = 0.002
Program is launched, the script is used but fails with this message (in the IronPython Console)

Code: Select all

IronPython 2.7.11 (2.7.11.1000)
[.NETFramework,Version=v4.5 on .NET Framework 4.8.4645.0 (64-bit)]
Type "help", "copyright", "credits" or "license" for more information.
>>> 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Data\RINGSS\python_code\SharpCap.py", line 7, in <module>
ImportError: No module named Base
The last three lines of code in the script work well from the code snippets area of the Console...

I am using SharCap Pro (v4.0.9538, 64 bit)

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

Re: No module named Base

#2

Post by admin »

Hi Christian,

I'm not sure that I can work out why you have the first 6 lines of the script in the first place - those duplicate things that SharpCap does for you when it initializes the python language (and it should do those things before your script it run). The last 3 lines of ths script should be sufficient. However there is a bug in SharpCap 4.0 that means that the /runscript command may not work. This is fixed in SharpCap 4.1.

I do wonder if the duplication of the clr.AddReferences() in the first few lines is causing the issue.

cheers,

Robin
cveillet
Posts: 8
Joined: Tue Jul 25, 2023 11:50 pm

Re: No module named Base

#3

Post by cveillet »

Hi Robin,

I initially thought that I didn't need to add anything to plain code already working from the scripting tool inside SharpCap. As it didn't work out, I thought I would add more information in the script.

I quickly checked that indeed removing the first six lines does not work either. The message I get when opening the console to see what happened is:

Code: Select all

>>> 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Data\RINGSS\python_code\SharpCap.py", line 1, in <module>
NameError: global name 'SharpCap' is not defined
The good news is that the script is sent to SharpCap through the command line file name, which is good. It just fails to run, as if it were executed too early...

Is SharpCap 4.1 already available?

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

Re: No module named Base

#4

Post by admin »

Hi,

SharpCap 4.1 is in release candidate stage at the moment - you can download the latest candidate here : https://www.sharpcap.co.uk/sharpcap/sha ... p-4-1-beta

If you stay with 4.0, try putting the script into the 'Startup Scripts' section of the settings - those are handled better than the /runscript option in SharpCap 4.0

cheers,

Robin
cveillet
Posts: 8
Joined: Tue Jul 25, 2023 11:50 pm

Re: No module named Base

#5

Post by cveillet »

Thanks!
I downloaded the 4.1 beta and I am working with it.
I will come with questions if any...

Cheers,
Christian
cveillet
Posts: 8
Joined: Tue Jul 25, 2023 11:50 pm

Re: No module named Base

#6

Post by cveillet »

The startup scripts option works very well! Thanks...

So far so good... with probably more questions as I progress toward using SharpCap to automate a seeing monitor / turbulence profiler.

Cheers,
Christian
Post Reply