Benedick_Miller Posted February 8, 2019 Share Posted February 8, 2019 (edited) 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 February 8, 2019 by Benedick_Miller cleaning up typos, moved vs.KeyDown() to a callback Quote Link to comment
Silas Posted February 20, 2019 Share Posted February 20, 2019 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 Quote Link to comment
Benedick_Miller Posted February 20, 2019 Author Share Posted February 20, 2019 Hi Silas, thanks for trying and replying. As you say - "in Python this function will NOT block execution. It will execute a callback function with the resulted point" - I did read that but i was hoping there was some way around that. I'll stick to Vectorscript for now for this tool. Quote Link to comment
LandArchTools Posted September 6, 2021 Share Posted September 6, 2021 Sorry for digging up an old post but has there been any advancement to this? not being able to block execution makes python a non starter, I've been banging against a brick wall to make a simple multi-copy tool. Quote Link to comment
Recommended Posts
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.