Jump to content

Getting started


Recommended Posts

I've decided to have another go at learning to write scripts, as I'm reaching the limit with some of the things we'd like to achieve. I know very little about coding. Seems to make sense to start with Python and then use the vs.x functions inside of it. So far, I've downloaded PyCharm, opened a project and created a new 'Virtualenv' environment, then set the Interpreter as the python file in the VW 23 folder:

image.thumb.png.d53b5f8b8234841286ec50b31fc1ce0f.png

 

However, in my Project tree, I see no reference to anything to do with Vectorworks. presumably that's because the project code lives in the specified location even though the interpreter is in the VW23 program folder. Is that correct?

 

(I would love to resize these massive images smaller...but the forum image resize still seems to be broken)

image.thumb.png.d3b73fb57383b204111b9131da97db53.png

 

Having imported, the vs.py file, I can see vectorscript functions available to populate in my code. So, to my two questions:

 

At the moment, I've just defined a simple alert dialogue to pop up. If I use the 'Run Script' command in VW and point it at the main.py file, it will execute in VW fine. But obviously now I'll be trying to make more useful things. If I had a script that executed various things in VW, how can I run the script such that I can debug it in PyCharm and see it running in VW as well? Put another way, if the script fails at a certain point when executed in VW, how would I be able to see that problem in PyCharm and sort it?

 

Next, if I remove the 'import vs' line from my code and just run the vs.AlrtDialog line, it still works fine in VW, presumably because the vs functions are already defined in vectorworks and so don't need to be defined again. But what if I had other python libraries/files alongside the vs.py that were called in the code, and I wanted the script to be transportable - i.e. it can be a script in our standard VW template and/or be sent to others in the office that want to use the script. Is there a function that kind of wraps everything up/compiles it in to a single py file that can be sent to other users or just generally be transportable? I'm probably misunderstanding how this works, but that's the best way I can think of to ask the question.

 

Thank you!

Link to comment
On 8/19/2023 at 11:54 PM, spettitt said:

At the moment, I've just defined a simple alert dialogue to pop up. If I use the 'Run Script' command in VW and point it at the main.py file, it will execute in VW fine. But obviously now I'll be trying to make more useful things. If I had a script that executed various things in VW, how can I run the script such that I can debug it in PyCharm and see it running in VW as well? Put another way, if the script fails at a certain point when executed in VW, how would I be able to see that problem in PyCharm and sort it?

 

That could be done by the remote debugger but according to this topic it is not working reliable.

 

https://developer.vectorworks.net/index.php/Python_Debugging

 

 

When the script fails you should see the error message poping up in VW that tells you in which function and which line the problem occured.

Make sure the VW option run scripts in debug mode is enabled.

Edited by PatW
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...