Jump to content
giez

vs.vstGetPt2D() not working

Recommended Posts

Hello all,

 

After having learned some basic Python, I'm trying to get started with Python in Vectorworks.

As an exercise I'm trying to create a basic version of the existing 'Move by Points'-Tool:

Get two points (pt1 and pt2) clicked by the user and then move a previously selected object by (x2-x1, y2-y1) but I'm having problems getting the user input.

 

As I understood from previous posts, vs.GetPt() only works with commands but not with tools.

Instead, the function to use would be: vs.vstGetPt2D() http://developer.vectorworks.net/index.php/VS:vstGetPt2D
 

The script of my Tool-Plugin refers to _main.py as follows:

import _main
_main.execute()

_main.py looks like this:

import vs
def execute():
    pt = vs.vstGetPt2D()
    vs.Message(str(pt))

After starting the tool, no matter where I click, I get (1e+100, 1e+100) as a result.

Also I don't quite understand what the required parameters (inPtIndex, result) should be set to?

In the example above I just left them away which of course causes an Error (Invalid number of parameters...) but still prints the Message.

Setting them to something arbitrary like vs.vstGetPt2D(1, True) doesn't result in an Error but still prints the wrong coordinates.

Is the problem related to the parameters or what is it that I'm not getting?

 

Thanks in advance!

 

Daniel

Share this post


Link to post

Vs.GetPt() would be the call to use, or because you need two clicks, GetPtL(). The vst functions work with RunTempTool and TrackObject, and require you to structure your code as an event handler. 

 

Note that all script based tools start execution on the first click. This can be an issue if you are doing selection processing like with TrackObject, but because you want the first click the user makes to set the start of your move offset, having that click start the script shouldn’t be an issue. 

 

Share this post


Link to post

Thanks for your reply.

As already mentioned, I can't get vs.GetPt() to work in a Plugin-Tool.

The following code works perfectly fine as a Script or Plugin-Command but won't work when used in a Tool (i.e. nothing happens, no Message, no Error,...)

import vs
def callback(pt):
	vs.Message(str(pt))	
vs.GetPt(callback)

 

Share this post


Link to post

There seems to be a delay for when the callback runs.  You can write your own handler fairly simply

 

import vs

def GetPt():
	click = False
	while not(click):
		click, pt = vs.MouseDown()
	vs.LineTo(pt)
	
pt = vs.GetMouse()	
vs.MoveTo(pt)
GetPt()

 

Share this post


Link to post

I've been experimenting around with vs.MouseDown(), too.

It kind of works but it's of no practical use since snapping won't work anymore which makes precise drawing / moving impossible.

 

It seems like simply getting a click from the user is not as obvious as I thought it'd be..

I'll probably stick to writing plug-ins as commands then.

 

Thanks for your help!

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×