Save and read the position of the reticule

Got an idea for something that SharpCap should do? Share it here.
Forum rules
'+1' posts are welcome in this area of the forums to indicate your support for a particular feature suggestion. Suggestions that get the most +1's will be seriously considered for inclusion in future versions of SharpCap.
Post Reply
Pawcio_K
Posts: 3
Joined: Wed Nov 03, 2021 3:07 pm

Save and read the position of the reticule

#1

Post by Pawcio_K »

Hi,
Is it possible to add the option of saving and reading the position of the reticule?
User avatar
admin
Site Admin
Posts: 13173
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Save and read the position of the reticule

#2

Post 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
Pawcio_K
Posts: 3
Joined: Wed Nov 03, 2021 3:07 pm

Re: Save and read the position of the reticule

#3

Post by Pawcio_K »

Thank you for the hint, I'm interested in the Python language.
Pawcio
Pawcio_K
Posts: 3
Joined: Wed Nov 03, 2021 3:07 pm

Re: Save and read the position of the reticule

#4

Post 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)
Last edited by Pawcio_K on Wed Dec 08, 2021 9:54 am, edited 1 time in total.
User avatar
admin
Site Admin
Posts: 13173
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Save and read the position of the reticule

#5

Post by admin »

Hi Pawcio,

good to hear that it worked, and thanks for sharing your script!

Robin
Post Reply