06-08-2021 02:28 AM
As part of a Project template script, I would like to create a type def (cluster with element names and sizes defined from other sources). I can copy a type def and rename items within the cluster of the type def, but I have not found a way to add or remove elements of the cluster. Is there a method to do this?
06-08-2021 05:54 AM
I had a Project where an Experiment was being "driven" by a Excel File, each row being a separate Trial and the Columns (I forget how many, but around 150) were the various parameters of the Trial (e.g. Initial Position, MoveTo Position, MoveTo Speed, etc.). I built a pair of TypeDefs from a Master Excel File (one with the Header and Structure information, but no data, a "Template" if you will, that the Users used to "fill in the Rows with Trial Parameters). One was an Enum that named each "variable" in the Cluster, and which came from the Column Headers (Row 1) of the Master WorkSheet, and the other was the Data Cluster, each element of which was the Enum that "named" the Column (taken from the earlier Enum Typedef created from the Column Header) and a separate Enum that specified the Type of the data stored in that column. I "deduced" the latter by building the Master Excel File with Row 2 filled with "Dummy Data" and parsing the entry to decide if it was a String, an Integer numeric, a Float, or a Boolean.
I never tried to "edit" the existing TypeDef -- when a new Master WorkBook was created, I just created a new set of Enum and Cluster with a unique name based on the (also unique) name of the Master Excel WorkBook. To create a version of the Program for a particular Master Excel WorkBook, I had only to make sure I had a uniquely-named set of Enum and Cluster TypeDefs (by running the "Build TypeDefs" program using the chosen Master WorkBook) and then copying the current Enum and Cluster to the name I used in the Project File.
For example, say the Master Files were named Master 1, Master 2, etc. The Script creates Enum 1 and Cluster 1, Enum 2 and Cluster 2, etc. If I need a version that supports Master 2, I copy Enum 2 and Cluster 2 into the files Working Enum and Working Cluster, which are the (unique) names my Project uses. When a new Master file comes along, I build new Enums and Clusters, and compile a new Executable based on them.
Fortunately, we put enough thought into the original Master WorkBook that we only had about 4-6 (slightly) different Executables to contend with. As the User knew which Master Workbook they were using for their Study, they knew which version of the Program to run.
Bob Schor
06-08-2021 06:30 AM
You can do those things via LabVIEW or VI scripting. You have to program a VI that changes or creates a new typedef and after that run it. That is totally possible, but it takes some work to do so. The first point is to activate the option "VI scripting" in LabVIEW -> Tools -> Options -> VI server.
There a many resources about VI scripting to be found - just start your favourite search engine and look for VI scripting (and more specific questions).
Regards, Jens
06-08-2021 07:38 AM
Hi Jens
I already have some ability to look at clusters, however I can not find any means of adding or removing the elements of the cluster in type def, and want to know if that is possible. Searching has not given any useful examples. My code for looking at the elements is
The controls[] array is not a writable property on the cluster. Is there a way to add or remove a control in that cluster?
06-08-2021 08:02 AM
Hi,
as I said, yes it is possible, but first you have to activate this:
VI scripting is not for the beginner in LabVIEW and not very well documented, hence I recommended to search in google for topics to your question.
Here is one example of many that you can find for VI scripting:
https://forums.ni.com/t5/Example-Code/Create-Cluster-Scripting-Using-LabVIEW/ta-p/3497533
Regards, Jens
06-11-2021 02:40 AM
I wouldn't create a type def with scripting.
Make the template with type defs, then edit them.
06-11-2021 12:24 PM
Two options are to create the control and move it into the cluster, or create a new control with the cluster as the owner.
static ref is to the attached cluster_td.ctl