Jump to content
Developer Wiki and Function Reference Links ×

Scripts I've been using for years fail in Vectorworks 2018


David L

Recommended Posts

Most of the 100+ scripts I use in Vectorworks (some for over 10 years) fail in Vectorworks 2018.  All of the failures are related to undeclared variables.  I looked for changes to Vectorscript in 2018 that may be causing the problems, but couldn't find anything specific.

 

This is a typical example of a simple script that sets the line weight of a selected object, but now it fails saying the Handle (h) is not declared, even though it is in the Function definition, and has been working fine in many versions of Vectorworks since 2008.

 

PROCEDURE SelectedObjLineWeight;

CONST
   w = 20;  { <----------- Line weight in mils.}

VAR
   countObj : INTEGER;

FUNCTION SetAttribute(h:HANDLE) :BOOLEAN;
BEGIN
   SetLW(h, w);
   ResetObject (h);
   countObj := countObj + 1;
END;

{---IF selected objects exist, they will be 
    counted each time Function above is called}

BEGIN
   ForEachObjectInLayer(SetAttribute, 2, 1, 4);
{---IF no objects are selected, then default attribute is set}
   IF countObj = 0 THEN PenSize(w);
END;
Run(SelectedObjLineWeight);

 

If anyone can tell me what the problem is, I can migrate my office to 2018.

Error_Example.png

Link to comment

David,

   I pasted your script into VW 2018 (into both a Palette Script and a Menu Command) and it worked perfectly. Perhaps it is the menu PIO you migrated from VW 2008 that is kicking an error, but I can't test that here. Try creating a new one in VW 2018 and migrate your script to it. If the error persists, it's in your code. If it runs, it's your old Menu Command.

 

   If you copy your text out to an external text editor, then copy it from there and paste it back into the VS Editor, does it compile? One trick I've used to clear unseen cobwebs is to CUT everything out of the script Editor, close/save it, run the empty script (which forces the compiler to compile the empty file, which will execute without errors), then reopen the Script Editor and past the text back in. Sometimes that's all it takes. 

 

   A more likely cause is VW 2018 now runs entirely on Unicode (UTF-8 for scripts, UTF-16 internally). If there are any high-order ASCII characters in your code (chars 128-255 are illegal one-byte characters in Unicode), like a Non-Breaking-Space character, you will get strange errors. BBEDIT or something similar can help you isolate any "odd" characters, or translate them to UTF-8 encoding, at which point they will compile as they always have. Save a Latin-1 encoded file as UTF-8, then copy that text to the script editor and it will work.

 

   Let us know how your next round fares.

 

Raymond

Link to comment

The other thing I see is that you are using single letter variables. I used to do that and found that occasionally I was running into problems. I now almost always use longer variable names.

 

  • Your h and w are not criteria and I think most of my problems came from trying to use variable names that could be interpreted as criteria.

Try changing h to H1 and w to W1 globally and see if that solved you problems.

 

 

Link to comment

Thanks to both of you.  I found a partial solution.

  • Tried Pat's recommendation to make variables H1 and W1.  Still failed in the same places.  I will use that practice in the future.
  • I did find something on the VS:Vectorworks 2018 Development page that said the script engine needed Unicode UTF-8 encoding.  http://developer.vectorworks.net/index.php/VS:Vectorworks_2018_Development
  • Following RJ's lead, I copied the script from this page and pasted it back into my existing script.  It compiled and worked from the assigned key command.
  • I tried copying the script into TextEdit and saved it as a plain text file, then used the Run command from inside Vectorworks.  That failed with the same error.
  • I dug around in TextEdit and found the Save As dialog allowed you to choose UTF-8 and other formats to save plain text files.  Those also failed using Run and pasting the text into the script.
  • If someone with Vectorworks is following, we need a method to convert existing scripts, to fix the incompatibility.  The Migration Manager does not convert custom plug-ins in the User folder.
  • For the time being I may have to post scripts to this website and copy them back, as a temporary solution.
Link to comment
12 hours ago, David L said:

I tried copying the script into TextEdit

The best editor for VectorScript is in my opinion TextWrangler, there Is even a language module http://www.vectorlab.info/index.php?title=Category:Language_modules  that knows most of VectorScript's functions (whether it has been updated in the last years, I don't know) and shows them in colour. UTF-8 can be set as default. 

Link to comment

My answer to David (in a PM) was his PIO's have Non_Breaking_Space (NBS) characters in his code and the compiler does not like single_byte characters in the Extended ASCII range (#128-255)  . The NBS character is a High Order ASCII character (#160 decimal). UTF-8 only accepts ASCII in the 0-127 range. It is a relatively simple process to replace all NBS characters \x{A0} with TABs \t or SPACEs. I was able to edit the .vsm file in TextWrangler (yes, I still have a copy), replace all NBS with TAB, then save. The file then compiled and ran. It would be very easy to 10, 50, or 100 .vsm files in succession. BUT, BE WARNED. THIS SHOULD ONLY BE DONE ON COPEIS OF YOUR ORIGINAL PLUG-IN FILES!!!

 

