Jump to content
Developer Wiki and Function Reference Links ×

Python. From the very beginning


michaelk

Recommended Posts

Is there something I need to install before running a Python script?

I'm unable to get any Python script to run, even "Hello, World"

I've tried translating some existing one line scripts with no success.

For example, this is a simple one-liner I often use from VS:

SetPref(44,FALSE);

What would that look like in Python?

Thanks!

mk

Link to comment

Interesting....

Can someone check this?

1. In a VW script editor window, select Python as the language and type in

vs.AlrtDialog('Hello')

2. Run the script. Works Great.

3. Edit the script. Add a space in the wrong place:

vs.Alrt Dialog('Hello')

4. Run the script. Get the error message, click "View Error Output..."

The Script Errors dialog box says:

File "", line 1

vs.Alrt Dialog('Hello')

^

SyntaxError: invalid syntax

5. Click on Edit Script...

Remove the space. Click OK.

6. Run the script again.

I get the same error. If I edit the script by right clicking in the RB and choosing Edit... the edit "sticks". If I choose edit Edit Script... from the Script Errors dialog the edit doesn't "stick".

mk

Link to comment

Now that I (maybe) understand why I was unable to edit a script to make it run...

vs.SetPref(44, False) works as a python script.

At first I was trying to use Message instead of AlrtDialog

vs.Message('Hello')

returns the error:

Traceback (most recent call last):

File"", line 1, in

AttributeError: 'module' object has no attribute 'Message'

Any ideas?

thanks

MK

Link to comment

Hello Michael

Python works for me(win xp sp3 and 8), i download PythonSample_Menu2.

I test it(got errors), when i looked at code:

1. i put ui* dir to site-packages dir, because natively there is not such name of class in VW pyAPI

2. modify main(.py) fuction - this, adding execute() to end

* - dir from sample - PythonSample_Menu2\ui\

Edited by Ilay
Link to comment
  • Vectorworks, Inc Employee

Hi Ilay, you should not copy anything to 'site-packages' from the sample. Unzip the sample in your user's plug-ins folder and that should be all.

when a vsm, vsm, or vst runs, VW adds that folder to the python search path. So, when the scripts does 'import import ui.dlgHandler' the first thing python would do is to look for a folder 'ui' next to the vsm.

Link to comment

Hello Vladislav

Thanks a'lot

Anyway can we use additional math/graphical libs as Numpy an etc.?

honestly i don't like such scheme*:

when a vsm, vsm, or vst runs, VW adds that folder to the python search path. So, when the scripts does 'import import ui.dlgHandler' the first thing python would do is to look for a folder 'ui' next to the vsm.

Currently pyAPI has dependence from vwvs

* - hmm, that why i made several test project, and they did not work properly.

Link to comment
  • Vectorworks, Inc Employee

Anyway can we use additional math/graphical libs as Numpy an etc.?

Yes, you should be able to. Those you should install in the side packages.

Edited by Vladislav Stanev
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...