From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Editing .cws and .prj files

I have a "template" .cws and .prj that has most of the directory file structure and .c/.h files in place. I have written a batch file script with powershell commands that will search for the generic "token" that is part of particular filenames that are needing to be changed to be used in a particular usage, i.e. searching and changing token UUT to PN628227. I can successfully change all instances within the .cws and .prj to the correct filenames as well as updating the various paths that has those filenames listed. The problem is that when I go to open the "new" .cws I get an error that the Number of Projects tag is missing from the [Workspace Header]. When I open the .cws using Codewright or Notepad, I clearly see it is there under the [Workspace Header]. So, as mentioned in a previous posting, I tried editing the .cws and .prj in CVI directly or by changing the file extention first and then opening in CVI. I get a error saying that CVI cannot open a binary file as text. Which in this case leads me to believe that once I save my edited changed .cws and .prj they become corrupted, which is also an error I have experienced. If I can get the batch file script to work, this will save a great deal of time when using the template .cws and .prj when setting up to do a new "job".

 

There's got to be a way to deal with this issue. I can do this sort of thing in .seq TestStand sequence files, but I have to make sure I save the file as a text not as a binary file before doing any editing directly to the .seq file. I do not see the same sort of thing for CVI.

 

If you can, I am waiting to be enlightened and schooled.

 

Thanks,

Denton Jarvis

0 Kudos
Message 1 of 3
(5,295 Views)

Jarvis (I like how that makes me sound like Iron Man),

 

You're definitely experiencing some corruption when you edit with your external editor.  I've used Notepad++ on numerous ocassions to edit those files without issue.

 

That said, I hate to say it but your goal might be a fool's errand.  In my experience, editing them is a delicate proposition.  Take a look at how the CWS file handles long pathnames:

 

2015-09-03 15_12_48-C__Users_rob.lund_Documents_SVN Checkouts_01005TF400-SW Auto Burn-In_01005TF400 .png

 

See how the lines are split?  That makes batch scripting very tricky.

 

But in general, you should be able to edit the files without breaking them.  Make sure you're saving them as ASCII with the right encoding.  My Notepad++ is set to ANSI encoding and that works.

0 Kudos
Message 2 of 3
(5,292 Views)

Here is my solution:

 

Lets say you have a template project/workspace and all of its goodies on a different drive. Lets say that you have a group of files that "UUT" in them that need to be replaced with a part number, say PNxxxxxxx. Lets say that you want to use 90% of the template settings but need to change out all of the "UUT" files and change the paths in the .prj and .cws so they will point to those newly named files when loading up the .cws and .prj.

 

using a combo of .cmd and powershell, the following could be used to automate this grueling tasks.

 

rem <first, get the bulk project files and move them to your work location, I am going to my desktop>

@echo off

set arg1=%1

cd '%systemdrive%/documents and settings/%username%/desktop"

set /p x= TPS_PartNumber :

md %x%

xcopy /s/e "Z:\(the location of the bulk project files are located at)\*.*" "%CD%\%x%"

cd %CD%\%x%

rem <change all the file names that have "UUT" token to the part number just entered>

%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -command "Dir | Rename-Item -NewName" {$_.name -replace 'UUT', '%x%'}"

rem <if there is a subfolder, as in my case, that needs the doctoring as well>

cd ".\%x%"

%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -command "Dir | Rename-Item -NewName" {$_.name -replace 'UUT', '%x%'}"

rem <move back up one directory for dealing with .cws and .prj content, I am sure there is a recursive Dir | Rename-Item functionality, but>

rem <as personal preference, I like to do one thing at a time to make sure I got my logic instructions down in correct order>

cd ..

rem <in the .cws and .prj, find the UUT token and replace with PNxxxxxx entered>

%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -command "(Get-Content %x%.prj) | Foreach-Object {$_ -replace 'UUT', '%x%'} | Out-File -encoding ACSII %x%.prj"

rem <NOTE: as Mr. ElectroLund pointed out here, the format needs to stay in ASCII. The Out-File -encoding flag can be used to do this. There are other options, but for this>

rem <operation, the ASCII is the man>

%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -command "(Get-Content %x%.cws) | Foreach-Object {$_ -replace "UUT', '%x%'} | Out-File -encoding ACSII %x%.cws"

%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -command "(Get-Content %x%.cdb) | Foreach-Object {$_ -replace "UUT', '%x%'} | Out-File -encoding ACSII %x%.cdb"

cd ..

rem <end of script>

 

There is probably more cleanup to do, but the above does the operation I was initially asking about and thought I would share the solution.

 

Thanks ElectroLund for the input. It is greatly appreciated.

 

Message 3 of 3
(5,256 Views)