Jump to content

Difficulty reading in text file on OS X


Recommended Posts

I'm trying to write a script to read data from a text file in Vectorworks. The help file seems curiously incomplete in this area and some of the Python examples appear to be incorrect. Still, it appears straightforward and I'm at a bit of a loss as to why my code isn't working. My code is based on the 'GetFile' example code in the function reference, and it boils down to this:

import vs

fileName = vs.GetFile()

a = vs.Read()

vs.Close(fileName)

(in VW2016 on OS X)

I would expect this to result in the first number or word in my chosen file being read into variable a. Running this script in VW2016 produces a file-choosing dialog box as expected. It then produces an error as follows:

File "", line 3, in

AttributeError: 'module' object has no attribute 'Read'

Can anyone shed any light on this? or point me at a working example of how to read from a text file in vectorworks?

Link to comment

Hi David

Hm, I just hav experience by using python moduls for text handling. Because you can get help for this via google for every error message. Also with python you can do so much more (sort, arrange, split, sorting out characters etc).

An Example. Which Reads a text fila as one single string value. To get File Dialog use vs.GetFile, after that you should convert the path (Which is MacHD:User:Dom:etc:ect) to a Posix Path (MacHD/User/Dom/etc/etc)

Try this:

import vs

fileName = vs.GetFile()

bool, fileName=vs.ConvertHSF2PosixPath(fileName)

a=open(fileName).read()

vs.Message(a)

Edited by DomC
Link to comment

The VS file routines have a number of limitations, so they may actually be disabled in the Python API. Follow the above advice and use Python's built-in routines for file handling.

The only built-in Python routines I don't recommend are UI -- tk, etc. The Python library needs a special update for Mac, and the Python commands can cause some memory issues when run inside VW, so you are best using the VW dialogs.

-Josh

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