01-07-2013 03:59 PM
Hello,
I'm looking for an example on how to create a teststand project file with the API. I cannot find a methode or property to create it, and add the project file(s) to a workspace. I've tried with PropertyObjectFile (Classe) without success.
Let me know if you can help.
Thx
Martin.
Teststand 2010 SP1.
Solved! Go to Solution.
01-08-2013 09:36 AM
I think the following will work:
Engine.CurrentWorkspaceFile.RootWorkspaceObject.InsertObject(Engine.CurrentWorkspaceFile.RootWorkspaceObject.NewFile(filePath), 0)
-Doug
01-08-2013 02:21 PM
Thx for your answer, i use Labview 8.6 to interact with the API, So i don't know if I interpreted rightly your code...
I've managed to create an empty project file (.tpj) with "Engine.NewPropertyObjectFile (6)"
With the "rootworkspaceObject.NewFile(filePath),0" A pop-up appear to select the file (so it must be created before like above).
What i've done is:
- Creating the file as a project file "Engine.NewPropertyObjectFile (6),(Path)."
- I write the new file to disk "PropertyObjectFile.WriteFile(format)" and "PropertyObjectFile.SaveIfModified"
- Then i try to associate The existing .TPJ file to the RootWorkspaceObject "WorkspaceObject.NewFile(Path)" and "WorkspaceObject.InsertObject(Index)"
-At last I save modification of the association "WorkspaceFile.SaveWorkspaceAndProjectFiles(option)"
There is no error and when i open the workspace in teststand, there is no .pjt in the workspace tree...What i'm missing...
So this does not work for me..
Cheers
Martin
01-08-2013 03:42 PM
Before saving the workspace file, try:
workspaceFile.AsPropertyObjectFile().IncChangeCount()
It might not really be saving the file because it's not marked as modified.
-Doug
01-08-2013 05:23 PM
What you said make sense, I've managed to make it work in a different way using PropertyObject.WriteFile(format) just before SaveWorkspaceAndProjectFiles.
Recapitulation:
Creating a workspace = Engine.NewWorkspaceFile(WorkspaceFile.AsPropertyObject((PropertyObjectFile.Path[Path])(PropertyObjectFile.WriteFile[writeFormat])(PropertyObjectFile.SaveFileIfModified[Prompt]))
Creating a project = Engine.NewPropertyObjectFile[FileType]((PropertyObjectFile.Path[Path])(PropertyObjectFile.WriteFile[writeFormat])(PropertyObjectFile.SaveFileIfModified[prompt]
Adding a project to a workspace = Rootworkspace ---->WorkspaceObject.NewFile[Path]---->WorkspaceObject.insertObject[obj(NewFileReference)][Index] then WorkspaceFile.AsPropertyObjectFile(PropertyObjectFile.WriteFile[writeFormat])WorkspaceFile.SaveWorkspaceAndProjectFiles.
Thx for giving me a hand.
Martin
01-09-2013 09:46 AM
No problem. You really should increment the change count on any files you edit though. It's a requirement for TestStand to know that the file has been modified and things like the save methods check it to see if the file really needs to be saved. Also the Sequence editor shows a modification indicator '*' if you increment the change count.
-Doug
01-09-2013 11:52 AM
Thx for your suggestion,
my goal is not to edit existing workspace, it is to create a workspace with a defined set of projects/folders/vi's that gonna be part of the image build by the deployment utility once the developer has done is project. I already builded a resource that get all sequences/subsequence/vi's(dependencies) inside a workspace to be able to create a label in perforce before automatic deployment over the stations. What i'm doing is much like a wizard to create a new workspace from scratch to be compatible with the deployment system i've coded.
My missing part for now is how to add folders (autopopulating) I expected it to be like adding project but it doesn't seem so...
Regards,
Martin
01-10-2013 09:49 AM - edited 01-10-2013 09:50 AM
I think the only kind of autopopulating that is supported is InsertCodeModules which probably isn't what you want. If you want to populate all files under a particular directory you will probably have to write your own code to do so.
When inserting a new folder make sure you are using the workspace object for the project or a deeper node. I think only projects can be inserted at the top level.
Also, even though you are not editing workspaces, but creating a new one, the architecture of the TestStand API is such that it is expected you will increment the change count of the file to indicate it has been modified before calling a save method (which will check the change count).
-Doug
01-10-2013 12:39 PM
Doug, your the man,
I underestimated your advice about the increment change, I added a folder to a workspaceobject referring to a project then query the projectfile related to the workspaceobject of the project, done a write file, incrment change and at last a save file if modified.
About the autopopulating thx for the cue since I looked I couldn't figure out hot to... I'll think that i'll make some resources for that too in this case.
Again thx for your help, there is so little information about this API it is not easy to manage for unexperienced user of teststand.
Martin
01-11-2013 09:50 AM
Glad you were able to get things working. Note that there is no need to use both WriteFile and SaveIfModfied. WriteFile is a lower-level API that does NOT check the change count and does not ever display dialogs. SaveFileIfModified checks the change count and only saves if the count is different then when the file was last saved, and also optionally prompts the user in some cases.
SaveWorkspaceAndProjectFiles similarly is not needed if you are calling the lower-level WriteFile on every file (i.e. all projects and the workspace), but it might be convenient since it will attempt to save all of the files in one call, the catch is that you have to increment the change counts on the files you want it to save since it will not save files where the change count hasn't changed since the file was last saved.
Hope this helps clarify things,
-Doug