michaelk Posted December 2, 2013 Share Posted December 2, 2013 Can someone please put me out of my misery? What is the exact syntax for calling a procedure in Python? For example, how would this VS script be written in Python: PROCEDURE MoveOver; PROCEDURE Moveit(h :HANDLE); BEGIN HMove(h,10,10); END; BEGIN ForEachObject(Moveit, T=RECT); END; RUN(MoveOver); Thanks! mk Quote Link to comment
DeSignature Posted December 2, 2013 Share Posted December 2, 2013 (edited) Still struggling with this Python-module, but this code seems to work: vs. SelectAll () vs. ForEachObject (vs. HMove (vs. LSActLayer (), 100, 100), vs. ObjectType (3)) vs. DSelectAll () or vs. SelectAll () Obj_H = vs. LSActLayer () Crit = vs. ObjectType (3) vs. ForEachObject (vs. HMove (Obj_H, 100, 100), Crit) vs. DSelectAll () Edit: Seems to work for just one rectangle at the time ... Edited December 2, 2013 by DeSignature Quote Link to comment
michaelk Posted December 2, 2013 Author Share Posted December 2, 2013 Glad I'm not the only one struggling with it! Thanks for taking a swing at this. I see what you're trying to do. But it doesn't have the same effect as a user defined procedure. It only moves the top rectangle on the active layer. Not every rectangle on every layer. The online Python guide doesn't list a ForEachObject(callback,c): function. But it's in the VS reference guide. Python: def vs.ForEachObject(callback, c): return None Description: Calls a user defined procedure to operate on each object matching the specified search criteria. The procedure subroutine specified by the callback parameter must have one parameter of type HANDLE, which is passed the handle to an object by the ForEachObject call. Parameters: callback Name of action procedure to be applied to matching objects c Search criteria for locating objects. My question is how to write the "action procedure to be applied to matching objects". Really wish there was a VW-specific Python language guide and more examples of scripts. mk Quote Link to comment
JBenghiat Posted December 2, 2013 Share Posted December 2, 2013 I'm not at my desk, but some tidbits: In the Python examples, download the Interactive Calls demo. There is an FEO example there. FEO works identically to VectorScript, except that the procedure definition should follow a Python format, and criterium is not a native data type, so you need to enclose it in quotes like a string. Think of criteria in Python as a string that has significance when parsed by VW's criteria handler. -Josh Quote Link to comment
michaelk Posted December 2, 2013 Author Share Posted December 2, 2013 Josh Is there another page of examples other than http://developer.vectorworks.net/index.php/Python ? I've downloaded all of those and looked for vs.ForEachObject with no luck. Can you point me to the Interactive Calls demo? Thanks! mk Quote Link to comment
JBenghiat Posted December 3, 2013 Share Posted December 3, 2013 Michael, You're right, I see the example file I referenced didn't make it to the developer site. I'll have to ask why. Here is the example for FEO: import vs; def SelectThem(h): vs.AlrtDialog( "we're in", h ); vs.AlrtDialog( 'should show three consecutive dialogs' ) vs.ForEachObject( SelectThem, '((T=WALL))' ); or to answer your original question import vs def Moveit(h): vs.HMove(h,10,10) vs.ForEachObject(Moveit, "T=RECT") -Josh Quote Link to comment
michaelk Posted December 3, 2013 Author Share Posted December 3, 2013 Thanks. That's exactly what I was looking for! What is the 'import vs' line for? The script runs without it. mk PS. Please feel free to send along any other python examples that didn't make it to the developer site! Quote Link to comment
DeSignature Posted December 3, 2013 Share Posted December 3, 2013 Thanks. PS. Please feel free to send along any other python examples that didn't make it to the developer site! I second these. By the way: where did you define the handle in this code? Quote Link to comment
michaelk Posted December 3, 2013 Author Share Posted December 3, 2013 The way I understand it, you don't have to define the variable type in Python. ForEachObject passes a handle variable, so therefore h is a handle type variable. hth mk Quote Link to comment
Vectorworks, Inc Employee Vlado Posted December 20, 2013 Vectorworks, Inc Employee Share Posted December 20, 2013 (edited) Check the developer.vectorworks again: http://developer.vectorworks.net/index.php/VS:ForEachObject I've put an example of python using this function. Edited December 20, 2013 by Vladislav Stanev Quote Link to comment
Vectorworks, Inc Employee Vlado Posted December 20, 2013 Vectorworks, Inc Employee Share Posted December 20, 2013 Also, it is even more interesting (different than VectorScript) is the vs.GetPt call. See the sample at: http://developer.vectorworks.net/index.php/VS:GetPt Quote Link to comment
JBenghiat Posted January 6, 2014 Share Posted January 6, 2014 One thing to remember is that VS came first, so many of the existing calls are more logical in VS than Python. Here are a couple ways to make ForEachObject more Pyhton-like. def ListEachObject( C ): outList = [] def AddToList( h ): outList.append( h ) vs.ForEachObject( AddToList, C ) return outList for h in ListEachObject( "T = RECT" ): vs.HMove(h, 0, 1) vs.ForEachObject(lambda h: vs.HMove(h, 0, -1), 'T = RECT') 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.