Jump to content
Bertf

vs.GetPt()

Recommended Posts

Hi,

I'm having troubles to get vs.GetPt() working.

What I have is a plugin written in Python that places a textbox with text from the plugin parameters on the mouse last location. -> This works (code below)

Although vs.GetMouse isn't so precisely because when moving the mouse fast after clicking, I receive another location. So I want to use the Getpt() function.

Is there any way to get vs.GetPt() working? Or am I doing something wrong?

p = vs.GetMouse()
CabinetNr = getattr(vs, 'PKastNr')
Material = getattr(vs, 'PMateriaal')
Text = 'K'+ CabinetNr + chr(13) + Material
Length = len(Text)
PosEnter = Text.index(chr(13))

#p = vs.GetPt() --> NOT WORKING HERE

vs.TextOrigin(p)
vs.CreateText(Text)
h = vs.LNewObj()

vs.SetTextFont(h, 0, Length, vs.GetFontID('Arial'))
vs.SetTextSize(h, 0, PosEnter, 12)
vs.SetTextSize(h, PosEnter, Length-PosEnter, 7)

Thank you,

Bert

Edited by Bertf

Share this post


Link to post

Hi Bert,

What kind of plug-in are you creating? This looks like it would be a menu or tool. You may want to look at coding a plug-in object, where you wouldn't need to code the user interaction (PIOs automatically create a tool for inserting them from the tool palettes).

The cursor UI functions in Python need some special handling. In Python, you need to provide a callback function that tells VW what to do with the user clicks. Take a look at the example in the developer wiki. http://developer.vectorworks.net/index.php/VS:GetPt

-Josh

Share this post


Link to post

Hi, JBenghiat.

I've tried your suggestion and it works when I create a command but it doesn't when I create the same code in a tool. Any reason for that?

Thank you (code below)

import vs;

def PickPointCallback(pt):
vs.AlrtDialog( "Point {0}:{1}".format(pt[0],pt[1]) )

vs.GetPt( PickPointCallback )

Share this post


Link to post
Hi, JBenghiat.

I've tried your suggestion and it works when I create a command but it doesn't when I create the same code in a tool. Any reason for that?

Thank you (code below)

import vs;

def PickPointCallback(pt):
vs.AlrtDialog( "Point {0}:{1}".format(pt[0],pt[1]) )

vs.GetPt( PickPointCallback )

Not an answer, but you can use lambda's and the % string format to shorten your code:

vs.GetPt(lambda pt: vs.AlrtDialog('Point %s:%s' % pt))

Share this post


Link to post

For a tool I think you can try

x1,y1 = vs.vstGetCurrPt2D()

or - not tried in code yet

outX, outY, outZ = vs.vstGetCurrPt3D(result)

As an aside I had a Vectorscript tool with

Getpt(x1,y1)

Getptl(x1,y1,x2,y2) {rubberband line}

and couldn't get the Python version of Getptl to work.

Share this post


Link to post

Thank you BillW!

x1,y1 = vs.vstGetCurrPt2D() -> This works!

Share this post


Link to post

I spent a lot of time trying to get vs.GetPt() to work. I understand the callback function will extract the 2d point e.g

def Callback(pt):
 vs.Locus(pt)
 vs.Message(pt[0],' ',pt[1])
vs.ReDraw()
vs.GetPt(Callback)

However I have not found a way to use pt outside the callback function.

I can draw the locus using pt inside the callback function but not outside.

I really want to create the locus using pt after vs.GetPt(Callback).

Any suggestions ?

Share this post


Link to post

Yea I don't get it either.

The only way to manipulate that 'pt' value is to do it within the callback function.

Well in my testings anyway.

HTH

Share this post


Link to post

Thanks Dieter for the suggestion.

pt is still trapped in the callback function.

user_point = None creates the locus at 0,0 even before you have an oppportunity to select your user point.

Even if you make user_point a global variable within the callback function which should theoretically change user_point = None it still does not work.

Share this post


Link to post
17 hours ago, ahedley said:

Thanks Dieter for the suggestion.

pt is still trapped in the callback function.

user_point = None creates the locus at 0,0 even before you have an oppportunity to select your user point.

Even if you make user_point a global variable within the callback function which should theoretically change user_point = None it still does not work.

I see now, it's stated in the docs that script execution will not be blocked (like most other functions do): http://developer.vectorworks.net/index.php/VS:GetPt

That means that you have to make sure that you first call that function, and that the callback is actually your main function to execute with everything in it.

Share this post


Link to post

Note too that something like this will crash Vectorworks 2016/Mac for me:

import vs
def main():
	vs.GetPt(lambda pt: vs.Message(str(pt)))
    
main()

and this will work OK:

import vs

vs.GetPt(lambda pt: vs.Message(str(pt)))

As far as I can tell this is roughly what the line "This cannot be used if there is a function anywhere in the calling chain" from the docs means.

  • Like 1

Share this post


Link to post

Ryan,

 

import vs vs.GetPt(lambda pt: vs.Message(str(pt))).

 

Crashes vectorworks 2017 windows.

 

Adrian

Share this post


Link to post

Huh, yep. Crashes for me on Mac/2016 and 2017 too. Sorry. (That's what I get for typing in code off the top of my head).

 

I thought it might have been the call to `vs.Message`, maybe on the hypothesis that dialogs tend to be callback-driven too and the message window is kinda-sorta a dialog, but no. This crashes consistently too:

import vs

def cb(pt):
    vs.Locus(pt)

vs.GetPt(cb)

 

Share this post


Link to post

From what I understand GetPt( ) is used in vectorscript when you are trying to create a tool plugin object which may require multiple user points.

 

GetPt( ) and GetPtL( ) are procedures that are used in conjunction.

 

I have noticed in vectorscript it is relatively easy to use these procedures. However in pythonscript it is very challenging, for instance, vs.GetPt( ) using a callback function will work only once. Trying to get multiple vs.GetPt( ) calls thus far for me has proved futile. I have tried without success to use vs.GetPtL( ) which generally uses as its first point the point you select via. vs.GetPt.

 

Has anybody had success creating tool plugin objects requiring user interaction using these procedures or is there another recommended way of creating tools?

 

Most of my experimentation has been developing plugin objects, I want to broaden to tool objects.

Share this post


Link to post
11 hours ago, ahedley said:

Most of my experimentation has been developing plugin objects, I want to broaden to tool objects.

 

Tools aren't objects. Tools are used to generate objects. For example, the rectangle tool will let you create a rectangle in different ways. The rectangle object is the result. The creation of it is what the tool does, and those two have no connection at all. An object should not know how it is created.

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

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×