BatchRunner choose files

Referring to batchrunner script by Orso, from thread
http://bbs.applescript.net/viewtopic.php?pid=62637#p62637

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

This script lets me choose a vectorscript file and few vectorworks file. It pops up a window to choose those files.

Can someone help me, on how to modify this file to have the vectorscript file and vectorwork file hardcoded into the script. I only need 1 vectorwork file and 1 vectorscript file

Can I hard coded like

set aVWscript to "/System/Users/test.text"

Thank you for your help

set aVWscript to readFile alias ( drag your file here in the script editor to get the “hard” address )

set theChosenFiles to ( drag your file here in the script editor to get the “hard” address )

replacing these lines:

Thank you for the help, but it didn’t work.

I did exactly like you told me to do

set aVWscript to readFile alias (/Users/joso/3631B1.text)
set theChosenFiles to (/Users/joso/BlankPage)

The problem seems to be the “alias”, but when I removed the alias, it still doesn’t work.

Thanks …

An alias should look more like a Mac path, rather than a Unix-type path, ajoso.

In addition, I’m not entirely convinced that the ‘readFile’ handler is strictly necessary, since you should be able to read a file directly. So your couple of lines above might look something like this (depending on the name of your hard drive):

set aVWscript to read alias "Macintosh HD:Users:joso:3631B1.text" (* modify disk name if necessary *)
set theChosenFiles to {alias "Macintosh HD:Users:joso:BlankPage"} (* ditto *)

Please correct the file path according to your mac.
The read routine is needed for VectorWorks. Alternative is to load a text content from an editor.

tell application "VectorWorks"
	activate
	open ("Macintosh HD:Users:Ajoso:Desktop:test.mcd" as alias)
	DoScript my readFile("Macintosh HD:Users:Ajoso:Desktop:test.text")
end tell

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

Ajoso, if you need to run one only vectorScript on one file, why don’t you use INCLUDES?
You definitely do not need to go through AS for that. AppleScript is very cumbersome for VectorWorks. I would suggest using it only if really needed.

Supposing you have your script “test” on the desktop, the valid path for VW would look something like this:
{$INCLUDE Macintosh HD\Users\Ajoso\Desktop\test.text}

Open your plug-in editor.
Create a new plug-in of type command, name it “test”.
Click on “Script”. Paste the following lines:
"{
Test
this is a test for using includes. It’s very comfortable.
}
{$INCLUDE Macintosh HD\Users\Ajoso\Desktop\test.text}

"
Please do not ignore the last carriage returns. If you run your plug-in on PC you need them for cross-compatibility.
Open the Workspace editor and add the newly created plug-in to your workspace.

That’s it.
From now on you can launch it from ANY VW file, WHILE working on it.
In order to coerce the compiler to recompile at every run, you should also have a plug-in containing the following script loaden:
Run this everytime you launch the application, since it always resets.

PROCEDURE ToggleCompilerMode;
BEGIN
SetPref(407, NOT GetPref(407));
alrtDialog(concat('Compile script at every run: ', GetPref(407)));
END;
Run(ToggleCompilerMode);

Orso

Thanks for all the help.

The reason why I need applescript is that I need to do an automation of drawing.
Vectorscript will be controlled by Applescript and Applescript will be controlled by Java.
This java application will be deployed by using Webservices.

Thanks for all the help once again.

You should be able to load the script throu Java.
Drop the read routine, load the script with Java in a Var. Then run the script.
If it doesn’t work, it could mean you have some problem in the VS script.
Alternative, Java doesn’t support the DoScript event. Does Java send events?

If you are more precise as to exactly what you need to achieve, I might be able to help you.
Do you actually have a subscription to the vectorscript-list? If you don’t, make one: http://lists.nemetschek.net/archives/vectorscript-l.html
This discussion is now here off-topic. You need help from other people. There is already people trying to get Java operational with VectorScript. You need contact with them.

If a script like this doesn’t work:

tell application "VectorWorks"
   activate
   open ("Macintosh HD:Users:Ajoso:Desktop:test.mcd" as alias)
   DoScript "AlrtDialog('I will hack it!');"
end tell

it only means AS is no good for what you need to do.

Orso
See you on v-list, hopefully!

P.S.
Don’t give up. Do the connection to Java. We’ll make you a nice room on vcor (the newly born VS last resource wiki) for that, if you succeed.
There’s no improvement without failure. It takes a lot of failure to do something great.

Thanks Orso,

I got the connection between java and applescript working. Except it is very very slow. I don’t know why. I do exactly the same thing from applescript to vectorscript, it takes only around 1-2 seconds. But when I have java to call the applescript, it takes around 6-8 minutes. It’s working though, that’s the start

Is it possible that you can command vectorworks to save a file automatically from applescript?

Thanks

tell application "VectorWorks"
	activate
	open ("Macintosh HD:Users:Ajoso:Desktop:test.mcd" as alias)
	DoScript "lineTo(1, 2);"
	close document 1 saving yes
end tell

The document 1 is a reference. As to VW 11 you can only use the reference in this form, nothing else would work. You can use numbers from 1 to 8. If you open 8 files, this index corresponds to the sequence of opening the files. It’s a tricky boring way to access the files, since it messes up if you open other VW files in between or it cheats you if you had some files previously open. There’s no way to get a list of files from VW, nor a handle to the frontmost doc (which is NOT always “document 1”).
The only way you have to be sure to close and save the right doc, is to close everything up, open a file, then close it.

Additionally you should be able to use a parameter Saving In [alias]. I couldn’t get it to work. If you succeed, please tell me how.

I think you should explore the VS routine openURL. That would allow you under circumstances to avoid AS.
The use of this routine is a bit tricky but very powerful, I don’t know how much experience you have with it.

Orso