Jump to content

Number stamp tool with python - how?


Recommended Posts

Hi,

Some years ago I wrote a few tools in Vectorscript based on a number stamp. The idea is simple enough: enter a starting number in a dialog, start clicking, the number increments and is "printed" in the drawing on each mouse click. In the actual implementation there is other stuff going on too, but it's just this part I need help with at the moment.

 

The Vectorscript tools work fine, but now I would like to re-write them in Python, but I can't get it working at all! This is because I am probably too stupid to understand what I need to do, but also it is because of the way GetPt() seems to works in Python. Also I don't get how to use KeyDown() in Python. I am open to any suggestion on how to do this in python in any way it works:

  • Enter a starting number in a dialog
  • Start clicking to add numbers (as text) that increment with each mouse click.

It seems like this should be simple enough, but I have been trying to get it to work for a while and i can't! Any help would be much appreciated.

 

Here, below, is a simplified version of my Vectorscript that works fine, and below that one example of how I have tried (and failed miserably) to translate it to Python:

 

{
V4
Simple Number Stamp Tool
By: Benedick Miller
Date: 2014-10-06
}

Procedure SimpleNumberStamp;

	VAR 
		n,i,keyhit:INTEGER;
		pt:POINT;
		t:STRING;				

	BEGIN
		
		n:=IntDialog('Enter the starting number','1');
		IF NOT DidCancel THEN
		keyhit:=27;
		i:=1;
		DSelectAll;
					
		while not keydown(keyhit) do
		
		begin
			t:=num2Str(0,n);	
			getpt(pt.x,pt.y);
			TextOrigin(pt.x,pt.y);
			CreateText(t);				
			n:=n+i;
			redrawall;
		end;
		
	END;

Run(SimpleNumberStamp);

And the Python translation:

# Print Incremental Numbers on each mouse click until [Esc]
# NOT WORKING!!!

import vs

def label(pt):
	vs.TextOrigin(pt[0],pt[1])
	vs.CreateText(str(n))
	vs.ReDraw()
	
def kdwn():
	k=vs.KeyDown()
	return k[1]

keyhit = 27
i = 1
n = 1

vs.DSelectAll()

n = vs.IntDialog('Enter the starting number', n ) 
if not vs.DidCancel():
	while not kdwn() == keyhit:
		vs.GetPt(label)
		n = n + i

 

Edited by Benedick_Miller
cleaning up typos, moved vs.KeyDown() to a callback
Link to comment
  • 2 weeks later...

Hello Benedick

 

I tryed a few possible solutions but get no results.

 

The main problem is that "in Python this function will NOT block execution. It will execute a callback function with the resulted point"

http://developer.vectorworks.net/index.php/VS:GetPt

 

So I tryed to get around with a second while loop like:

 

mdwn = False

mdwn, na = vs.MouseDown()
        n = n + i
        if mdwn == True:
            continue

 

But it  iterates over and over.

 

So maybe in a future version vs.GetPt() or vs.MouseDown() is like a dialog userinput.

 

Silas

Link to comment
  • 2 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...