Jump to content
Sign in to follow this  

Custom Worksheet Function with *Args

Recommended Posts

I would like to create a custom worksheet function to return a value from a range of worksheet cells - Like vlookup() in MS Excel. For now though I will settle for returning the th value in [*args]list

To my knowledge the closest I can get to that is the following

=RUNSCRIPT(13, 'lookup.py', 2, 1, 2, 3, 4, 5)



> 13 - Is the location of 'lookup.py' in this case


> 'lookup.py' is the name of my script

> 2, 1, 2, 3, 4, 5 are the arguments i'm trying to pass in

lookup.py: (current)


def lookup(i, *args):

>>>return args[i-1]


Do I need to call lookup(i,*args) here as well? as the function

has only been defined and not run above


Or should I change it more to something like this:


def lookup(f_i, *f_args):

>>>for a in f_args:


>>>return args[i-1]

i = 0

args = []

lookup(i, *args)

Please Help. How do I make this work?

Edited by CarlJdP

Share this post

Link to post

Do you want get the output in your OS Terminal or somewhere out of Vectorworks?

That is to high for me, but I am very interested on this possibilities too.

As I suppose, that the args method is not loaded in an embedded python. So maybe we have to somehow initialize this first.

But as I told, this could be a very dilettantish comment.

Edited by DomC

Share this post

Link to post

OK, forget my comment about your args. I thought you want to have access to the sys.argv command line arguments.

Share this post

Link to post


I think, we have to specify the args in the worksheet scripts. Like this



I tried to get all args with a while loop


while vs.WSScript_GetPrmReal(i) !=None: #Endless loop, attension!


Don't try this. You will never be able to open your document again. Because Worksheets script automatically actualize at open document (which seems to be a nice feature ...) but If you have an endless loop in your script you will have to wait endless :-)

Or maybe it's because the vs.WSScript_Get******* ist not very liberal, if you get wrong value type. A String instead of a float as example?

Edited by DomC

Share this post

Link to post

Hi Carl

I made an example. Attached to this post. Hope, It can help you finish your project.

Code in the Worksheet:

=RUNSCRIPT('Script-1', A2, B2, C2, D2, E2)

Code of the Script

while arg_len >0:
arg = vs.WSScript_GetPrmStr(i)
arg_len = len(arg)


Share this post

Link to post

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.

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.

Sign in to follow this  


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.

  • Create New...