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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use replace invoke node on a typedef constant inside a typedef cluster in VI scripting?

Solved!
Go to solution

Hi,

 

I want to write a program to rename every element on my blockck diagram. I had difficulty when rename a typedef inside a typedef cluster. 

for example, I have a target VI contains only one constant in its BD. The constant is a cluster. It has only one element: a typedef string constant with a name tst1 String 1.ctrl.

My plan was to create a copy of the string typedef with a different name, tst2 String 1.ctrl, and use the "replace" to replace tst1 String 1.ctrl.

change constant.png

 

 

The same code works if the cluster is not a typedef. However, I got an error from the replace invoke node when the cluster is a typedef.

It seems that it does allow me to replace it since it is an element of a type def. 

Is there any way I can achieve what I want, even when there is type def inside type def?

 

The target VI and the VI script VI are in the attached zip file.

 

Thanks in advance,

 

Message 1 of 10
(4,007 Views)

If your goal is to obfuscate the code, you could simply disconnect the type def from it's definition. It doesn't need updating anyway, the reason for using the type def.

 

If you want to rename the element in the type def, you need to open a reference to the type def, cluster, and change it there. (You could do that before disconnecting, so all instances get the rename.)

 

If you really want to copy each type def, I'd try saving a copy of the type def using LabVIEW, not the file system. Not sure if that's the problem.

0 Kudos
Message 2 of 10
(3,979 Views)

Hi Wiebe,

 

Thanks for replying. I want to create a set of programs for a new project (not labview project, but work project) by copying everything it to a new folder, and rename everything in that contained old project name to the new project name.

 

It worked fine with all the SubVIs. But I met difficulty when renaming typedef constant in a typedef cluster.

 

I believe I didn't understand your 2nd sentence. This is the code I have modified, but I guess that's not what you meant:

This is in Main.vi

Main.png

there is a type def string inside a type def cluster. They are saved as tst1 cluster.ctrl, and tst1 string. ctrl. I want to change their names to tst2 cluster.ctrl and tst2 string.ctrl. ( i.e. tst1 to tst2)

 

This is in VI scripting.vi

change typedef in typedef.png   

 

the "vi path" control points to the Main.vi. This time, I got the tst1 string.ctrl's reference from the cluster instead of directly from "Get GObject" vi as before. However, I still get the same error when I rename the string ctrl: the element in the type def cluster.

 

Also, if I just do this with the clusters, I will ended up with a type def cluster named tst2 cluster.ctrl containing tst1 string.ctrl. So how do I change the tst1 string.ctrl to tst2 string.ctrl?

 

Thanks,

 

Yong Liao 

0 Kudos
Message 3 of 10
(3,966 Views)

>It worked fine with all the SubVIs. But I met difficulty when renaming typedef constant in a typedef cluster.

 

You can't rename an element in a type def constant, because the constant is type def-d. That is the hole reason of existence for type defs: the're all the same.

 

So if you want to rename an element in a type def, you need to open the type def, and rename the elements in it. In you situation, the element inside is a type def, so you need to open it and rename it.

 

But if you rename all the type defs, in your example the cluster and the string, the string in the cluster would also have changed automatically.

 

You can't change an element in a type def-d constant manually either. The way to do it manually, is to open the type def of that constant, and change it there...

0 Kudos
Message 4 of 10
(3,955 Views)

Hi Wiebe,

 

How do I rename all of them, both the cluster and its element , programmatically?

 

also, because I don’t know how to do a rename directly, I used the replace node. It is a work around.

 

finally, how do I open the cluster and then rename its element programmatically? 

 

I know now how to do that manually. But the point of a scripting program is to process many files in a similar manner. 

 

Thanks again!

0 Kudos
Message 5 of 10
(3,951 Views)

@littlett01 wrote:

 

How do I rename all of them, both the cluster and its element , programmatically?

The type def control is more like a VI then a constant. It has a path, like a VI. So you can open a VI reference to the type def (.ctl) and save it under a different name, like a VI.

 


@littlett01 wrote:

also, because I don’t know how to do a rename directly, I used the replace node. It is a work around.


Just like a VI. Open a reference, save as.

 


@littlett01 wrote:

finally, how do I open the cluster and then rename its element programmatically? 

For a type def cluster that has other type defs, you shouldn't need to rename the elements (assuming you mean the type def name, not the label). The type def inside the cluster is a file, just like the cluster itself. So if you rename all controls (.ctl), all type defs in clusters should automatically be renamed as well. Think of the type def in the cluster as a Sub VI in another VI. VI has SubVI, Control has Sub Control.

 


@littlett01 wrote:

I know now how to do that manually. But the point of a scripting program is to process many files in a similar manner. 

The point was that you can't replace an element in a type def constant with scripting, for the same reason you can't do it manually. And the way you can do it manually, also works with scripting.

 

 

 

Message 6 of 10
(3,947 Views)

Hi Weibe,

 

I gave a try but I am not sure if that's what you meant:

change all constants.png

 

Here is the code. The code does create two controls with new name without error. However, when I open the main.vi, the one I wanted to modify, it was tst2 cluster.ctrl with tst1 string.ctrl in it, instead of tst2 cluster.ctrl with tst2 string.ctrl in it.

Did the code reflect what you said? If not, could you clarify again?

If yes, what went wrong?

 

Thanks,

 

0 Kudos
Message 7 of 10
(3,945 Views)
Solution
Accepted by topic author littlett01

Hi Weibe,

 

OK, I figured it out. I have to first save the string ctrl, and then the cluster control.

 

Here is a working code:

save typedef.png

 

Does this reflect what you meant?

 

Thanks,

0 Kudos
Message 8 of 10
(3,940 Views)

@littlett01 wrote:

Hi Weibe,

 

I gave a try but I am not sure if that's what you meant:

change all constants.png

 

Here is the code. The code does create two controls with new name without error. However, when I open the main.vi, the one I wanted to modify, it was tst2 cluster.ctrl with tst1 string.ctrl in it, instead of tst2 cluster.ctrl with tst2 string.ctrl in it.

Did the code reflect what you said? If not, could you clarify again?

If yes, what went wrong? 


Save a copy is probably true by default, so you'll get a copy. Wire a false to it, and it will save the control with a new name.

 

You make your life a lot easier if you simply skip this on type def constants, and make a new loop that does this for all .ctl files, like you do for all the .vi files. If you do this for a constant that is a type def, this type def will be saved over and over again, once for each time it is encountered. And so will it's sub-type defs. So it would be a lot easier if you simply save all the .ctl file with a different name once.

 

In short:

For each VI

 save with different name

For each contrl

 save with different name

 

Or:

For each VI or control

 save with different name

0 Kudos
Message 9 of 10
(3,935 Views)

wiebe@CARYA wrote:Save a copy is probably true by default, so you'll get a copy. Wire a false to it, and it will save the control with a new name.

Never mind this then, it's false by default.

0 Kudos
Message 10 of 10
(3,931 Views)