Need scripting help
Need scripting help
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?
Using the sample script provided returns a "4 arguments required" There are 4 arguments listed.
What am I doing wrong?
- admin
- Site Admin
- Posts: 13339
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Need scripting help
Can you share your code so far please?
cheers,
Robin
cheers,
Robin
Re: Need scripting help
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)
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)
- admin
- Site Admin
- Posts: 13339
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Need scripting help
Hi Frank,
sorry, but it's a rogue letter 't' at the beginning of this line of script
take out the t at the beginning (typo on my part) and you should be fine.
cheers,
Robin
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
cheers,
Robin
Re: Need scripting help
Hi Robin,
Yes I did notice the t and removed it in my previous tries but that didn't help.
Frank
Yes I did notice the t and removed it in my previous tries but that didn't help.
Frank
- admin
- Site Admin
- Posts: 13339
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Need scripting help
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
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
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 above code works correctly for me, so give it a try from scratch.
cheers,
Robin
Re: Need scripting help
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.
#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
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.
#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
- admin
- Site Admin
- Posts: 13339
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Need scripting help
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.
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
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
Re: Need scripting help
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)
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)
Re: Need scripting help
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.
Hope that's the final hurdle
And thanks - needed that button.