MAKE BACKUPS, THEN DO YOUR SURGERY. 

 

The NBS character is not the only character that will cause compiler problems, but it is a very common character to encounter, AND it is nearly invisible. It looks exactly like the SPACE character (#32 decimal). Any character in the Extended ASCII range (#128-255) will cause problems. For more elusive problems, it may be necessary to use a HEX Editor to see exactly what characters are in your files.

 

HTH,

Raymond

  • Like 1
Link to comment
1 hour ago, Urbanist said:

there Is even a language module http://www.vectorlab.info/index.php?title=Category:Language_modules  that knows most of VectorScript's functions (whether it has been updated in the last years, I don't know) and shows them in colour. 

 

Hello Urbanist, I am the one who did it years ago but I don't support it any longer, because now it's easy to create and maintain the latest set of VS keywords using another method:

  • create a simple list of VS keywords
  • save it as text file into the folder "Custom Keywords": <user>/Library/Application Support/BBedit/Custom Keywords or <user>/Library/Application Support/TextWrangler/Custom Keywords 
  • change the file suffix into ".px"
  • make a copy of it and change the file suffix into ".vss"

Now you have two identical files covering the keywords which will be used as array for all Vectorscripts. This is dealt with in the preferences, automatically.

 

I attach here a set for VW 21 (VW 2017) that you can unzip into the folder Custom Keywords. I just forgot to do the new set for VW 2018, I'll post it here as soon as possible.

 

Ciao

 

 

 

Vectorscript_Keywords_2017.zip

Edited by _c_
try desperately, unsuccessfully, most likely, to improve my English
  • Like 1
Link to comment

To fix the encoding error in VW 2018, something that I also had extensively, this worked very well for me:

  • open all your vectorscript files in TextWrangler/BBedit
  • In the bottom bar, set the encoding to "Unicode (UTF-8)" (see screenshot)
  • save
  • close

Don't use "File > Re-open using encoding..." because that will mess things up for reasons that I fail to understand

 

Ciao

Screen Shot 2017-10-10 at 08.28.20.png

Edited by _c_
  • Like 1
Link to comment
26 minutes ago, _c_ said:

create a simple list of VS keywords

 

A tall order: one has to go through the library file MiniPascal Callbacks (or something like that), which incidentally has at least in the past contained functions that are not in the official documentation. 

 

Nice method, though, thank you.

Link to comment
3 hours ago, _c_ said:

I attached one set for you to use, that includes ALL hidden functions that I could find, also stuff really buried in the resources. Look at the zipped file attached to my post.

Well, excellent! You've  done what one should get from the developer VS site, that should of course include also those hidden functions that cannot be found even by the Grand Master of Vectorscripting. Hats off, lads: if Ms. _c_ does not know something about VS, it is well and truly unknowable. 

  • Like 2
Link to comment
  • Vectorworks, Inc Employee
On 10/7/2017 at 9:33 PM, David L said:

Most of the 100+ scripts I use in Vectorworks (some for over 10 years) fail in Vectorworks 2018.  All of the failures are related to undeclared variables.  I looked for changes to Vectorscript in 2018 that may be causing the problems, but couldn't find anything specific.

 


I can not confirm this 100% yet, but as soon as 2018 SP1 releases (which is... imminent) you should install it and right away try running the scripts again. I have heard tell that many of these types of issues may be fixed even if they weren't mentioned specifically in the patch notes. There were no fixed SPECIFICALLY aimed at the items in this thread, but it is suspected that many of the issues were fixed via other tasks.

Link to comment

That is very interesting to hear. I hope this could include a solution to some of the problems I am experiencing - I have spent the last few days trying to isolate why some scripts have just stopped working (in VW 2018). They compiled fine but just did not work as they used to.

 

I will now 'down tools' until this new release becomes available...

Link to comment

Raymond was correct on my issue.  The non-breaking space characters (option-space) caused the problem.  I don’t know why the error presented itself as an undeclared variable, but replacing the non-breaking spaces with regular spaces or tabs fixed the problem.

 

I just pasted the script into Pages, turned on Show Invisibles, Found & Replaced all non-breaking space characters with tabs, copied the corrected script and pasted it back into Vectorworks and that version did compile.  I assume Pages uses UFT-8 encoding, but I didn’t even check that.

 

I don’t remember why I used non-breaking spaces when I wrote the scripts years ago.  I think it made the lines indent in a more controllable fashion.

 

It would be nice if Vectorworks would make a Command to fix old scripts, like the Update Plugin Objects command.  I will look into making a Keyboard Maestro macro to automate the script cleanup process.  If I can get one working, I will make it available for those who use Keyboard Maestro.

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