Jump to content

Learning Vectorscript/Python


_James

Recommended Posts

I would like to get into writing some scripts for VW either via Vectorscript or Python. I have pretty much zero experience save for a few modules of "Automate the Boring Stuff with Python" on udemy or similar platform. I was wondering if anyone had some tips/recommendations on how they got started and what they found helpful/not helpful.

 

- I've watched this Vectorworks University course about Vectorscript which is a great primer to show you what is possible, but now I'd like to jump in and actually make something.

- I will try to take a look at the Vectorscript Language Guide here in the next few days

- I've been having a look through https://developer.vectorworks.net/index.php/Main_Page and the Vectorworks help pages.

 

I'm leaning more towards Python for it's use outside of Vectorworks, but I do recognise @michaelk's point about Vectorscript having some advantages (like with the compile button, exporting objects as script to get the creation data etc.), so i'm interested to hear people's opinion!

 

Thanks in advance!

Link to comment

If I was starting from scratch today, I'd use Python.

 

In the back of my mind I keep meaning to write my next script in python.  But I'm always in a hurry and I need it right away so I write in VS.  

 

But eventually I intend to get good enough with python that I can use it when I'm in a hurry. 🙂 

 

If you already know a little Python, keep going.  The VS specific functions are pretty much the same in both languages.  

 

 

  • Like 1
Link to comment

I'm not sure I agree Michael. It depends on what you are trying to do.

 

If you need to access a lot of data from outside of VW, then you need Python.

If you want to develop skills that are directly applicable outside of VW then you need Python.

 

If you need to be interactive with VW, then you need to use Vectorscript. Apparently VW lacks the ability to pause execution of a python script while it waits for user interaction. Take a look at this thread that talks about wrapping a Python script inside a Vectorscript and using VS for the interactive part. This means you have to learn at least a little of both.  

 

 

Vectorscript was developed originally as a form of Pascal. In the 1980s, Pascal was one of the primary "learning" languages that were developed to teach people how to program, so it is relatively clean, even if it is strict in a number of ways (Begin/End statements, required semicolons at the end of every (almost) line, etc.)

 

My two biggest problems with Python are:

1. It is case sensitive.  rNow, RNow, Rnow, and rnow are all different variables. My typing is not good enough to be that consistent.

2. IT IS WHITE SPACE SENSITIVE.  Python uses the indentation of a piece of code to determine the looping.  If you use an IF statement and put everything inside that at a 2 space indent, but then accidentally change one line to a single space or three spaces it changes the way the code operates. ME HATES THIS.

 

But for someone with no experience, especially someone with a long career ahead of them, Python is probably the better language to learn as it will likely be used for a long time.

  • Like 2
Link to comment

I have preferred to stick with Vectorscript myself, but also understand the larger application of Python being useful.  I learned Python in 2010, a good number of years before it was integrated into Vectorworks, but didn't have much use for it at the time, so fell out of the habit.  In the meantime, I became very familiar with Vectorscript and have been dragging my feet a bit in picking Python back up.  In some ways, the Python integration is a bit "kludgy", being that you are still more or less locked into the Vectorscript functions when interacting with Vectorworks, but Python handles and organizes data much, much better.  Sorting and searching arrays is MUCH easier in Python, and the Dictionary structure is pretty game-changing.

 

If learning Vectorscript, you can't go wrong with the Vectorscript Language Guide that you linked above, it's how I was able to teach myself the language 12 years ago.  If learning Python, there are a huge number of resources to look into, but it might take a bit of experimentation to apply that knowledge more specifically to Vectorworks.  Either way, I cannot recommend enough keeping a copy of the Function Reference open anytime you're working on a script.  In addition to the online one, an offline (and easier to navigate) one is stored in the VWHelp folder in the Vectorworks application directory.  There, you will find a general description of each function and an example of the method constructor, and, if you're really lucky, a relevant example of how to use it.

 

About a year ago, I also wrote up a quick "crash course" for Vectorscript for another user who was interested in getting started.  It distills a lot of what you find in the Language Guide down to a slightly more straight forward how-to.  Keep in mind that I wrote most of it in the wee hours of the morning, so it may get a bit loopy, but it may prove helpful.

 

Do also be warned, this is how it begins.  Once you start writing your own menu commands and plug-in objects, you might have a hard time getting yourself to stop...

  • Like 3
Link to comment
2 minutes ago, Jesse Cogswell said:

In addition to the online one, an offline (and easier to navigate) one is stored in the VWHelp folder in the Vectorworks application directory.  There, you will find a general description of each function and an example of the method constructor, and, if you're really lucky, a relevant example of how to use it.

I completely agree Jesse.  I actually keep a separate browser window with  panes for the local Function Reference, the local Vectorscript Appendix (part of the function reference, and the online (Developer site) Function Reference.

 

The online version is actually user editable so many of the functions there have had additional descriptions and code samples posted that can greatly help in figuring out how something is supposed to work.

 

All are necessary.

  • Like 3
Link to comment

Totally agree with all @Pat Stanford and @Jesse Cogswellabout the local version of the function reference.

 

Nice "quick" writeup Jesse!

 

I also recommend getting BBEdit:  https://www.barebones.com.  

 

If you're using VS BBEdit will autocomplete VS functions and color code the script.  It's much easier to keep scripts neat and organized.  Here's a post to explain how to set it up:

 

 

  • Like 2
Link to comment
11 hours ago, Pat Stanford said:

Vectorscript was developed originally as a form of Pascal. In the 1980s, Pascal was one of the primary "learning" languages that were developed to teach people how to program, so it is relatively clean, even if it is strict in a number of ways (Begin/End statements, required semicolons at the end of every (almost) line, etc.)

One of the biggest advantages of writing in Python is not having to care about or predefine data types.  If you pass a handle to a variable - Poof, it's a handle.

  • Like 2
Link to comment

Thanks everyone for the messages and advice. @michaelk was right when he said in his webinar that this is one of the nicest places on the internet! I thought it would be a clear win for Python but Vectorscript seems to still have advantages.

 

I was partly inspired by @MarcelP102 and his thread "Babysteps into Vectorscripting". I'm a big believer in learning by doing so I need to get my teeth into a project!

  • Like 1
Link to comment
  • 2 weeks later...

As has been said above a combination of both is always good, however I would personally be aiming to start with Python, and frankly I think you'll end up doing the majority within that language. It's a hugely transferrable skill, it's easy to learn and the amount of resources available on the web for python are huge (stackoverflow will be your go to saver after this place!)

 

I program 99% of my plugins in Python, and i've not come up against many scenarios where Python has been the limiting factor. That's not to say they aren't there, as has been outlined above they are there. But 90% of what you're going to want to do can be achieved in Python.

Link to comment

I think the biggest advantage of using vectorscript is the built in debugger. Although is possible, according to the python pages, to uas a third party python program to debug, the instructions are vague and I have never been able to successfully get the remote debugger working. If Nemetschek would add a native interface with a debugger, python would be the better choice because it can interact with data and systems outside of vectorworks.

Link to comment

No debugger??  I didn't know that.  Beginning programmer?   No debugger?? 

If you learned to program prior to coming to VW macro programming maybe python, after all it is what you learned, but without having learned Python first,  hands down use vectorscript.  Period.  I'm sure there will be continued discussion on this, but there shouldn't be.  Prior to coming to MiniCAD and vectorscript, I had learned PL-1, Forrtan, Pascal, and Forth.  Yes, Forth, the fastest, most obscure, stack programming language.  .  I was using Forth on an Apple II for god sakesl  That anyone would want to introduce someone new to programming using a language that is space sensitive, uses white space as a meaningful delimiter, has no variable type checking, and has no integrated debugger  is madness.  I was on the fence before; not now.  If you know Python, go for it.  String handling, and outside libraries are a big plus; although, I don' know how outside libraries are handled by encryption, or how encryption might be hobbled by outside libraries.  If you're new to programming use vectorscript.  You will get farther faster.

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