Page 1 of 1
Save and read the position of the reticule
Posted: Thu Nov 04, 2021 7:53 am
by Pawcio_K
Hi,
Is it possible to add the option of saving and reading the position of the reticule?
Re: Save and read the position of the reticule
Posted: Thu Nov 04, 2021 1:46 pm
by admin
Hi,
it's possible to access (fetch and modify) the reticule position using the built in Python scripting language
Code: Select all
>>> print SharpCap.Reticules.SelectedReticule.FractionalPosition
{X=0.5, Y=0.5}
>>> clr.AddReference("System.Drawing")
>>> from System.Drawing import PointF
>>> SharpCap.Reticules.SelectedReticule.FractionalPosition = PointF(0.1,0.3)
Since you can also add custom toolbar buttons and other UI using the Python language it would be possible to make buttons to save/load reticule position using this approach.
I often recommend using Python scripting to add features when I haven't heard the request before - it's a great way for users to add custom functionality to SharpCap that may be perfect for their particular usage but might not be of interest to many other users. If I hear lots of people asking for the same feature then that feature gets more consideration for addition to core SharpCap.
thanks,
Robin
Re: Save and read the position of the reticule
Posted: Thu Nov 04, 2021 2:45 pm
by Pawcio_K
Thank you for the hint, I'm interested in the Python language.
Pawcio
Re: Save and read the position of the reticule
Posted: Thu Dec 02, 2021 11:47 pm
by Pawcio_K
I came back to the topic. I read a bit and .. it worked!
Sorry about the syntax - this is my first python script.
Code: Select all
import os,sys,re
file_tmp = (os.getenv("TEMP") if os.name=="nt" else "/tmp") + os.path.sep + "tempfilename.tmp"
def write_pos():
PointF = SharpCap.Reticules.SelectedReticule.FractionalPosition
file = open(file_tmp,"w")
sys.stdout = file
print PointF
file.close()
def read_pos():
clr.AddReference("System.Drawing")
f = open(file_tmp,"r")
Point = f.readline()
f.close()
x=float.Parse(re.findall ("{X=(\\d+.\\d+)",Point)[0])
y=float.Parse(re.findall ("Y=(\\d+.\\d+)}",Point)[0])
SharpCap.Reticules.SelectedReticule = SharpCap.Reticules[1]
from System.Drawing import PointF
SharpCap.Reticules.SelectedReticule.FractionalPosition = PointF(x,y)
SharpCap.AddCustomButton("ZAPIS", None, None, write_pos)
SharpCap.AddCustomButton("ODCZYT", None, None, read_pos)
Re: Save and read the position of the reticule
Posted: Fri Dec 03, 2021 1:03 pm
by admin
Hi Pawcio,
good to hear that it worked, and thanks for sharing your script!
Robin