Jump to content
Developer Wiki and Function Reference Links Read more... ×
Sign in to follow this  
JoelS

Calling DoScript with Applescript on VW2011/MacOS X 10.6

Recommended Posts

I am having trouble sending an Applescript to VW2011 (SP2) under MacOS X 10.6

With VW2009 on the same machine, I use this Applescript to send the contents of my editor?s front window to Vectorworks:

-- getplaintext subroutine called from within the Tell using 'of me'

on getplaintext(fromUnicodeString)

set styledText to fromUnicodeString as string

set styledRecord to styledText as record

return ?class ktxt? of styledRecord -- Ensure Western (Mac OS Roman) encoding

end getplaintext

tell application "SubEthaEdit"

activate

-- Get the script text out of SEE as a string.

set theScript to the plain text of document 1 as string

-- Convert from Unicode

set theScript to getplaintext(theScript) of me

tell application "Vectorworks 2009"

activate

-- Execute the script in VW

ignoring application responses

DoScript theScript

end ignoring

end tell

end tell

This does not function with VW2011 as the AS compiler returns ?Expected end of line but found identifier.?

Changing the line to DoScript(theScript) gives a clean compilation but it does not work with VW2011 (other than bringing VW to the front) and no errors are reported that I can find.

I see elsewhere that using a file reference in a script has been used but I cannot make this work with VW2011 either:

set theFileReference to "My HD:Users:Me:Desktop:VScript.txt" as alias

tell application "Vectorworks 2011"

activate

-- Execute the script in VW

DoScript(theFileReference)

end tell

An error is returned by the system: ?error "Vectorworks 2011 got an error: Can?t continue DoScript." number -1708?

This error is not an Applescript or OS error code that I can find so was probably returned from Vectorworks but I cannot find any trace of this error code in the documentation I have searched.

I have tried different file encodings for the script file without success.

If I open the same file with the Run VectorScript command, it executes as expected.

So what is the official way to address DoScript in VW2011 under MacOS X 10.6? I can find no trace of any recent documentation on the subject.

Using a file reference would be by far my least favourite option as it means creating an intermediate file on each occasion to a fixed location as text first, so the old way would be much easier if it is still possible.

Many thanks,

Joel.

Share this post


Link to post

Joel,

I think there might be an AS dictionary bug introduced in SP2. Opening my Run 2011 script for BBEdit, it now looks like:

tell application "BBEdit"
set theScript to contents of front window
end tell

tell application "Vectorworks 2011"
activate
?event miscdosc? (theScript)
end tell

If I replace ?event miscdosc? with DoScript, DoScript is seen as a variable and not a keyword. If I leave as is, the script works. I'm filing this as a bug.

That said, VW 2011 is Unicode aware, so both cleaning the text or passing a file to DoScript are no longer necessary.

-Josh

Share this post


Link to post

Joshua,

Well done, it works! Hopefully we'll know when it changes again as a result of your submission.

How did you discover this solution?

Thanks,

Joel.

Share this post


Link to post

I built the script in SP1 with DoScript and it worked. I just opened my existing script in script editor, and the substitution was there.

-Josh

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×