Need scripting help

Discussions on extending SharpCap using the built in Python scripting functionality
putty tat
Posts: 8
Joined: Mon May 08, 2017 2:34 pm

Need scripting help

Post by putty tat » Wed May 24, 2017 7:30 pm

Trying to learn Iron Python but running into problems with the procedure creating a custom button on the lower frame.
Using the sample script provided returns a "4 arguments required" There are 4 arguments listed.
What am I doing wrong? :?

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

Re: Need scripting help

Post by admin » Thu May 25, 2017 6:25 am

Can you share your code so far please?

cheers,

Robin

putty tat
Posts: 8
Joined: Mon May 08, 2017 2:34 pm

Re: Need scripting help

Post by putty tat » Thu May 25, 2017 7:32 pm

Hello Robin
First, may my wife from Ireland and myself offer to you and the people of England our heartfelt sorrow and sympathies for sad attack by scumbags in Manchester.

Here's what the I used copied from the help() screen:

#Do the same a slightly simpler way
tSharpCap.SelectedCamera.GetControl(CommonPropertyIDs.Exposure).Value = 0.1

#Add a custom button to the toolbar that will open the first camera when it is clicked
def selectFirstCamera():
SharpCap.SelectedCamera=SharpCap.Cameras[0]
SharpCap.AddCustomButton("Test", None, "Select the first camera", selectFirstCamera)


Responed also
Traceback (most recent call last):
File "<string>", line 2, in <module>
NameError: name 'tSharpCap' is not defined

Could it be the interpreter is corrupted? About 2 years I had a project with a Raspberry that used Python.
I had read that Python 3 had serious problems at that time.

Best regards, Frank (putty tat)

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

Re: Need scripting help

Post by admin » Thu May 25, 2017 9:07 pm

Hi Frank,

sorry, but it's a rogue letter 't' at the beginning of this line of script

Code: Select all

tSharpCap.SelectedCamera.GetControl(CommonPropertyIDs.Exposure).Value = 0.1
take out the t at the beginning (typo on my part) and you should be fine.

cheers,

Robin

putty tat
Posts: 8
Joined: Mon May 08, 2017 2:34 pm

Re: Need scripting help

Post by putty tat » Thu May 25, 2017 10:09 pm

Hi Robin,

Yes I did notice the t and removed it in my previous tries but that didn't help.

Frank

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

Re: Need scripting help

Post by admin » Fri May 26, 2017 6:57 am

Ok, next suggestion - the python language considers whitespace at the beginning of lines important (it denotes block nesting in the way that curly brackets - { } - do in other languages.

The code should look just like this as you enter it

Code: Select all

>>> SharpCap.SelectedCamera.GetControl(CommonPropertyIDs.Exposure).Value = 0.1
>>> def selectFirstCamera():
... 	SharpCap.SelectedCamera=SharpCap.Cameras[0]
... 
>>> SharpCap.AddCustomButton("Test", None, "Select the first camera", selectFirstCamera)
The first line after the def that starts ... instead of >>> - you have to put a tab at the beginning of that line.
The above code works correctly for me, so give it a try from scratch.

cheers,

Robin

putty tat
Posts: 8
Joined: Mon May 08, 2017 2:34 pm

Re: Need scripting help

Post by putty tat » Fri May 26, 2017 3:33 pm

Hi Robin,
No luck. Still getting either syntax error or unexpected tokens. Either I'm still doing something wrong or there's something corrupted in the interpreter or maybe even the compiler. Below is what I'm doing. :cry:


#List the cameras available
print SharpCap.Cameras

#Open the first camera
SharpCap.SelectedCamera = SharpCap.Cameras[0]

#List the controls on the open camera
print SharpCap.SelectedCamera.Controls

#Print the value of the first control
print SharpCap.SelectedCamera.Controls[0].Value

#Find the exposure control and set its value to 0.1
SharpCap.SelectedCamera.Controls.Find(lambda x:x.Id == CommonPropertyIDs.Exposure).Value = 0.5

Returns error:
>>>
File "", line 20
... def selectFirstCamera():

^
SyntaxError: unexpected token '.'
>>>




# SharpCap.SelectedCamera.GetControl(CommonPropertyIDs.Exposure).Value = 0.5
... def selectFirstCamera():
... SharpCap.SelectedCamera=SharpCap.Cameras[0]
...
>>> SharpCap.AddCustomButton("Test", None, "Select the first camera", selectFirstCamera)



Best regards,

Frank

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

Re: Need scripting help

Post by admin » Fri May 26, 2017 4:03 pm

Ah, I think you are typing the '.' and '>' characters at the beginning of the lines - you don't want to type those as they are the prompts that the Python interpreter puts up to show you where and what to type.
Capture.PNG
Capture.PNG (13.32 KiB) Viewed 543 times
I have highlighted in yellow the text that I actually typed in the screenshot above. Note that there is a tab typed at the beginning of the SharpCap.SelectedCamera = SharpCap.Cameras[0] line. Also that I needed to press <Enter> twice after that line - once to get the second '...' prompt and a second time to get back to the >>> prompt. If I'd have wanted to put more lines of code in my function definition, I'd have continued to press tab at the beginning of each line where prompted with ...

hope this helps,

Robin

putty tat
Posts: 8
Joined: Mon May 08, 2017 2:34 pm

Re: Need scripting help

Post by putty tat » Sat May 27, 2017 7:01 pm

Hi Robin,

Sorry to be a P.I.T.A. So far it seems to work except for adding a button to the tool bar. When I run the script it does not create
the button. This what I run as the last lines:

#Add a custom button to the toolbar that will open the first camera when it is clicked
def selectFirstCamera():
SharpCap.SelectedCamera=SharpCap.Cameras[0]
SharpCap.AddCustomButton("Test", None, "Select the first camera", selectFirstCamera)

pgn
Posts: 16
Joined: Wed Mar 08, 2017 9:46 am

Re: Need scripting help

Post by pgn » Sun May 28, 2017 6:48 am

Been learning scripting. Just to say I copied the very last 3 lines of script you posted. Indented the second one ran it and it works. At first it didn't seem to then realised I hadn't made the SharpCap window wide enough to see the button tacked onto the end.

Hope that's the final hurdle :)

And thanks - needed that button.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest