Jump to content

Using an External Text Editor

Recommended Posts

As I've read, it's possible to use an external text editor instead of the built-in one. I'd like to be able to keep a .py file open, save it, and have it automatically update in Vectorworks, and I'd think there would be a way to select a file to be referenced, but I can't figure out how to do this; I also haven't found anything useful on the developer page. When I navigate to the plugins manager there are .vso and .vst files with the names of plugins I've created, but if I try to open them in Sublime it's just a string of integers. How can I integrate a text editor into my workflow?

Link to comment

It works the other way.


You create a very small script in the Script or Plug-in editor with basically a single like to {$INCLUDE Name of your text file here}.


Then you can edit the text file and if you have VW Preferences:Session tab:Run Scripts in Developer Mode checked, the script will be recompiled every time it is run and reimport any changes to the file referenced as an Include.


Check out Page 67 of The Vectorscript Reference. https://developer.vectorworks.net/images/7/72/VectorScriptGuide.pdf


There have been numerous threads about this in the past. Seach for $INCLUDE and you should get what you need. If not ask again.

Link to comment

I don't know VS, but it looks similar to a Python import function. Using that method, at least as I understand it, things are sort of working. I've set the environment path in "script options" to a folder containing my script, which includes a main() function. In the Vectorworks script editor all I have is this:

import Blocks

But there's a bit of code in the script that's broken now. Below is a simplification of what's going on. This works fine when in the Vectorworks editor but breaks in Sublime. Any ideas?

def __main():
  valid, objN, objH, recH, nilx = vs.GetCustomObjectInfo()
	record = vs.GetName(recH)
    	vs.Message(str(objH)) #this prints a valid Handle 
	name = vs.GetName(objH) #but this tells me the handle variable is NIL


Edited by sully8391
Link to comment

This could be from pasting into the post, but your indents are off. Python depends on indents for code structure, so everything under def needs to have the same leading white space. Also make sure you have a non-indented blank line at the end of the file. 

I don’t have it off the top of my head, but there is a preference variable you can set to prevent python from caching, which can be an issue if you change the text file and don’t invoke the plug-in editor. You should be able to find this in the forums. 

If your external files has dependencies that you are also editing, you need to refresh those modules with python’s imp module. Again, I believe there is info for this on the forum. 

Link to comment

@JBenghiat The indents are from pasting. I eventually just had to make a new plugin and copy all the code and have ditched the external editor until I get more comfortable with Python in Vectorworks. I'm still getting strange errors, but this might have something to do with my windows machine. For example, I have one function that relies on converting a string to an integer. On my Windows machine I get "Error trying to convert string to number" (I have to use vs.Str2Num() first, because Vectorworks doesn't seem to like int()), but then it executes all the lines of code that require that conversion to happen. When I try this on my Mac, there are no errors. If I didn't have any ancient computer monitor and could use it with my Mac, I'd just ignore it for now, but I can't code and do CAD on a 13" screen.

Link to comment

Update: Ignore people who code at 4:00 am. I found the real problem, and it actually was, in one execution of the function, attempting to convert a None to an integer. *infinite face-palm*


Apparently a Mac doesn't care to tell you and just considers it a 0. Fixed it with an if-then.

Link to comment

this is the bit of code Josh was referring to prevent VW from caching.  I've also found that python in VW is very sensitive to tabs versus spaces.  I have my external editor set to insert 4 spaces when I tab. If I copy and paste a snippet from VW to my external editor it copies it as tabs and I have to run a utility that converts tabs to spaces.


import yourExternalFile
import imp
imp.reload(yourExternalFile) #reloads the external file so VW doesn't use a cached version
vs.SetPref(412, True) #Turns off include caching

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.

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