03-15-2012 02:15 PM
Hi all,
I have a complex project with a number of build specifications. Each of those build specs has the version number in it in several places. Opening each build spec takes a looooong time for LV to process, so the chore of bumping version numbers on this project is a major pain.
This works:
I just wrote an LV script to do some other pre-build stuff and when I try to code the search and replace in labview (with read from and write to text file), the project file won't open because it's corrupt.
I'm guessing this is a unicode issue, but I don't know how to fix it. Any tips?
Solved! Go to Solution.
03-15-2012 02:41 PM
I would suggest attacking the lvproj file using the XML DOM as opposed to a String based search and replace. I have used them extensively to alter various LV generated XML files with mostly good results. I miss the regexes, but XPath is almost as much fun.
03-15-2012 02:41 PM
Is the XML still valid? I think you can tell by opening it up in Internet Explorer. Just make a copy of your .lvproj with the extension .xml and do a file/open from Internet Explorer.
How are you doing the "search and replace" in LabVIEW? Are you using the xml functions?
03-16-2012 08:21 AM
Hah! Thanks for prodding me to look at the output file more closely, Steve. Turns out I was appending the new text to the end of the file rather than rewriting the file. D'OH!
So for the record: you can open, write, and close an lvproj file with the text file primitives just fine, at least in LV2010 sp1.
03-19-2012 08:44 AM
lvproj files can contain binary parts, such as icons, so be careful.
03-19-2012 10:06 AM
In what circumstances would that be the case? I have icons included in the project (for the build specs) but that's just a path to a file...
I check the project file into source control first, so if this script breaks it I can easily revert it (that's step 1!)
-B
03-20-2012 07:50 AM
I don't know all the circumstances that could lead to binary parts in an lvproj file, and it may not exist any more (I ran into it in LabVIEW 8.6). As long as you are not modifying those parts, you should be OK. You just have to make sure your text/XML parser can handle non-ASCII blobs, since you may have to rewrite them if you are adding information before them. Streaming the parts I was relocating as U8 arrays instead of text eliminated any problem. Note that U8 Array ↔ string conversion is an in-place operation, so you can go between the two easily enough with no major performance penalty.
03-20-2012 08:20 AM
If you want to alter a project file directly, you should use the methods that LV provides - then you don't have to worry about all this other stuff. There is an Application method for returning a reference to an existing project or creating a new one. You can modify things programatically using such a reference.
Mike...
03-21-2012 02:17 PM
@mikeporter wrote:
If you want to alter a project file directly, you should use the methods that LV provides - then you don't have to worry about all this other stuff. There is an Application method for returning a reference to an existing project or creating a new one. You can modify things programatically using such a reference.
Mike...
That's a nice idea, but it doesn't do what I'm trying to do, at least in 2010 and prior. I'm (mainly) trying to bump version numbers in build specifications. The relevant classes in VI server don't have properties or methods that do much, and the App Builder API doesn't do installers and cannot retrieve version numbers from a buildspec.
background and limitations of AB API discussed here:
http://forums.ni.com/t5/LabVIEW/Darren-s-Weekly-Nugget-02-15-2010/
text search works fine, is fast, is easy.