Jump to content

HCenter with python?


relume

Recommended Posts

Hello

I may have a stupid question about the correct syntax of the vs.HCenter command in pyhton:

In vectorscript HCenter works the following:

vObjectHandel : handle;

vX = real;

vY = real;

HCenter(vObjectHandel, vX, vY);

In python I am calling the HCenter method in the analog form:

vs.HCenter(vObjectHandle, vX, vY)

Executing the python script I receive for vX und vY the error "NameError : gobal name 'vX' is not defined" for the call of vs.HCenter.

If am writing the following:

vX = 0.0

vY = 0.0

vs.HCenter(vObjectHandle, vX, vY)

The previous error is gone but vX und vY remains always 0.0 and never gets the values from the object referenced by the vObjectHandle passed as the first parameter to vs.HCenter.

Many thanks for any hint,

best regards

Link to comment

Hello

with some best guess tryings I a found that the following python syntax works for vs.HCenter:

vPoint = vs.HCenter(vObjectHandle)

Thereby the returned vPoint is of the pyhton data type tulple of the form (X,Y) and the single values can be accessed by the form of:

vX = vPoint[0]

vY = vPoint[1]

best regards

Link to comment

Python doesn't have a direct analog to input/output parameters, but it does have the ability to return multiple results to a function in the form of tupples. Any time you see VAR as input for a vs function, the python equivalent will be returned as a result to the call.

This is reflects in the API documentation: Http://developer.vectorworks.net/index.php/VS:HCenter

I believe this is also a valid syntax:

uX,uY = vs.HCenter(vObjectHandle)

Some vs functions rely on both having the input value and returning an update to that value. In that case, you would need a python variable both receiving output and as an argument. UprString is an example:

def vs.UprString(str):

return str

Here it's fairly strain forwards, but some of the API can look a little wonky.

HTH,

Josh

  • Like 1
Link to comment
  • 6 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...