This script is meant as follow up to the thread Run VectorWorks’ script from the clipboard http://bbs.applescript.net/viewtopic.php?id=16735.
VectorWorks is a CAD application with its own script language, VectorScript. It is a powerful script language allowing access to almost any element of the application, but it has one limit: VectorScript can -under normal conditions- only operate on the frontmost open window.
The topic on the previously mentioned thread evolved to a very common question among VectorScripters: how to run a VectorScript on multiple files. This question is highly “recursive” since years among VectorScripters. Since to my knowledge no free scripts of this sort are available online, I thought, well, it is time to put out one. And it has to be a simple one.
For testing, copy whatever object in your drawing (for example a symbol containing drawing informations), save the VectorScript snippet below in a text file, then to run the batch runner on some chosen files:
{ SAVE THIS IN A TEXT FILE }
{ paste in place clipboard content on every sheet layer }
PROCEDURE pasteInEverySheetLayer;
VAR
layerHand :HANDLE;
temp_i : INTEGER;
BEGIN
layerHand := FLayer;
WHILE LayerHand <> NiL DO BEGIN
IF (getObjectVariableInt(LayerHand, 154) = 2) THEN BEGIN
Layer(getLName(LayerHand));
DoMenuTextByName(‘Paste In Place’, 0);
END;
LayerHand := NextObj(LayerHand);
END;
END;
Run(pasteInEverySheetLayer);
-- very simple batch runner for VectorScript Files
-- Orso B. Schmid 2006
-- MacOs X.3+
-- NOTE: the close command seams to be broken under VW 12.
-- Avoid using this script under VW 12
-- Please avoid having two versions of VW contemporarily open,
-- this can lead to unpredictable results
-- change file types according to your needs
global VWfileTypes
set VWfileTypes to {"DO11"} -- VectorWorks 11
-- choose a Text file containing a VectorScript code
-- You better have that code valid, VW won't tell AppleScript he dislikes it...
set aVWscript to readFile((choose file with prompt "Choose a VectorScript file " of type "TEXT") as text)
-- choose one or more VectorWorks files
set theChosenFiles to choose file with prompt "Choose one or more vectorWorks files " of type VWfileTypes with multiple selections allowed without invisibles
launch application "VectorWorks"
set theProcessedFiles to {return}
repeat with aVWfile in the theChosenFiles
runTheScript(aVWfile, aVWscript)
set end of theProcessedFiles to name of (info for aVWfile) & return
end repeat
display dialog "Processed files: " & theProcessedFiles as text
on runTheScript(theVWfile, theVSscript)
tell application "VectorWorks"
open theVWfile
ignoring application responses
DoScript theVSscript
-- this deals with eventual dialogs raised by VectorScript
-- according to the busy state of VW, this might fail miserably
-- I just put it here to show how to access the problem
-- couldn't find any working way to put it on a "if" condition
-- nor seams to be possible to trap a vectorScript taking more time as 1 sec.
-- the whole system events is kept busy by the eventual VS dialog
-- turn on "Enable access for assistive devices" in the "Universal Access" pane for this to work
tell application "System Events"
tell process "VectorWorks"
set frontmost to true
delay 1
key code 36
end tell
end tell
end ignoring
close document 1 saving yes -- this is broken in VW 12 !!!!!!!
end tell
end runTheScript
-- reads the values stored in the script file
to readFile(aFilePath)
try
set openFile to open for access file aFilePath without write permission
set theVWdata to read openFile as text -- this has to be clean text, unstyled
close access openFile
on error errorMessage
try
close access openFile
end try
set theVWdata to ""
display dialog errorMessage
end try
return theVWdata
end readFile
The script allows a very simple batch running of a VectorScript file on any number of chosen VectorWorks files.
The script must be a valid VectorScript: no error will be sent by VectoWorks to AppleScript if the script for some reasons do not compile. Eventual dialogs raised by the VectorScript are all confirmed. Please consider this carefully.
Also remember that the AppleScript implementation of VectorWorks is reduced to very few commands (open, close, translate, doScript) and never, under no conditions, does VectorWorks outputs a result. The efficiency of your scripting relies thus on the efficiency of your VectorScript.
I hardly think an explanation of this AppleScript is needed, since it is of most basic nature:
let a user choose a script file,
let a user choose a list of VectorWorks files
load the script file into a variable through the standard additions open for access and read,
run the script in the list of chosen files.
Model: PowerBook g4, 1500
AppleScript: 1.9.3
Browser: Safari 312.6
Operating System: Mac OS X (10.3.9)