Jump to content
Developer Wiki and Function Reference Links ×

syntax for vs.ForEachObject(callback, c):


michaelk

Recommended Posts

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

Link to comment

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 by DeSignature
Link to comment

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

Link to comment

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

Link to comment

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

Link to comment
  • 3 weeks later...
  • 3 weeks later...

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')

Link to comment

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...