relume Posted December 22, 2014 Share Posted December 22, 2014 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 Quote Link to comment
relume Posted December 22, 2014 Author Share Posted December 22, 2014 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 Quote Link to comment
JBenghiat Posted December 22, 2014 Share Posted December 22, 2014 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 1 Quote Link to comment
matteoluigi Posted March 17, 2021 Share Posted March 17, 2021 Works fine, here a short testscript, which returns the center of the active object Quote H0 = vs.FSActLayer() X,Y = vs.HCenter(H0) vs.AlrtDialog(vs.Concat('X: ',X,'; Y: ',Y)) 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.