Wizard12 Posted January 20, 2021 Share Posted January 20, 2021 I was wondering if there is a way to delete a text file (.txt) using a script. I have various hole pattern files saved per a height code and a number saved to multiple text files (93AA-1.txt) which are being read to populate a dialog list browser and using the Read procedure. 93AA-1.txt has 20 parameters to populate line 1 of the list, 93AA-2.txt populates line 2 and so on for a limit of 9. If the user wants to delete one of the patterns, I was hoping to delete the file to show the correct pattern list. I tried to do all of the patterns in a single text file (ReadLn) but was unsuccessful in getting the pointer to read the correct line. Any thoughts or help would be appreciated. Thanks. Quote Link to comment
PatW Posted January 20, 2021 Share Posted January 20, 2021 PythonBeginContext; PythonExecute( 'import os' ); PythonExecute( 'os.remove( r"C:\Users\admin\Desktop\remove.txt")' ); PythonEndContext; This should do it. Make sure the file is in a dir where VW has the permission to delete it. regards, Patrick 1 Quote Link to comment
Wizard12 Posted January 20, 2021 Author Share Posted January 20, 2021 Thanks Pat, that works great. One question, is there a way to make the file path contain variables? I get an error when I try. here is my method for finding the filepath to insure it exist before populating the dialog: fileName:=Concat('C:\Users\Eric\AppData\Roaming\Nemetschek\Vectorworks\2014\Stud Patterns\',FileCode,Ext,'.txt'); GetFileInfo(fileName, fullReadPath, fullWritePath, readFileExists, writeFileExists, locked, hasReadPermission, hasWritePermission, hasFolderPermission); Quote Link to comment
Pat Stanford Posted January 20, 2021 Share Posted January 20, 2021 Check out the VS.GetVSVar function https://developer.vectorworks.net/index.php/VS:GetVSVar This will bring a Vectorscript Variable into Python Variable. I filed a bug in November. If you pass a String variable through this function it loses the first character. If you pass a DynArray of Char it works properly. It is supposed to be fixed in SP3 whenever that is released. Apparently the bug also impact the reverse function VS.SetVSVar. 1 Quote Link to comment
Wizard12 Posted January 20, 2021 Author Share Posted January 20, 2021 Thanks Pat, I was just researching how to pass my Vectorscript variables into the python code. I will take a look, thanks for the heads up on it having to be a DynArray! Quote Link to comment
Recommended Posts
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.